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
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TGlobal
0013 #define ROOT_TGlobal
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 #include "TDictionary.h"
0025
0026 #include <functional>
0027
0028 class TGlobal : public TDictionary {
0029
0030 private:
0031 DataMemberInfo_t *fInfo;
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)
0050 };
0051
0052
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); }
0063 Int_t GetMaxIndex(Int_t ) 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 * ) 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};
0093
0094 GlobalFunctor_t fFunctor;
0095
0096 TGlobalMappedFunction &operator=(const TGlobal &) = delete;
0097
0098
0099 static TList &GetEarlyRegisteredGlobals();
0100
0101 friend class TROOT;
0102 };
0103
0104 #endif