Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
40class TMethodCall;
41class TMethod;
42#else
43#include "TMethodCall.h"
44#include "TMethod.h"
45#endif
46
47class TToggle: public TNamed {
48
49private:
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
55protected:
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
63public:
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 ClassDefOverride(TToggle,0) //Facility for toggling datamembers on/off
90};
91
92#endif
bool Bool_t
Definition RtypesCore.h:63
long Longptr_t
Definition RtypesCore.h:75
long Long_t
Definition RtypesCore.h:54
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
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:41
This class defines toggling facility for both - object's method or variables.
Definition TToggle.h:47
TToggle()
TToggle default constructor.
Definition TToggle.cxx:42
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
Int_t * fTglVariable
Definition TToggle.h:61
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
virtual Long_t GetOnValue()
Definition TToggle.h:79
virtual void SetOffValue(Long_t lof)
Definition TToggle.h:80
TObject * fObject
Definition TToggle.h:57
Long_t fOffValue
Definition TToggle.h:52
virtual Int_t GetValue()
Definition TToggle.h:83
virtual void Toggle()
Toggles the Values and State of this object and connected data!
Definition TToggle.cxx:112
virtual void SetOnValue(Long_t lon)
Definition TToggle.h:78
TMethodCall * fSetter
Definition TToggle.h:59
virtual Bool_t IsInitialized()
Definition TToggle.h:72
Longptr_t fValue
Definition TToggle.h:53
TMethodCall * fGetter
Definition TToggle.h:58
Long_t fOnValue
Definition TToggle.h:51
TMethodCall * GetSetter() const
Definition TToggle.h:87
Bool_t fInitialized
Definition TToggle.h:56
TMethodCall * GetGetter() const
Definition TToggle.h:86
virtual void SetToggledObject(TObject *obj, TMethod *anymethod)
Initializes it to toggle an object's datamember using this object's method.
Definition TToggle.cxx:135
virtual Long_t GetOffValue()
Definition TToggle.h:81
Bool_t fState
Definition TToggle.h:50
virtual void SetState(Bool_t state)
Sets the value of toggle to fOnValue or fOffValue according to passed argument.
Definition TToggle.cxx:80
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