/
FairRegistryItemXxx.cxx
207 lines (174 loc) · 4.17 KB
/
FairRegistryItemXxx.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#include <TBuffer.h>
#include <TObject.h>
#include "FairRegistryItem.h"
#include "FairRegistryItemXxx.h"
#include <FairUtilStream.h>
#include <string>
using namespace std;
#if (__GNUC__ == 3 && __GNUC_MINOR__ >= 3) || (__GNUC__ >=4 )
template<> const char* FairRegistryItemXxx<char>::GetTypeAsString(void) const
{ return "char"; }
template<> const char* FairRegistryItemXxx<int>::GetTypeAsString(void) const
{ return "int"; }
template<> const char* FairRegistryItemXxx<double>::GetTypeAsString(void) const
{ return "double"; }
template<> const char* FairRegistryItemXxx<const char*>::GetTypeAsString(void) const
{ return "string"; }
template<> const char* FairRegistryItemXxx<FairRegistry>::GetTypeAsString(void) const
{ return "FairRegistry"; }
template<> std::ostream& FairRegistryItemXxx<FairRegistry>::PrintStream(std::ostream& os) const
{ return fData->PrintStream(os); }
template<> std::istream& FairRegistryItemXxx<FairRegistry>::ReadStream(std::istream& is)
{ if (!fData) { fData = new FairRegistry(); } return fData->ReadStream(is); }
#endif
TBuffer& operator>>(TBuffer& buf, int*& xptr)
{
int x;
buf >> x;
xptr = new int(x);
return buf;
}
TBuffer& operator>>(TBuffer& buf, double*& xptr)
{
double x;
buf >> x;
xptr = new double(x);
return buf;
}
TBuffer& operator>>(TBuffer& buf, float*& xptr)
{
float x;
buf >> x;
xptr = new float(x);
return buf;
}
#if 0
TBuffer& operator>>(TBuffer& buf, bool*& xptr)
{
int i;
buf >> i;
if (i) { xptr = new bool(true); }
else { xptr = new bool(false); }
return buf;
}
#endif
//......................................
TBuffer& operator<<(TBuffer& buf, int*& xptr)
{
buf << *xptr;
return buf;
}
TBuffer& operator<<(TBuffer& buf, double*& xptr)
{
buf << *xptr;
return buf;
}
TBuffer& operator<<(TBuffer& buf, float*& xptr)
{
buf << *xptr;
return buf;
}
#if 0
TBuffer& operator<<(TBuffer& buf, bool*& xptr)
{
buf << (*xptr ? 1 : 0);
return buf;
}
#endif
#if 0
TBuffer& operator<<(TBuffer& buf, const char*& xptr)
{
const char* x = xptr;
--x;
do {
++x;
buf << *x;
} while (*x);
return buf;
}
#endif
#include <string>
template<>
void FairRegistryItemXxx<const char*>::Streamer(TBuffer& buf)
{
if (buf.IsReading()) {
Version_t v = buf.ReadVersion();
if (v) { }
FairRegistryItem::Streamer(buf);
std::string str = "";
char x[2];
x[1] = '\0';
do { // read out string one byte at a time
buf >> x[0];
str += x;
} while (x[0]);
char** ppchar = new char*;
*ppchar = new char[str.length() + 1];
strcpy(*ppchar,str.c_str());
(*ppchar)[str.length()] = '\0'; // paranoia
fData = const_cast<const char**>(ppchar);
} else {
buf.WriteVersion(IsA());
FairRegistryItem::Streamer(buf);
buf << (*fData);
}
}
// Must do this special because ROOT treats char and char* asymmetric
template<>
void FairRegistryItemXxx<char>::Streamer(TBuffer& buf)
{
if (buf.IsReading()) {
Version_t v = buf.ReadVersion();
if (v) { }
FairRegistryItem::Streamer(buf);
char c;
buf >> c;
fData = new char(c);
} else {
buf.WriteVersion(IsA());
FairRegistryItem::Streamer(buf);
buf << *fData;
}
}
template<>
std::ostream& FairRegistryItemXxx<const char*>::PrintStream(std::ostream& os) const
{
os << "'" << *fData << "'";
return os;
}
template<>
std::istream& FairRegistryItemXxx<const char*>::ReadStream(std::istream& is)
{
string stot = Util::read_quoted_string(is);
if (!fData) {
char** ppchar = new char*;
*ppchar = 0;
fData = const_cast<const char**>(ppchar);
}
if (*fData) { delete [] *fData; }
char* pchar = new char[stot.length() + 1];
strcpy(pchar,stot.c_str());
*fData = const_cast<const char*>(pchar);
return is;
}
template<>
FairRegistryItemXxx<const char*>::~FairRegistryItemXxx()
{
if (fData) {
if (*fData) {
delete [] *fData;
*fData = 0;
}
delete fData;
fData = 0;
}
}
template<>
FairRegistryItem* FairRegistryItemXxx<const char*>::Dup(void) const
{
char** ppc = new char*;
(*ppc) = new char [strlen(*fData)+1];
strcpy(*ppc,*fData);
const char** ppcc = const_cast<const char**>(ppc);
return new FairRegistryItemXxx< const char* >(ppcc);
}