//////////////////////////////////////////////////////////////////////// // $Id: IDbiCfg.cxx,v 1.1 2011/01/18 05:49:19 finch Exp $ // // Some utility functions for working with configurations // // messier@indiana.edu //////////////////////////////////////////////////////////////////////// #include #include #include #include #include #include "IDbiRegistry.hxx" #include "IDbiCfg.hxx" #include "UtilString.hxx" //...................................................................... void COMET::IDbiCfg::TDbiRegistryToString(std::string& x, const IDbiRegistry& r) { //====================================================================== // Convert the IDbiRegistry r to a string dump //====================================================================== IDbiRegistry::IDbiRegistryKey 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; IDbiRegistry 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 isTDbiRegistry = 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 (COMET::UtilString::IsInt(cValue)) { int i = atoi(cValue); r.Set(cKey,i); } else if (COMET::UtilString::IsFloat(cValue)) { double d = atof(cValue); r.Set(cKey,d); } else if (COMET::UtilString::IsBool(cValue)) { bool b = COMET::UtilString::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; } ////////////////////////////////////////////////////////////////////////