Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-02-27 07:20:01

0001 #ifndef FWCore_Reflection_ObjectWithDict_h
0002 #define FWCore_Reflection_ObjectWithDict_h
0003 
0004 /*----------------------------------------------------------------------
0005 
0006 ObjectWithDict:  A holder for an object and its type information.
0007 
0008 ----------------------------------------------------------------------*/
0009 
0010 #include <string>
0011 #include <typeinfo>
0012 
0013 #include "FWCore/Reflection/interface/TypeWithDict.h"
0014 
0015 namespace edm {
0016 
0017   class ObjectWithDict {
0018   private:
0019     TypeWithDict type_;
0020     void* address_;
0021 
0022   public:
0023     static ObjectWithDict byType(TypeWithDict const&);
0024 
0025   public:
0026     ObjectWithDict() : address_(nullptr) {}
0027     explicit ObjectWithDict(TypeWithDict const& type, void* address) : type_(type), address_(address) {}
0028     explicit ObjectWithDict(std::type_info const& type, void* address) : type_(TypeWithDict(type)), address_(address) {}
0029     explicit operator bool() const { return bool(type_) && (address_ != nullptr); }
0030     void* address() const { return address_; }
0031     TypeWithDict const& typeOf() const { return type_; }
0032     TypeWithDict dynamicType() const;
0033     ObjectWithDict castObject(TypeWithDict const&) const;
0034     ObjectWithDict get(std::string const& memberName) const;
0035     //ObjectWithDict construct() const;
0036     void destruct(bool dealloc) const;
0037 
0038     template <typename T>
0039     T& objectCast() {
0040       return *reinterpret_cast<T*>(address());
0041     }
0042 
0043     template <typename T>
0044     T const& objectCast() const {
0045       return *reinterpret_cast<T*>(address());
0046     }
0047   };
0048 
0049 }  // namespace edm
0050 
0051 #endif  // FWCore_Reflection_ObjectWithDict_h