ROOT  6.06/09
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 #ifndef ROOT_TObject
38 #include "TObject.h"
39 #endif
40 #ifndef ROOT_TMethodCall
41 #include "TMethodCall.h"
42 #endif
43 #ifndef ROOT_TMethod
44 #include "TMethod.h"
45 #endif
46 #ifndef ROOT_TNamed
47 #include "TNamed.h"
48 #endif
49 
50 
51 class TToggle: public TNamed {
52 
53 private:
54  Bool_t fState; //Object's state - "a local copy"
55  Long_t fOnValue; //Value recognized as switched ON (Def=1)
56  Long_t fOffValue; //Value recognized as switched OFF(Def=0)
57  Long_t fValue; //Local copy of a value returned by called function
58 
59 protected:
60  Bool_t fInitialized; //True if either SetToggledObject or SetToggledVariable called - enables Toggle() method.
61  TObject *fObject; //The object this Toggle belongs to
62  TMethodCall *fGetter; //Method to Get a value of fObject;
63  TMethodCall *fSetter; //Method to Set a value of fObject;
64 
65  Int_t *fTglVariable; //Alternatively: pointer to an integer value to be Toggled instead of TObjectl
66 
67 public:
68  TToggle();
69  virtual void SetToggledObject(TObject *obj, TMethod *anymethod);
70 
71  // you just provide any method which has got an initialized pointer
72  // to TDataMember... The rest is done automatically...
73 
74  virtual void SetToggledVariable(Int_t &var);
75 
76  virtual Bool_t IsInitialized(){return fInitialized;};
77 
78  virtual Bool_t GetState();
79  virtual void SetState(Bool_t state);
80  virtual void Toggle();
81 
82  virtual void SetOnValue(Long_t lon){fOnValue=lon;};
83  virtual Long_t GetOnValue(){return fOnValue;};
84  virtual void SetOffValue(Long_t lof){fOffValue=lof;};
85  virtual Long_t GetOffValue(){return fOffValue;};
86 
87  virtual Int_t GetValue(){return fValue;};
88  virtual void SetValue(Long_t val);
89 
90  TMethodCall *GetGetter() const { return fGetter; }
91  TMethodCall *GetSetter() const { return fSetter; }
92 
93  ClassDef(TToggle,0) //Facility for toggling datamembers on/off
94 };
95 
96 #endif
TObject * fObject
Definition: TToggle.h:61
Bool_t fState
Definition: TToggle.h:54
virtual void SetOffValue(Long_t lof)
Definition: TToggle.h:84
Bool_t fInitialized
Definition: TToggle.h:60
This class defines toggling facility for both - object's method or variables.
Definition: TToggle.h:51
virtual void SetState(Bool_t state)
Sets the value of toggle to fOnValue or fOffValue according to passed argument.
Definition: TToggle.cxx:79
virtual Long_t GetOffValue()
Definition: TToggle.h:85
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Long_t fOffValue
Definition: TToggle.h:56
virtual Long_t GetOnValue()
Definition: TToggle.h:83
virtual Int_t GetValue()
Definition: TToggle.h:87
virtual void Toggle()
Toggles the Values and State of this object and connected data!
Definition: TToggle.cxx:111
#define ClassDef(name, id)
Definition: Rtypes.h:254
TMethodCall * fSetter
Definition: TToggle.h:63
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
TMethodCall * GetSetter() const
Definition: TToggle.h:91
virtual Bool_t GetState()
Returns the state of Toggle according to its current value and fOnValue, returns true if they match...
Definition: TToggle.cxx:68
TMethodCall * GetGetter() const
Definition: TToggle.h:90
Method or function calling interface.
Definition: TMethodCall.h:41
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:97
virtual void SetOnValue(Long_t lon)
Definition: TToggle.h:82
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:58
long Long_t
Definition: RtypesCore.h:50
virtual void SetToggledObject(TObject *obj, TMethod *anymethod)
Initializes it to toggle an object's datamember using this object's method.
Definition: TToggle.cxx:134
virtual Bool_t IsInitialized()
Definition: TToggle.h:76
TMethodCall * fGetter
Definition: TToggle.h:62
Mother of all ROOT objects.
Definition: TObject.h:58
Long_t fValue
Definition: TToggle.h:57
Each ROOT class (see TClass) has a linked list of methods.
Definition: TMethod.h:40
Int_t * fTglVariable
Definition: TToggle.h:65
TObject * obj
Long_t fOnValue
Definition: TToggle.h:55