#include "FairDbConf.h" #include "FairDbString.h" // for IsBool, IsFloat, IsInt, etc #include "FairRegistry.h" // for FairRegistry, etc #include "Riosfwd.h" // for ostream #include // IWYU pragma: keep for rint // IWYU pragma: no_include #include // for strlen, strcpy #include // for assert #include // for atof, atoi #include // for operator<<, basic_ostream, etc void FairDbConf::RegistryToString(std::string& x, const FairRegistry& r) { FairRegistry::FairRegistryKey rk = r.Key(); const char* s; std::ostringstream ss; while ( (s=rk()) ) { // Try to extract the value for this key char c = 0; const char* cs = 0; int i = 0; double d = 0; FairRegistry reg; bool isChar = r.Get(s,c); bool isCharStar = r.Get(s,cs); bool isInt = r.Get(s,i); bool isDouble = r.Get(s,d); bool isRegistry = r.Get(s,reg); ss << s << "="; if (isChar) { ss << c; } else if (isCharStar) { ss << "'"<scopy; --cKey) { *cKey = '\0'; } for (; *cKey!=' ' && *cKey!=',' && *cKey!='\0' && cKey>scopy; --cKey) { ; } for (; *cKey==' ' || *cKey=='\0'; ++cKey) { ; } // Step forward to get the start of the value for (cValue=cEqual+1; *cValue==' '&&*cValue!='\0'; ++cValue) { *cValue = '\0'; } while (*cValue==' ') { ++cValue; } // Handle special case of long strings in single or double quotes bool isString = false; if (*cValue=='\'' || *cValue=='\"') { isString = true; char stringDelim = *cValue; ++cValue; for (cEnd = cValue; *cEnd!='\0' && *cEnd!=stringDelim; ++cEnd) { ; } } else { for (cEnd = cValue; *cEnd!='\0'&& *cEnd!=' '&& *cEnd!=','; ++cEnd) { ; } } *cEnd = '\0'; // Convert value to correct data type if ( isString ) { r.Set(cKey,cValue); } else if (FairUtilString::IsInt(cValue)) { int val = atoi(cValue); r.Set(cKey,val); } else if (FairUtilString::IsFloat(cValue)) { double d = atof(cValue); r.Set(cKey,d); } else if (FairUtilString::IsBool(cValue)) { bool b = FairUtilString::atob(cValue); r.Set(cKey,b); } else { // Single character stored at char if (strlen(cValue)==1) { char c = *cValue; r.Set(cKey,c); } else { // Longer string stored as string r.Set(cKey,cValue); } } } cEqual = cEnd+1; } delete [] scopy; }