Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:13:01

0001 #ifndef FWCore_Reflection_TypeWithDict_h
0002 #define FWCore_Reflection_TypeWithDict_h
0003 
0004 /*----------------------------------------------------------------------
0005 
0006 TypeWithDict: A unique identifier for a C++ type, with the dictionary information
0007 
0008 The identifier is unique within an entire program, but can not be
0009 persisted across invocations of the program.
0010 
0011 ----------------------------------------------------------------------*/
0012 #include "FWCore/Reflection/interface/IterWithDict.h"
0013 #include "FWCore/Utilities/interface/value_ptr.h"
0014 
0015 #include "TBaseClass.h"
0016 #include "TClass.h"
0017 #include "TDataMember.h"
0018 #include "TDataType.h"
0019 #include "TEnum.h"
0020 #include "TMethod.h"
0021 #include "TMethodArg.h"
0022 
0023 #include <iosfwd>
0024 #include <string>
0025 #include <typeinfo>
0026 #include <vector>
0027 
0028 namespace edm {
0029 
0030   class FunctionWithDict;
0031   class MemberWithDict;
0032   class ObjectWithDict;
0033 
0034   class TypeBases;
0035   class TypeDataMembers;
0036   class TypeFunctionMembers;
0037 
0038   class TypeWithDict {
0039     friend class TypeBases;
0040     friend class TypeDataMembers;
0041     friend class TypeFunctionMembers;
0042     friend bool operator==(TypeWithDict const&, std::type_info const&);
0043     typedef enum {} dummyType;        // Tag for valid type, but no type_info information
0044     typedef dummyType** invalidType;  // Tag for invalid type
0045   private:
0046     std::type_info const* ti_;
0047     TClass* class_;
0048     TEnum* enum_;
0049     TDataType* dataType_;
0050     value_ptr<std::vector<size_t> > arrayDimensions_;
0051     long property_;
0052 
0053   public:
0054     static TypeWithDict byName(std::string const& name);
0055     static TypeWithDict byTypeInfo(std::type_info const& ti);
0056 
0057   private:
0058     static TypeWithDict byName(std::string const& name, long property);
0059 
0060   public:
0061     TypeWithDict();
0062     TypeWithDict(TypeWithDict const&);
0063     explicit TypeWithDict(TClass* type);
0064     explicit TypeWithDict(TEnum* type);
0065     explicit TypeWithDict(std::type_info const&);
0066     explicit TypeWithDict(TMethodArg* arg);
0067 
0068   private:
0069     explicit TypeWithDict(std::type_info const&, long property);
0070     explicit TypeWithDict(TClass* type, long property);
0071     explicit TypeWithDict(TEnum* type, long property);
0072     explicit TypeWithDict(TMethodArg* arg, long property);
0073 
0074   public:
0075     TypeWithDict& operator=(TypeWithDict const&);
0076     TypeWithDict& stripConstRef();
0077     explicit operator bool() const;
0078     bool invalidTypeInfo() const;
0079     std::type_info const& typeInfo() const;
0080     //Do not check is 'invalidTypeInfo()' would return true
0081     std::type_info const& unvalidatedTypeInfo() const { return *ti_; }
0082     TClass* getClass() const;
0083     TEnum* getEnum() const;
0084     TDataType* getDataType() const;
0085     long getProperty() const;
0086     bool isClass() const;
0087     bool isConst() const;
0088     bool isArray() const;
0089     bool isEnum() const;
0090     bool isFundamental() const;
0091     bool isPointer() const;
0092     bool isReference() const;
0093     bool isTemplateInstance() const;
0094     bool isTypedef() const;
0095     bool isVirtual() const;
0096     std::string qualifiedName() const;
0097     std::string cppName() const;
0098     std::string unscopedName() const;
0099     std::string name() const;
0100     std::string userClassName() const;
0101     std::string friendlyClassName() const;
0102     std::string templateName() const;
0103     size_t size() const;
0104     size_t arrayLength() const;
0105     size_t arrayDimension() const;
0106     size_t maximumIndex(size_t dim) const;
0107     size_t dataMemberSize() const;
0108     size_t functionMemberSize() const;
0109     MemberWithDict dataMemberByName(std::string const&) const;
0110     // Note: Used only by FWCore/Modules/src/EventContentAnalyzer.cc
0111     FunctionWithDict functionMemberByName(std::string const&) const;
0112     // Note: Used only by Fireworks/Core/src/FWModelContextMenuHandler.cc:262
0113     //FunctionWithDict functionMemberByName(std::string const& name, TypeWithDict const& signature, int mods, TypeMemberQuery memberQuery) const;
0114     // Note: Used only by CondFormats/PhysicsToolsObjects/src/MVAComputer.cc
0115     FunctionWithDict functionMemberByName(std::string const& name, std::string const& proto, bool isConst) const;
0116     TypeWithDict nestedType(char const*) const;
0117     TypeWithDict nestedType(std::string const&) const;
0118     TypeWithDict finalType() const;
0119     TypeWithDict toType() const;
0120     void print(std::ostream& os) const;
0121     bool hasBase(std::string const&) const;
0122     bool hasBase(TypeWithDict const& basety) const;
0123     int getBaseClassOffset(TypeWithDict const& baseClass) const;
0124     TypeWithDict templateArgumentAt(size_t index) const;
0125     void const* pointerToBaseType(void const* ptr, TypeWithDict const& derivedType) const;
0126     void const* pointerToContainedType(void const* ptr, TypeWithDict const& derivedType) const;
0127     int stringToEnumValue(std::string const&) const;
0128     void* allocate() const;
0129     void deallocate(void* address) const;
0130     ObjectWithDict construct() const;
0131     void destruct(void* address, bool dealloc = true) const;
0132   };
0133 
0134   // A related free function
0135   bool hasDictionary(std::type_info const&);
0136 
0137   inline bool operator<(TypeWithDict const& a, TypeWithDict const& b) { return a.name() < b.name(); }
0138 
0139   bool operator==(TypeWithDict const& a, TypeWithDict const& b);
0140 
0141   inline bool operator!=(TypeWithDict const& a, TypeWithDict const& b) { return !(a == b); }
0142 
0143   bool operator==(TypeWithDict const& a, std::type_info const& b);
0144 
0145   inline bool operator!=(TypeWithDict const& a, std::type_info const& b) { return !(a == b); }
0146 
0147   inline bool operator==(std::type_info const& a, TypeWithDict const& b) { return b == a; }
0148 
0149   inline bool operator!=(std::type_info const& a, TypeWithDict const& b) { return !(b == a); }
0150 
0151   std::ostream& operator<<(std::ostream& os, TypeWithDict const& id);
0152 
0153   class TypeBases {
0154   private:
0155     TClass* class_;
0156 
0157   public:
0158     explicit TypeBases(TypeWithDict const&);
0159     IterWithDict<TBaseClass> begin() const;
0160     IterWithDict<TBaseClass> end() const;
0161     size_t size() const;
0162   };
0163 
0164   class TypeDataMembers {
0165   private:
0166     TClass* class_;
0167 
0168   public:
0169     explicit TypeDataMembers(TypeWithDict const&);
0170     IterWithDict<TDataMember> begin() const;
0171     IterWithDict<TDataMember> end() const;
0172     size_t size() const;
0173   };
0174 
0175   class TypeFunctionMembers {
0176   private:
0177     TClass* class_;
0178 
0179   public:
0180     explicit TypeFunctionMembers(TypeWithDict const&);
0181     IterWithDict<TMethod> begin() const;
0182     IterWithDict<TMethod> end() const;
0183     size_t size() const;
0184   };
0185 
0186 }  // namespace edm
0187 
0188 #include "FWCore/Reflection/interface/FunctionWithDict.h"
0189 #include "FWCore/Reflection/interface/MemberWithDict.h"
0190 #include "FWCore/Reflection/interface/ObjectWithDict.h"
0191 
0192 #endif  // FWCore_Reflection_TypeWithDict_h