ROOT logo
// @(#)root/meta:$Id$
// Author: Piotr Golonka   30/07/97

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TToggle
#define ROOT_TToggle


//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TToggle                                                              //
//                                                                      //
// This class defines toggling facility for both - object's method or   //
// variables.                                                           //
// Assume that user provides an object with a two-state field, and      //
// methods to Get/Set value of this field. This object enables to switch//
// values via this method when the only thing you know about the field  //
// is the name of the method (or method itself) which sets the field.   //
// This facility is required in context popup menu, when the only       //
// information about how to toggle a field is a name of method which    //
// sets it.                                                             //
// This Object may be also used for toggling an integer variable,       //
// which may be important while building universal objects...           //
// When user provides a "set-method" of name SetXXX this object tries   //
// automaticaly to find a matching "get-method" by looking for a method //
// with name GetXXX or IsXXX for given object.                          //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TObject
#include "TObject.h"
#endif
#ifndef ROOT_TMethodCall
#include "TMethodCall.h"
#endif
#ifndef ROOT_TMethod
#include "TMethod.h"
#endif
#ifndef ROOT_TNamed
#include "TNamed.h"
#endif


class TToggle: public TNamed {

private:
   Bool_t       fState;        //Object's state - "a local copy"
   Long_t       fOnValue;      //Value recognized as switched ON (Def=1)
   Long_t       fOffValue;     //Value recognized as switched OFF(Def=0)
   Long_t       fValue;        //Local copy of a value returned by called function

protected:
   Bool_t       fInitialized;  //True if either SetToggledObject or SetToggledVariable called - enables Toggle() method.
   TObject     *fObject;       //The object this Toggle belongs to
   TMethodCall *fGetter;       //Method to Get a value of fObject;
   TMethodCall *fSetter;       //Method to Set a value of fObject;

   Int_t       *fTglVariable;  //Alternatively: pointer to an integer value to be Toggled instead of TObjectl

public:
   TToggle();
   virtual void    SetToggledObject(TObject *obj, TMethod *anymethod);

   // you just provide any method which has got an initialized pointer
   // to TDataMember... The rest is done automatically...

   virtual void    SetToggledVariable(Int_t &var);

   virtual Bool_t  IsInitialized(){return fInitialized;};

   virtual Bool_t  GetState();
   virtual void    SetState(Bool_t state);
   virtual void    Toggle();

   virtual void    SetOnValue(Long_t lon){fOnValue=lon;};
   virtual Long_t  GetOnValue(){return fOnValue;};
   virtual void    SetOffValue(Long_t lof){fOffValue=lof;};
   virtual Long_t  GetOffValue(){return fOffValue;};

   virtual Int_t   GetValue(){return fValue;};
   virtual void    SetValue(Long_t val);

   TMethodCall    *GetGetter() const { return fGetter; }
   TMethodCall    *GetSetter() const { return fSetter; }

   ClassDef(TToggle,0)  //Facility for toggling datamembers on/off
};

#endif
 TToggle.h:1
 TToggle.h:2
 TToggle.h:3
 TToggle.h:4
 TToggle.h:5
 TToggle.h:6
 TToggle.h:7
 TToggle.h:8
 TToggle.h:9
 TToggle.h:10
 TToggle.h:11
 TToggle.h:12
 TToggle.h:13
 TToggle.h:14
 TToggle.h:15
 TToggle.h:16
 TToggle.h:17
 TToggle.h:18
 TToggle.h:19
 TToggle.h:20
 TToggle.h:21
 TToggle.h:22
 TToggle.h:23
 TToggle.h:24
 TToggle.h:25
 TToggle.h:26
 TToggle.h:27
 TToggle.h:28
 TToggle.h:29
 TToggle.h:30
 TToggle.h:31
 TToggle.h:32
 TToggle.h:33
 TToggle.h:34
 TToggle.h:35
 TToggle.h:36
 TToggle.h:37
 TToggle.h:38
 TToggle.h:39
 TToggle.h:40
 TToggle.h:41
 TToggle.h:42
 TToggle.h:43
 TToggle.h:44
 TToggle.h:45
 TToggle.h:46
 TToggle.h:47
 TToggle.h:48
 TToggle.h:49
 TToggle.h:50
 TToggle.h:51
 TToggle.h:52
 TToggle.h:53
 TToggle.h:54
 TToggle.h:55
 TToggle.h:56
 TToggle.h:57
 TToggle.h:58
 TToggle.h:59
 TToggle.h:60
 TToggle.h:61
 TToggle.h:62
 TToggle.h:63
 TToggle.h:64
 TToggle.h:65
 TToggle.h:66
 TToggle.h:67
 TToggle.h:68
 TToggle.h:69
 TToggle.h:70
 TToggle.h:71
 TToggle.h:72
 TToggle.h:73
 TToggle.h:74
 TToggle.h:75
 TToggle.h:76
 TToggle.h:77
 TToggle.h:78
 TToggle.h:79
 TToggle.h:80
 TToggle.h:81
 TToggle.h:82
 TToggle.h:83
 TToggle.h:84
 TToggle.h:85
 TToggle.h:86
 TToggle.h:87
 TToggle.h:88
 TToggle.h:89
 TToggle.h:90
 TToggle.h:91
 TToggle.h:92
 TToggle.h:93
 TToggle.h:94
 TToggle.h:95
 TToggle.h:96