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 "TObject.h"
38#include "TMethodCall.h"
39#include "TMethod.h"
40#include "TNamed.h"
41
42
43class TToggle: public TNamed {
44
45private:
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
51protected:
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
59public:
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
int Int_t
Definition: RtypesCore.h:41
long Long_t
Definition: RtypesCore.h:50
bool Bool_t
Definition: RtypesCore.h:59
#define ClassDef(name, id)
Definition: Rtypes.h:326
Method or function calling interface.
Definition: TMethodCall.h:37
Each ROOT class (see TClass) has a linked list of methods.
Definition: TMethod.h:38
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
Mother of all ROOT objects.
Definition: TObject.h:37
This class defines toggling facility for both - object's method or variables.
Definition: TToggle.h:43
Long_t fValue
Definition: TToggle.h:49
TToggle()
TToggle default constructor.
Definition: TToggle.cxx:41
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
Int_t * fTglVariable
Definition: TToggle.h:57
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 Long_t GetOnValue()
Definition: TToggle.h:75
virtual void SetOffValue(Long_t lof)
Definition: TToggle.h:76
TObject * fObject
Definition: TToggle.h:53
Long_t fOffValue
Definition: TToggle.h:48
virtual Int_t GetValue()
Definition: TToggle.h:79
virtual void Toggle()
Toggles the Values and State of this object and connected data!
Definition: TToggle.cxx:111
virtual void SetOnValue(Long_t lon)
Definition: TToggle.h:74
TMethodCall * fSetter
Definition: TToggle.h:55
virtual Bool_t IsInitialized()
Definition: TToggle.h:68
TMethodCall * fGetter
Definition: TToggle.h:54
Long_t fOnValue
Definition: TToggle.h:47
TMethodCall * GetSetter() const
Definition: TToggle.h:83
Bool_t fInitialized
Definition: TToggle.h:52
TMethodCall * GetGetter() const
Definition: TToggle.h:82
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 Long_t GetOffValue()
Definition: TToggle.h:77
Bool_t fState
Definition: TToggle.h:46
virtual void SetState(Bool_t state)
Sets the value of toggle to fOnValue or fOffValue according to passed argument.
Definition: TToggle.cxx:79
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