Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/TGlobal.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // @(#)root/meta:$Id$
0002 // Author: Rene Brun   13/11/95
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TGlobal
0013 #define ROOT_TGlobal
0014 
0015 
0016 //////////////////////////////////////////////////////////////////////////
0017 //                                                                      //
0018 // TGlobal                                                              //
0019 //                                                                      //
0020 // Global variables class (global variables are obtained from CINT).    //
0021 //                                                                      //
0022 //////////////////////////////////////////////////////////////////////////
0023 
0024 #include "TDictionary.h"
0025 
0026 #include <functional>
0027 
0028 class TGlobal : public TDictionary {
0029 
0030 private:
0031    DataMemberInfo_t  *fInfo;      //!pointer to CINT data member info
0032 
0033 public:
0034    TGlobal(DataMemberInfo_t *info = nullptr);
0035    TGlobal (const TGlobal &);
0036    TGlobal &operator=(const TGlobal &);
0037 
0038    virtual       ~TGlobal();
0039    virtual Int_t  GetArrayDim() const;
0040    virtual DeclId_t GetDeclId() const;
0041    virtual Int_t  GetMaxIndex(Int_t dim) const;
0042    virtual void  *GetAddress() const;
0043    virtual const char *GetTypeName() const;
0044    virtual const char *GetFullTypeName() const;
0045    virtual Bool_t IsValid();
0046    Long_t Property() const override;
0047    virtual bool   Update(DataMemberInfo_t *info);
0048 
0049    ClassDefOverride(TGlobal,2)  //Global variable class
0050 };
0051 
0052 // Class to map the "funcky" globals and be able to add them to the list of globals.
0053 class TGlobalMappedFunction : public TGlobal {
0054 public:
0055    typedef void *(*GlobalFunc_t)();
0056    typedef std::function<void *()> GlobalFunctor_t;
0057 
0058    TGlobalMappedFunction(const char *name, const char *type, GlobalFunc_t funcPtr);
0059 
0060    virtual ~TGlobalMappedFunction() = default;
0061    Int_t GetArrayDim() const override { return 0; }
0062    DeclId_t GetDeclId() const override { return (DeclId_t)(fFuncPtr); } // Used as DeclId because of uniqueness
0063    Int_t GetMaxIndex(Int_t /*dim*/) const override { return -1; }
0064    void *GetAddress() const override { return !fFunctor ? (*fFuncPtr)() : fFunctor(); }
0065    const char *GetTypeName() const override { return GetTitle(); }
0066    const char *GetFullTypeName() const override { return GetTitle(); }
0067    Long_t Property() const override { return 0; }
0068    bool Update(DataMemberInfo_t * /*info*/) override { return false; }
0069 
0070    static void Add(TGlobalMappedFunction *gmf);
0071 
0072    template <typename GlobFunc>
0073    static void MakeFunctor(const char *name, const char *type, GlobFunc &func)
0074    {
0075       auto glob = new TGlobalMappedFunction(name, type, (GlobalFunc_t)((void *)&func));
0076       glob->fFunctor = [&func] {
0077          auto &res = func();
0078          return (void *)(&res);
0079       };
0080       Add(glob);
0081    }
0082 
0083    template <typename GlobFunc>
0084    static void MakeFunctor(const char *name, const char *type, GlobFunc &func, GlobalFunctor_t functor)
0085    {
0086       auto glob = new TGlobalMappedFunction(name, type, (GlobalFunc_t)((void *)&func));
0087       glob->fFunctor = functor;
0088       Add(glob);
0089    }
0090 
0091 private:
0092    GlobalFunc_t fFuncPtr{nullptr}; // Function to call to get the address
0093 
0094    GlobalFunctor_t fFunctor; // functor which correctly returns pointer
0095 
0096    TGlobalMappedFunction &operator=(const TGlobal &) = delete;
0097    // Some of the special ones are created before the list is create e.g gFile
0098    // We need to buffer them.
0099    static TList &GetEarlyRegisteredGlobals();
0100 
0101    friend class TROOT;
0102 };
0103 
0104 #endif