Logo ROOT  
Reference Guide
TToggle.h
Go to the documentation of this file.
1 // @(#)root/meta:$Id$
2 // Author: Piotr Golonka 30/07/97
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TToggle
13 #define ROOT_TToggle
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TToggle //
19 // //
20 // This class defines toggling facility for both - object's method or //
21 // variables. //
22 // Assume that user provides an object with a two-state field, and //
23 // methods to Get/Set value of this field. This object enables to switch//
24 // values via this method when the only thing you know about the field //
25 // is the name of the method (or method itself) which sets the field. //
26 // This facility is required in context popup menu, when the only //
27 // information about how to toggle a field is a name of method which //
28 // sets it. //
29 // This Object may be also used for toggling an integer variable, //
30 // which may be important while building universal objects... //
31 // When user provides a "set-method" of name SetXXX this object tries //
32 // automaticaly to find a matching "get-method" by looking for a method //
33 // with name GetXXX or IsXXX for given object. //
34 // //
35 //////////////////////////////////////////////////////////////////////////
36 
37 #include "TNamed.h"
38 
39 #ifdef R__LESS_INCLUDES
40 class TMethodCall;
41 class TMethod;
42 #else
43 #include "TMethodCall.h"
44 #include "TMethod.h"
45 #endif
46 
47 class TToggle: public TNamed {
48 
49 private:
50  Bool_t fState; //Object's state - "a local copy"
51  Long_t fOnValue; //Value recognized as switched ON (Def=1)
52  Long_t fOffValue; //Value recognized as switched OFF(Def=0)
53  Longptr_t fValue; //Local copy of a value returned by called function
54 
55 protected:
56  Bool_t fInitialized; //True if either SetToggledObject or SetToggledVariable called - enables Toggle() method.
57  TObject *fObject; //The object this Toggle belongs to
58  TMethodCall *fGetter; //Method to Get a value of fObject;
59  TMethodCall *fSetter; //Method to Set a value of fObject;
60 
61  Int_t *fTglVariable; //Alternatively: pointer to an integer value to be Toggled instead of TObjectl
62 
63 public:
64  TToggle();
65  virtual void SetToggledObject(TObject *obj, TMethod *anymethod);
66 
67  // you just provide any method which has got an initialized pointer
68  // to TDataMember... The rest is done automatically...
69 
70  virtual void SetToggledVariable(Int_t &var);
71 
72  virtual Bool_t IsInitialized(){return fInitialized;};
73 
74  virtual Bool_t GetState();
75  virtual void SetState(Bool_t state);
76  virtual void Toggle();
77 
78  virtual void SetOnValue(Long_t lon){fOnValue=lon;};
79  virtual Long_t GetOnValue(){return fOnValue;};
80  virtual void SetOffValue(Long_t lof){fOffValue=lof;};
81  virtual Long_t GetOffValue(){return fOffValue;};
82 
83  virtual Int_t GetValue(){return fValue;};
84  virtual void SetValue(Long_t val);
85 
86  TMethodCall *GetGetter() const { return fGetter; }
87  TMethodCall *GetSetter() const { return fSetter; }
88 
89  ClassDef(TToggle,0) //Facility for toggling datamembers on/off
90 };
91 
92 #endif
TToggle::fGetter
TMethodCall * fGetter
Definition: TToggle.h:58
TToggle::GetState
virtual Bool_t GetState()
Returns the state of Toggle according to its current value and fOnValue, returns true if they match.
Definition: TToggle.cxx:69
TToggle::GetOnValue
virtual Long_t GetOnValue()
Definition: TToggle.h:79
TToggle::fObject
TObject * fObject
Definition: TToggle.h:57
TToggle::GetGetter
TMethodCall * GetGetter() const
Definition: TToggle.h:86
TMethod.h
TNamed.h
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TToggle::SetToggledVariable
virtual void SetToggledVariable(Int_t &var)
Initializes object for use with a variable - you pass it via reference so it will be modified by Togg...
Definition: TToggle.cxx:59
bool
TToggle::SetToggledObject
virtual void SetToggledObject(TObject *obj, TMethod *anymethod)
Initializes it to toggle an object's datamember using this object's method.
Definition: TToggle.cxx:135
TToggle
This class defines toggling facility for both - object's method or variables.
Definition: TToggle.h:47
TToggle::SetState
virtual void SetState(Bool_t state)
Sets the value of toggle to fOnValue or fOffValue according to passed argument.
Definition: TToggle.cxx:80
TToggle::fTglVariable
Int_t * fTglVariable
Definition: TToggle.h:61
TToggle::GetOffValue
virtual Long_t GetOffValue()
Definition: TToggle.h:81
TToggle::fOnValue
Long_t fOnValue
Definition: TToggle.h:51
TNamed
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
TToggle::fOffValue
Long_t fOffValue
Definition: TToggle.h:52
TMethod
Each ROOT class (see TClass) has a linked list of methods.
Definition: TMethod.h:38
Long_t
long Long_t
Definition: RtypesCore.h:54
TToggle::fValue
Longptr_t fValue
Definition: TToggle.h:53
TToggle::Toggle
virtual void Toggle()
Toggles the Values and State of this object and connected data!
Definition: TToggle.cxx:112
Longptr_t
long Longptr_t
Definition: RtypesCore.h:82
TToggle::fState
Bool_t fState
Definition: TToggle.h:50
TToggle::fInitialized
Bool_t fInitialized
Definition: TToggle.h:56
TToggle::SetValue
virtual void SetValue(Long_t val)
Sets the value of toggle and modifies its state according to whether the value is equal to fOnValue.
Definition: TToggle.cxx:98
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TToggle::SetOnValue
virtual void SetOnValue(Long_t lon)
Definition: TToggle.h:78
TToggle::fSetter
TMethodCall * fSetter
Definition: TToggle.h:59
TMethodCall
Method or function calling interface.
Definition: TMethodCall.h:37
TToggle::TToggle
TToggle()
TToggle default constructor.
Definition: TToggle.cxx:42
TToggle::IsInitialized
virtual Bool_t IsInitialized()
Definition: TToggle.h:72
TToggle::GetSetter
TMethodCall * GetSetter() const
Definition: TToggle.h:87
TToggle::SetOffValue
virtual void SetOffValue(Long_t lof)
Definition: TToggle.h:80
TToggle::GetValue
virtual Int_t GetValue()
Definition: TToggle.h:83
int
TMethodCall.h