#ifndef __JROOT__JROOTDICTIONARY__ #define __JROOT__JROOTDICTIONARY__ #include #include #include #include "TDictionary.h" #include "JLang/JType.hh" #include "JLang/JNullType.hh" #include "JLang/JTypeList.hh" #include "JLang/JPrimitiveTypes.hh" #include "JLang/JException.hh" #include "JLang/JSingleton.hh" #include "JROOT/JRootDictionary_t.hh" #include "JROOT/JRootStreamer.hh" /** * \author mdejong */ namespace JROOT {} namespace JPP { using namespace JROOT; } namespace JROOT { using JLANG::JType; using JLANG::JNullType; using JLANG::JTypeList; using JLANG::JTYPELIST; using JLANG::JException; using JLANG::JSingleton; /** * Default implementation of ROOT based dictionary for ASCII I/O. */ class JRootDictionary : public JRootDictionary_t, public JSingleton { public: /** * Default constructor. * * This constructor builds a default dictionary which includes all primitive data types and std::vector thereof. * * Removed types: * - long double (not supported by ROOT TDictionary) * * Added STL type definitions: * - std::string * - size_t * - std::size_t * * Added ROOT type definitions: * - [U]Char_t * - [U]Short_t * - [U]Int_t * - [U]Long64_t * - [U]Float_t * - [U]Double_t */ JRootDictionary() : JRootDictionary_t() { #define VALUE_TYPE(__TYPE__) value_type(#__TYPE__, new JObjectStreamer<__TYPE__>()) using namespace JPP; this->add(JType::typelist>()); this->add(JType()); this->insert(VALUE_TYPE(size_t)); this->insert(VALUE_TYPE(std::size_t)); this->insert(VALUE_TYPE(Char_t)); this->insert(VALUE_TYPE(UChar_t)); this->insert(VALUE_TYPE(Short_t)); this->insert(VALUE_TYPE(UShort_t)); this->insert(VALUE_TYPE(Int_t)); this->insert(VALUE_TYPE(UInt_t)); this->insert(VALUE_TYPE(Long64_t)); this->insert(VALUE_TYPE(ULong64_t)); this->insert(VALUE_TYPE(Float_t)); this->insert(VALUE_TYPE(Double_t)); #undef VALUE_TYPE } /** * Get typename for given template class. * * This method uses the TDictionary class to get the name of the given class. * * \return type name */ template static const char* getTypename() { const TDictionary* pDictionary = TDictionary::GetDictionary(typeid(T)); if (pDictionary != NULL) return pDictionary->GetName(); else THROW(JException, "Data type not implemented."); } /** * Add ASCII I/O for given (list of) class(es) to dictionary. */ template void add() { add(JType()); } protected: /** * Addition of class. * * \param type data type */ template void add(const JType& type) { this->insert(value_type(getTypename(), new JObjectStreamer())); try { this->insert(value_type(getTypename< std::vector >(), new JObjectStreamer< std::vector >())); } catch(const JException& error) {}; } /** * Addition of std::vector. * * \param type data type */ template void add(const JType< std::vector >& type) { typedef std::vector data_type; this->insert(value_type(getTypename(), new JObjectStreamer())); } /** * Recursive addition of classes. * * \param typelist type list */ template void add(const JType< JTypeList >& typelist) { add(JType()); add(JType()); } /** * Template specialisation to terminate addition of classes. * * \param type null type */ void add(const JType& type) {} }; } /** * Global ROOT based dictionary for ASCII I/O. */ #define gRootDictionary (JROOT::JRootDictionary::getInstance()) /** * Add ASCII I/O for (list of) class(es) to dictionary. */ template inline void addToRootDictionary() { gRootDictionary.add(); } /** * Add ASCII I/O for given object to dictionary. * * \param object object */ template inline void addToRootDictionary(const T& object) { gRootDictionary.add(); } #endif