30 fValuesLocked(readonly),
42 fValuesLocked(rhs.fValuesLocked),
43 fKeysLocked(rhs.fKeysLocked),
51 while ( (s = rk()) ) {
fMap[
s] = rhs.
fMap.find(s)->second->Dup(); }
56 this->SetName(rhs.GetName());
61 if (
this == &rhs) {
return *
this; }
72 while ( (s = rk()) ) {
fMap[
s] = rhs.
fMap.find(s)->second->Dup(); }
77 this->SetName(rhs.GetName());
85 if (
this == &rhs) {
return; }
89 while ( (s = rk()) ) {
90 tRegMap::iterator mit =
fMap.find(s);
95 cout <<
"Merge: can't, add new key " << s <<
", keys locked."
96 <<
" merger=" << this->GetName()
97 <<
", mergie=" << rhs.GetName() << endl;
102 cout<<
"Merge: can't, merge key " << s <<
", values locked."
103 <<
" merger=" << this->GetName()
104 <<
", mergie=" << rhs.GetName() << endl;
107 if (exists) {
delete mit->second; }
108 fMap[
s] = rhs.
fMap.find(s)->second->Dup();
115 return fMap.find(key) !=
fMap.end();
120 tRegMap::iterator dead =
fMap.find(key);
121 if (dead ==
fMap.end()) {
return; }
131 cout <<
"Clear: can't, there are locks in \""
132 << this->GetName() <<
"\"\n";
136 tRegMap::iterator mit =
fMap.begin();
137 while (mit !=
fMap.end()) {
147 this->TNamed::Dump();
148 tRegMap::const_iterator mit =
fMap.begin();
150 cout<<
"FairRegistry: `" << this->GetName() <<
"', "
151 << this->
Size() <<
" entries."
152 <<
" (Locks: [Keys|Values] `key', `value'):\n";
153 while (mit !=
fMap.end()) {
157 <<
"`" << mit->first <<
"', `";
167 static int print_depth = 0;
170 tRegMap::const_iterator mit = this->
fMap.begin();
171 for(
int i=0; i<print_depth; ++i) { os <<
" "; }
172 os <<
"\"" << this->GetName() <<
"\", "
173 << this->
Size() <<
" entries."
174 <<
" keys " << (this->
fKeysLocked ?
"locked" :
"unlocked")
175 <<
", values " << (this->
fValuesLocked ?
"locked" :
"unlocked")
179 while (mit != this->
fMap.end()) {
180 for(
int i=0; i<print_depth; ++i) { os <<
" "; }
182 os << mit->first <<
" = ";
183 mit->second->PrintStream(os);
199 tRegMap::iterator mit =
fMap.begin();
200 while (mit !=
fMap.end()) {
227 if (fIt == fReg->fMap.end()) {
return 0; }
228 const char*
s = fIt->first.c_str();
238 #define REGISTRY_SET(TYPE) \
239 bool FairRegistry::Set(const char* key, TYPE val) \
241 tRegMap::iterator mit = fMap.find(key); \
242 if (mit != fMap.end()) { \
243 if (fValuesLocked) { \
245 << "Set: Values are locked - not overwriting \"" \
246 << key << "\" with \"" << val << "\" in registry \"" << this->GetName() << "\"\n";\
249 if (!dynamic_cast<FairRegistryItemXxx<TYPE>*>(mit->second)) { \
251 << "Set: attempt to overwrite old value for key \"" \
252 << key << "\" with different type value " \
253 << val << " in registry \"" << this->GetName() << "\"\n";\
256 delete mit->second; \
262 << "Set: Keys are locked - not adding `" \
263 << key << "' to registry \"" << this->GetName() << "\"\n";\
267 FairRegistryItem* ri = new FairRegistryItemXxx< TYPE >(new TYPE (val)); \
282 tRegMap::iterator mit =
fMap.find(key);
283 if (mit !=
fMap.end()) {
286 cout <<
"Set: Values are locked - not overwriting `"
287 << key <<
"\" with \"" << val <<
"\" in registry \"" << this->GetName() <<
"\"\n";
292 cout <<
"Set: attempt to overwrite old value for key \""
293 << key <<
"\" with different type value "
294 << val <<
" in registry \"" << this->GetName() <<
"\"\n";
302 cout <<
"FairRegistry::Set: Keys are locked - not adding `"
303 << key <<
"' in registry \"" << this->GetName() <<
"\"\n";
308 char** cpp =
new char*;
309 (*cpp) =
new char [strlen(val)+1];
311 const char** ccpp =
const_cast<const char**
>(cpp);
319 #define REGISTRY_GET(TYPE) \
320 bool FairRegistry::Get(const char* key, TYPE & val) const \
322 tRegMap::const_iterator mit = fMap.find(key); \
323 if (mit == fMap.end()) return false; \
324 FairRegistryItemXxx<TYPE>* rix = \
325 dynamic_cast<FairRegistryItemXxx<TYPE>*>(mit->second); \
327 cout << "Key " << key \
328 << " does not have type " \
329 << #TYPE << " as required" \
333 val = *(rix->Get()); \
343 tRegMap::const_iterator mit =
fMap.find(key);
344 if (mit ==
fMap.end()) {
return false; }
349 val = *(rixd->
Get());
356 val = *(rixi->
Get());
359 cout <<
"Key " << key
360 <<
" does not have type double or int"
361 <<
" as required" << endl;
365 #define REGISTRY_GET_TYPE(NAME, RETTYPE, TYPE) \
366 RETTYPE FairRegistry::Get##NAME(const char* key) const \
369 if (Get(key,retval)) return retval; \
370 if (fErrorHandler) { fErrorHandler(); return 0; } \
373 << "\nFairRegistry::GetTYPE: failed to get value for key \"" \
374 << key << "\" from FairRegistry \"" << this->GetName() \
375 << "\". Aborting\n\n"; \
376 bool must_get_a_value = false; \
377 assert(must_get_a_value); \
386 #undef REGISTRY_GET_TYPE
390 if (
Get(key,retval)) {
return retval; }
394 cout<<
"\nFairRegistry::GetTYPE: failed to get value for key \""
395 << key <<
"\" from FairRegistry \"" << this->GetName()
396 <<
"\". Aborting\n\n";
397 bool must_get_a_value =
false;
398 assert(must_get_a_value);
405 tRegMap::const_iterator mit =
fMap.find(key);
406 if (mit ==
fMap.end()) {
return typeid(
void); }
407 return mit->second->GetType();
411 tRegMap::const_iterator mit =
fMap.find(key);
412 if (mit ==
fMap.end()) {
return "void"; }
413 return mit->second->GetTypeAsString();
419 tRegMap::const_iterator mit =
fMap.find(key);
420 if (mit ==
fMap.end()) {
return ""; }
421 mit->second->PrintStream(os);
425 void FairRegistry::Streamer(TBuffer& b)
430 Version_t
v = b.ReadVersion();
436 for (
int i = 0; i < nobjects; ++i) {
446 tRegMap::iterator mit =
fMap.find(key);
447 if (mit !=
fMap.end()) {
456 b.WriteVersion(FairRegistry::IsA());
459 nobjects =
fMap.size();
463 cout <<
"Streamer, Writing "<< nobjects <<
" objects\n";
465 tRegMap::iterator mit =
fMap.begin();
466 while (mit !=
fMap.end()) {
467 b << mit->first.c_str();
470 cout << mit->first.c_str() << endl;
482 os <<
"['" << this->GetName() <<
"'";
484 tRegMap::const_iterator mit, done =
fMap.end();
485 for (mit =
fMap.begin(); mit != done; ++mit) {
486 os <<
" '" << mit->first <<
"'=(";
487 os << mit->second->GetTypeAsString();
489 mit->second->PrintStream(os);
497 static std::istream&
bail(std::istream& is)
500 cout <<
"FairRegistry::Read(istream&) stream corrupted\n";
509 if (!is.get(c)) {
return bail(is); }
515 reg.SetName(name.c_str());
518 if (isspace(c)) {
continue; }
527 if (key ==
"") {
return bail(is); }
530 if (!is.get(c)) {
return bail(is); }
533 if (!is.get(c) || c !=
'(') {
541 if (c ==
')') {
break; }
547 if (type ==
"char") {
549 }
else if (type ==
"int") {
551 }
else if (type ==
"double") {
553 }
else if (type ==
"string") {
555 }
else if (type ==
"FairRegistry") {
557 }
else {
return bail(is); }