TToggle.h

Go to the documentation of this file.
00001 // @(#)root/meta:$Id: TToggle.h 28005 2009-03-31 13:12:24Z brun $
00002 // Author: Piotr Golonka   30/07/97
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TToggle
00013 #define ROOT_TToggle
00014 
00015 
00016 //////////////////////////////////////////////////////////////////////////
00017 //                                                                      //
00018 // TToggle                                                              //
00019 //                                                                      //
00020 // This class defines toggling facility for both - object's method or   //
00021 // variables.                                                           //
00022 // Assume that user provides an object with a two-state field, and      //
00023 // methods to Get/Set value of this field. This object enables to switch//
00024 // values via this method when the only thing you know about the field  //
00025 // is the name of the method (or method itself) which sets the field.   //
00026 // This facility is required in context popup menu, when the only       //
00027 // information about how to toggle a field is a name of method which    //
00028 // sets it.                                                             //
00029 // This Object may be also used for toggling an integer variable,       //
00030 // which may be important while building universal objects...           //
00031 // When user provides a "set-method" of name SetXXX this object tries   //
00032 // automaticaly to find a matching "get-method" by looking for a method //
00033 // with name GetXXX or IsXXX for given object.                          //
00034 //                                                                      //
00035 //////////////////////////////////////////////////////////////////////////
00036 
00037 #ifndef ROOT_TObject
00038 #include "TObject.h"
00039 #endif
00040 #ifndef ROOT_TMethodCall
00041 #include "TMethodCall.h"
00042 #endif
00043 #ifndef ROOT_TMethod
00044 #include "TMethod.h"
00045 #endif
00046 #ifndef ROOT_TNamed
00047 #include "TNamed.h"
00048 #endif
00049 
00050 
00051 class TToggle: public TNamed {
00052 
00053 private:
00054    Bool_t       fState;        //Object's state - "a local copy"
00055    Long_t       fOnValue;      //Value recognized as switched ON (Def=1)
00056    Long_t       fOffValue;     //Value recognized as switched OFF(Def=0)
00057    Long_t       fValue;        //Local copy of a value returned by called function
00058 
00059 protected:
00060    Bool_t       fInitialized;  //True if either SetToggledObject or SetToggledVariable called - enables Toggle() method.
00061    TObject     *fObject;       //The object this Toggle belongs to
00062    TMethodCall *fGetter;       //Method to Get a value of fObject;
00063    TMethodCall *fSetter;       //Method to Set a value of fObject;
00064 
00065    Int_t       *fTglVariable;  //Alternatively: pointer to an integer value to be Toggled instead of TObjectl
00066 
00067 public:
00068    TToggle();
00069    virtual void    SetToggledObject(TObject *obj, TMethod *anymethod);
00070 
00071    // you just provide any method which has got an initialized pointer
00072    // to TDataMember... The rest is done automatically...
00073 
00074    virtual void    SetToggledVariable(Int_t &var);
00075 
00076    virtual Bool_t  IsInitialized(){return fInitialized;};
00077 
00078    virtual Bool_t  GetState();
00079    virtual void    SetState(Bool_t state);
00080    virtual void    Toggle();
00081 
00082    virtual void    SetOnValue(Long_t lon){fOnValue=lon;};
00083    virtual Long_t  GetOnValue(){return fOnValue;};
00084    virtual void    SetOffValue(Long_t lof){fOffValue=lof;};
00085    virtual Long_t  GetOffValue(){return fOffValue;};
00086 
00087    virtual Int_t   GetValue(){return fValue;};
00088    virtual void    SetValue(Long_t val);
00089 
00090    TMethodCall    *GetGetter() const { return fGetter; }
00091    TMethodCall    *GetSetter() const { return fSetter; }
00092 
00093    ClassDef(TToggle,0)  //Facility for toggling datamembers on/off
00094 };
00095 
00096 #endif

Generated on Tue Jul 5 14:11:41 2011 for ROOT_528-00b_version by  doxygen 1.5.1