Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 "TObject.h"
38 #include "TMethodCall.h"
39 #include "TMethod.h"
40 #include "TNamed.h"
41 
42 
43 class TToggle: public TNamed {
44 
45 private:
46  Bool_t fState; //Object's state - "a local copy"
47  Long_t fOnValue; //Value recognized as switched ON (Def=1)
48  Long_t fOffValue; //Value recognized as switched OFF(Def=0)
49  Long_t fValue; //Local copy of a value returned by called function
50 
51 protected:
52  Bool_t fInitialized; //True if either SetToggledObject or SetToggledVariable called - enables Toggle() method.
53  TObject *fObject; //The object this Toggle belongs to
54  TMethodCall *fGetter; //Method to Get a value of fObject;
55  TMethodCall *fSetter; //Method to Set a value of fObject;
56 
57  Int_t *fTglVariable; //Alternatively: pointer to an integer value to be Toggled instead of TObjectl
58 
59 public:
60  TToggle();
61  virtual void SetToggledObject(TObject *obj, TMethod *anymethod);
62 
63  // you just provide any method which has got an initialized pointer
64  // to TDataMember... The rest is done automatically...
65 
66  virtual void SetToggledVariable(Int_t &var);
67 
68  virtual Bool_t IsInitialized(){return fInitialized;};
69 
70  virtual Bool_t GetState();
71  virtual void SetState(Bool_t state);
72  virtual void Toggle();
73 
74  virtual void SetOnValue(Long_t lon){fOnValue=lon;};
75  virtual Long_t GetOnValue(){return fOnValue;};
76  virtual void SetOffValue(Long_t lof){fOffValue=lof;};
77  virtual Long_t GetOffValue(){return fOffValue;};
78 
79  virtual Int_t GetValue(){return fValue;};
80  virtual void SetValue(Long_t val);
81 
82  TMethodCall *GetGetter() const { return fGetter; }
83  TMethodCall *GetSetter() const { return fSetter; }
84 
85  ClassDef(TToggle,0) //Facility for toggling datamembers on/off
86 };
87 
88 #endif