EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FairRegistryItemXxx.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file FairRegistryItemXxx.h
1 
2 #ifndef FAIRREGISTRYITEMXXX_H
3 #define FAIRREGISTRYITEMXXX_H
4 
5 #include <TBuffer.h>
6 #include <TObject.h>
7 
8 #include <FairRegistryItem.h>
9 #include <FairRegistry.h>
10 //#include <typeinfo>
11 #include <iostream>
12 
13 template<class T> class FairRegistryItemXxx : public FairRegistryItem
14 {
15  public:
16  // Only Want FairRegistry to call Get/Set/etc methods
17  friend class FairRegistry;
18 
21 
22  void Dump() const { std::cerr << *fData; }
23  void Print(Option_t* /* option */ ="") const { std::cout << *fData; }
24 
25  virtual std::ostream& PrintStream(std::ostream& os) const {
26  return os << *fData;
27  }
28  virtual std::istream& ReadStream(std::istream& is) {
29  if (!fData) { fData = new T; }
30  return is >> *fData;
31  }
32 
33  virtual const std::type_info& GetType() const { return typeid(T); }
34  virtual const char* GetTypeAsString() const { return "void"; }
35 
36  private:
37 
39  T* Get(void); // Only let FairRegistry call
40  void Set(T* data); // these methods.
41  FairRegistryItem* Dup(void) const;
42 
43  T* fData;
44 
47 
48  ClassDefT(FairRegistryItemXxx<T>,1)
49 };
51 
52 
53 // Provide these so C++ base types act like ROOT types inside
54 // a ROOT Streamer function. This lets the same template to be used.
55 TBuffer& operator>>(TBuffer& buf, int*& xptr);
56 TBuffer& operator>>(TBuffer& buf, double*& xptr);
57 TBuffer& operator>>(TBuffer& buf, float*& xptr);
58 
59 TBuffer& operator<<(TBuffer& buf, int*& xptr);
60 TBuffer& operator<<(TBuffer& buf, double*& xptr);
61 TBuffer& operator<<(TBuffer& buf, float*& xptr);
62 
63 #ifndef __CINT__
64 #include <iostream>
65 
67 
68 template<class T>
69 FairRegistryItemXxx<T>::FairRegistryItemXxx(void) : fData(0)
70 {
71 }
72 
73 template<class T>
75 {
76 }
77 
78 template<class T>
80 {
81  if (fData) { delete fData; }
82 }
83 
84 template<class T>
86 {
87  return new FairRegistryItemXxx<T>(new T (*fData));
88 }
89 // see FairRegistryItemXxx.cxx for implementation
90 template<>
92 
93 
94 template<class T>
96 {
97  return fData;
98 }
99 
100 template<class T>
102 {
103  if (fData) { delete fData; }
104  fData = data;
105 }
106 
107 
108 // These specialized templates are in FairRegistryItemXxx.cxx
109 //
110 template<>
112 template<>
113 void FairRegistryItemXxx<char>::Streamer(TBuffer& buf);
114 template<>
116 
117 template<> std::ostream& FairRegistryItemXxx<const char*>::PrintStream(std::ostream& os) const;
118 template<> std::istream& FairRegistryItemXxx<const char*>::ReadStream(std::istream& is);
119 template<> const char* FairRegistryItemXxx<char>::GetTypeAsString(void) const;
120 template<> const char* FairRegistryItemXxx<int>::GetTypeAsString(void) const;
121 template<> const char* FairRegistryItemXxx<double>::GetTypeAsString(void) const;
122 template<> const char* FairRegistryItemXxx<const char*>::GetTypeAsString(void) const;
123 template<> const char* FairRegistryItemXxx<FairRegistry>::GetTypeAsString(void) const;
124 
125 #if (__GNUC__ == 3 && __GNUC_MINOR__ < 3) || __GNUC__ == 2
126 
127 #include <FairRegistry.h>
128 
129 template<> const char* FairRegistryItemXxx<char>::GetTypeAsString(void) const
130 { return "char"; }
131 
132 template<> const char* FairRegistryItemXxx<int>::GetTypeAsString(void) const
133 { return "int"; }
134 
135 template<> const char* FairRegistryItemXxx<double>::GetTypeAsString(void) const
136 { return "double"; }
137 
138 template<> const char* FairRegistryItemXxx<const char*>::GetTypeAsString(void) const
139 { return "string"; }
140 
141 template<> const char* FairRegistryItemXxx<FairRegistry>::GetTypeAsString(void) const
142 { return "FairRegistry"; }
143 
144 template<> std::ostream& FairRegistryItemXxx<FairRegistry>::PrintStream(std::ostream& os) const
145 { return fData->PrintStream(os); }
146 
147 template<> std::istream& FairRegistryItemXxx<FairRegistry>::ReadStream(std::istream& is)
148 { if (!fData) { fData = new FairRegistry(); } return fData->ReadStream(is); }
149 #endif
150 
151 // This assumes that objects spring forth (like ROOT objects)
152 template<class T>
153 void FairRegistryItemXxx<T>::Streamer(TBuffer& buf)
154 {
155  if (buf.IsReading()) {
156  Version_t v = buf.ReadVersion();
157  if (v) { }
158  FairRegistryItem::Streamer(buf);
159 
160  buf >> fData;
161  } else {
162  buf.WriteVersion(IsA());
163  FairRegistryItem::Streamer(buf);
164  buf << fData;
165  }
166 }
167 
168 
169 #include <FairRegistry.h>
170 
171 template<>
172 std::ostream& FairRegistryItemXxx<FairRegistry>::PrintStream(std::ostream& os) const;
173 
174 template<>
175 std::istream& FairRegistryItemXxx<FairRegistry>::ReadStream(std::istream& is);
176 
177 #endif // __CINT__
178 
179 
180 #endif // REGISTRYITEMXXX_H