forked from mgmarino/OrcaROOT
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathORDictionary.cc
169 lines (158 loc) · 5.35 KB
/
ORDictionary.cc
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
// ORDictionary.cc
#include "ORDictionary.hh"
#include "ORLogger.hh"
#include <sstream>
ORDictionary::ORDictionary(const ORDictionary& dict) : ORVDictValue(dict)
{
SetName(dict.fName);
/* Now the hard part, copying the dictionary map correctly calling
all the copy constructors. */
DictMap::const_iterator dictIter;
for (dictIter = dict.fDictMap.begin();dictIter!=dict.fDictMap.end();dictIter++) {
EValType type = dictIter->second->GetValueType();
ORVDictValue* insertDictValue = NULL;
switch (type) {
case kDict:
insertDictValue = new ORDictionary((*(ORDictionary*)dictIter->second));
break;
case kString:
insertDictValue = new ORDictValueS((*(ORDictValueS*)dictIter->second));
break;
case kReal:
insertDictValue = new ORDictValueR((*(ORDictValueR*)dictIter->second));
break;
case kInt:
insertDictValue = new ORDictValueI((*(ORDictValueI*)dictIter->second));
break;
case kBool:
insertDictValue = new ORDictValueB((*(ORDictValueB*)dictIter->second));
break;
case kArray:
insertDictValue = new ORDictValueA((*(ORDictValueA*)dictIter->second));
break;
}
if (insertDictValue) {
LoadEntry(dictIter->first, insertDictValue);
} else {
ORLog(kError) << "DictValue type not found!" << std::endl;
}
}
}
ORDictionary::~ORDictionary()
{
DictMap::iterator i;
for (i = fDictMap.begin(); i != fDictMap.end(); i++) {
delete i->second;
}
}
ORVDictValue* ORDictionary::LookUp(std::string key, char delimiter)
{
DictMap::const_iterator dictIter;
size_t delimPos = key.find(delimiter);
if (delimPos == std::string::npos) {
dictIter = fDictMap.find(key);
if (dictIter==fDictMap.end()) {
ORLog(kDebug) << "ORDictionary::LookUp(): could not find key " << key
<< " in dictionary " << fName << std::endl;
return NULL;
}
return dictIter->second;
} else {
std::string nextDictName = key.substr(0, delimPos);
std::string nextKeyName = key.substr(delimPos+1);
const ORVDictValue* nextDict = LookUp(nextDictName);
if (nextDict == NULL) return NULL;
if (nextDict->GetValueType() != kDict) {
ORLog(kDebug) << "ORDictionary::LookUp(): key " << nextDictName
<< " in dictionary " << fName << " is not a dictionary (ValueType = "
<< nextDict->GetValueType() << ")." << std::endl;
return NULL;
}
return ((ORDictionary*) nextDict)->LookUp(nextKeyName);
}
}
const ORVDictValue* ORDictionary::LookUp(std::string key, char delimiter) const
{
DictMap::const_iterator dictIter;
size_t delimPos = key.find(delimiter);
if (delimPos == std::string::npos) {
dictIter = fDictMap.find(key);
if (dictIter==fDictMap.end()) {
ORLog(kDebug) << "ORDictionary::LookUp(): could not find key " << key
<< " in dictionary " << fName << std::endl;
return NULL;
}
return (const ORVDictValue*) dictIter->second;
} else {
std::string nextDictName = key.substr(0, delimPos);
std::string nextKeyName = key.substr(delimPos+1);
const ORVDictValue* nextDict = LookUp(nextDictName);
if (nextDict == NULL) return NULL;
if (nextDict->GetValueType() != kDict) {
ORLog(kDebug) << "ORDictionary::LookUp(): key " << nextDictName
<< " in dictionary " << fName << " is not a dictionary (ValueType = "
<< nextDict->GetValueType() << ")." << std::endl;
return NULL;
}
return ((const ORDictionary*) nextDict)->LookUp(nextKeyName);
}
}
std::string ORDictValueA::GetStringOfValue() const
{
std::string o("{");
if(GetNValues()) o+=At(0)->GetStringOfValue();
for(size_t i=1; i<GetNValues(); i++) o+=", " + At(i)->GetStringOfValue();
o+="}";
return o;
}
std::string ORDictValueI::GetStringOfValue() const
{
std::ostringstream o;
if (! (o << fI)) return "ERROR";
return o.str();
}
std::string ORDictValueR::GetStringOfValue() const
{
std::ostringstream o;
if (! (o << fR)) return "ERROR";
return o.str();
}
ORDictValueA::ORDictValueA(const ORDictValueA& dictA) : ORVDictValue(dictA)
{
SetName(dictA.fName);
/* Now the hard part, copying the dictionary map correctly calling
all the copy constructors. */
for (size_t i = 0; i<dictA.fDictVals.size();i++) {
EValType type = dictA.fDictVals[i]->GetValueType();
ORVDictValue* insertDictValue = NULL;
switch (type) {
case kDict:
insertDictValue = new ORDictionary((*(ORDictionary*)dictA.fDictVals[i]));
break;
case kString:
insertDictValue = new ORDictValueS((*(ORDictValueS*)dictA.fDictVals[i]));
break;
case kReal:
insertDictValue = new ORDictValueR((*(ORDictValueR*)dictA.fDictVals[i]));
break;
case kInt:
insertDictValue = new ORDictValueI((*(ORDictValueI*)dictA.fDictVals[i]));
break;
case kBool:
insertDictValue = new ORDictValueB((*(ORDictValueB*)dictA.fDictVals[i]));
break;
case kArray:
insertDictValue = new ORDictValueA((*(ORDictValueA*)dictA.fDictVals[i]));
break;
}
if (insertDictValue) {
LoadValue(insertDictValue);
} else {
ORLog(kError) << "DictValue type not found!" << std::endl;
}
}
}
ORDictValueA::~ORDictValueA()
{
for (unsigned i=0; i < fDictVals.size(); i++) delete fDictVals[i];
}