Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JRootDictionary.hh
Go to the documentation of this file.
1#ifndef __JROOT__JROOTDICTIONARY__
2#define __JROOT__JROOTDICTIONARY__
3
4#include <string>
5#include <vector>
6#include <typeinfo>
7
8#include "TDictionary.h"
9
10#include "JLang/JType.hh"
11#include "JLang/JNullType.hh"
12#include "JLang/JTypeList.hh"
14#include "JLang/JException.hh"
15#include "JLang/JSingleton.hh"
16#include "JROOT/JRoot.hh"
19
20
21/**
22 * \author mdejong
23 */
24
25namespace JROOT {}
26namespace JPP { using namespace JROOT; }
27
28namespace JROOT {
29
30 using JLANG::JType;
31 using JLANG::JNullType;
32 using JLANG::JTypeList;
33 using JLANG::JTYPELIST;
36
37 /**
38 * Default implementation of ROOT based dictionary for ASCII I/O.
39 */
41 public JRootDictionary_t,
42 public JSingleton<JRootDictionary>
43 {
44 public:
45 /**
46 * Default constructor.
47 *
48 * This constructor builds a default dictionary which includes all primitive data types and <tt>std::vector</tt> thereof.
49 *
50 * Removed types:
51 * - <tt>long double</tt> (not supported by ROOT <tt>TDictionary</tt>)
52 *
53 * Added STL type definitions:
54 * - <tt>std::string</tt>
55 * - <tt>std::size_t</tt>
56 *
57 * Added ROOT type definitions:
58 * - <tt>[U]Char_t </tt>
59 * - <tt>[U]Short_t </tt>
60 * - <tt>[U]Int_t </tt>
61 * - <tt>[U]Long64_t</tt>
62 * - <tt>[U]Float_t </tt>
63 * - <tt>[U]Double_t</tt>
64 */
67 {
68#define VALUE_TYPE(__TYPE__) value_type(#__TYPE__, new JObjectStreamer<__TYPE__>())
69
70 using namespace JPP;
71
73
74 (*this)(JType<std::string>());
75 (*this)(JType<std::size_t>());
76
77 this->insert(VALUE_TYPE(Char_t));
78 this->insert(VALUE_TYPE(UChar_t));
79 this->insert(VALUE_TYPE(Short_t));
80 this->insert(VALUE_TYPE(UShort_t));
81 this->insert(VALUE_TYPE(Int_t));
82 this->insert(VALUE_TYPE(UInt_t));
83 this->insert(VALUE_TYPE(Long_t));
84 this->insert(VALUE_TYPE(ULong_t));
85 this->insert(VALUE_TYPE(Long64_t));
86 this->insert(VALUE_TYPE(ULong64_t));
87 this->insert(VALUE_TYPE(Float_t));
88 this->insert(VALUE_TYPE(Double_t));
89
90#undef VALUE_TYPE
91 }
92
93 /**
94 * Addition of class.
95 *
96 * \param type data type
97 */
98 template<class T>
99 void operator()(const JType<T>& type)
100 {
101 this->insert(value_type(JRoot::getTypename<T>(), new JObjectStreamer<T>()));
102
103 try {
104 this->insert(value_type(JRoot::getTypename< std::vector<T> >(), new JObjectStreamer< std::vector<T> >()));
105 }
106 catch(const JException& error) {};
107 }
108
109 /**
110 * Addition of class.
111 */
112 template<class T>
113 void add()
114 {
115 (*this)(JType<T>());
116 }
117 };
118}
119
120
121/**
122 * Global ROOT based dictionary for ASCII I/O.
123 */
124#define gRootDictionary (JROOT::JRootDictionary::getInstance())
125
126
127/**
128 * Add ASCII I/O for (list of) class(es) to dictionary.
129 */
130template<class T>
132{
133 gRootDictionary.add<T>();
134}
135
136
137/**
138 * Add ASCII I/O for given object to dictionary.
139 *
140 * \param object object
141 */
142template<class T>
143inline void addToRootDictionary(const T& object)
144{
145 gRootDictionary.add<T>();
146}
147
148#endif
Exceptions.
Type list of primitive data types.
#define VALUE_TYPE(__TYPE__)
#define gRootDictionary
Global ROOT based dictionary for ASCII I/O.
void addToRootDictionary()
Add ASCII I/O for (list of) class(es) to dictionary.
ASCII I/O of objects with ROOT dictionary.
General exception.
Definition JException.hh:24
JObjectStreamer class.
Default implementation of ROOT based dictionary for ASCII I/O.
void operator()(const JType< T > &type)
Addition of class.
void add()
Addition of class.
JRootDictionary()
Default constructor.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for ROOT I/O.
Auxiliary class for no type definition.
Definition JNullType.hh:19
Removal of data type from type list.
Definition JTypeList.hh:114
Simple singleton class.
Definition JSingleton.hh:18
Auxiliary class for recursive type list generation.
Definition JTypeList.hh:351
Type list.
Definition JTypeList.hh:23
Auxiliary class for a type holder.
Definition JType.hh:19
Type definition of ROOT based dictionary for ASCII I/O.
static const char * getTypename()
Get ROOT typename for given template class.
Definition JRoot.hh:138