00001
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00017
00018 #include <iostream>
00019 #include <sstream>
00020 using std::ostringstream;
00021
00022 #include <string>
00023 using std::string;
00024 #include <vector>
00025 using std::vector;
00026
00027 #include "DatabaseInterface/DbiSimFlagAssociation.h"
00028 #include "LeakChecker/Lea.h"
00029 #include "MessageService/MsgService.h"
00030 #include "Registry/Registry.h"
00031 #include "Util/UtilString.h"
00032
00033 ClassImp(DbiSimFlagAssociation)
00034
00035
00036
00037
00038
00039 CVSID("$Id: DbiSimFlagAssociation.cxx,v 1.1 2003/08/08 16:34:18 west Exp $");
00040
00041 const DbiSimFlagAssociation* DbiSimFlagAssociation::fgInstance = 0;
00042
00043
00044
00045
00046 ostream& operator<<(ostream& s, const DbiSimFlagAssociation& simFlagAss) {
00047 simFlagAss.Print(s);
00048 return s;
00049 }
00050
00051
00052
00053
00054
00055
00056 DbiSimFlagAssociation::DbiSimFlagAssociation() {
00057
00058
00059
00060
00061
00062
00063
00064 LEA_CTOR
00065
00066 MSG("Dbi", Msg::kVerbose) << "Creating DbiSimFlagAssociation" << endl;
00067
00068
00069 fgInstance = this;
00070
00071 }
00072
00073
00074
00075
00076 DbiSimFlagAssociation::~DbiSimFlagAssociation() {
00077
00078
00079
00080
00081
00082
00083
00084 LEA_DTOR
00085
00086 MSG("Dbi", Msg::kVerbose) << "Destroying DbiSimFlagAssociation" << endl;
00087
00088
00089 if ( fgInstance == this ) fgInstance = 0;
00090
00091 }
00092
00093
00094 DbiSimFlagAssociation::SimList_t
00095 DbiSimFlagAssociation::Get(const SimFlag::SimFlag_t value)const {
00096
00097
00098
00099
00100
00101
00102 SimMap_t::const_iterator itr = fAssociations.find(value);
00103 if ( itr != fAssociations.end() ) return itr->second;
00104 SimList_t l;
00105 l.push_back(value);
00106 return l;
00107
00108 }
00109
00110
00111
00112 const DbiSimFlagAssociation& DbiSimFlagAssociation::Instance() {
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 if ( ! fgInstance ) new DbiSimFlagAssociation;
00128
00129 return *fgInstance;
00130
00131 }
00132
00133
00134 void DbiSimFlagAssociation::Print(ostream& s)const {
00135
00136
00137
00138
00139 s << "\n\nSimFlag Association Status: ";
00140 if ( fAssociations.size() == 0 ) s <<"Not enabled" << endl;
00141 else {
00142 s << endl;
00143
00144 SimMap_t::const_iterator mapItr = fAssociations.begin();
00145 SimMap_t::const_iterator mapItrEnd = fAssociations.end();
00146 while ( mapItr != mapItrEnd ) {
00147
00148 SimFlag::SimFlag_t value = mapItr->first;
00149 string name = SimFlag::AsString(value);
00150 ostringstream buff;
00151 buff << name << "(" << value << ")";
00152 name = buff.str();
00153 if ( name.size() < 20 ) name.append(20-name.size(),' ');
00154 s << name << "maps to: ";
00155
00156 SimList_t l = mapItr->second;
00157 SimList_t::const_iterator listItr = l.begin();
00158 SimList_t::const_iterator listItrEnd = l.end();
00159 while ( listItr != listItrEnd ) {
00160 SimFlag::SimFlag_t v = *listItr;
00161 string n = SimFlag::AsString(v);
00162 s << n << "(" << v << ")";
00163 ++listItr;
00164 if ( listItr != listItrEnd ) s << ", ";
00165 }
00166 s << endl;
00167 ++mapItr;
00168 }
00169
00170 }
00171 }
00172
00173
00174
00175 void DbiSimFlagAssociation::Set(Registry& reg) {
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191 Registry::RegistryKey keyItr(®);
00192
00193 Bool_t hasChanged = kFALSE;
00194
00195 const char* key = keyItr();
00196 while ( key ) {
00197
00198 const char* nextKey = keyItr();
00199 if ( ! strncmp("SimFlagAssociation:",key,19) ) {
00200
00201
00202 string Name = key+19;
00203 SimFlag::SimFlag_t value = SimFlag::StringToEnum(Name.c_str());
00204 const char* listChars = 0;
00205 bool ok = reg.Get(key,listChars) && (value != SimFlag::kUnknown);
00206
00207 SimList_t lv;
00208 if ( ok ) {
00209 vector<string> ls;
00210 UtilString::StringTok(ls,listChars,",");
00211 vector<string>::iterator itr = ls.begin();
00212 vector<string>::iterator itrEnd = ls.end();
00213 for (; itr != itrEnd; ++itr ) {
00214 SimFlag::SimFlag_t v = SimFlag::StringToEnum(itr->c_str());
00215 if ( v == SimFlag::kUnknown) ok = false;
00216 lv.push_back(v);
00217 }
00218 }
00219
00220 if ( ok ) {
00221 this->Set(value,lv);
00222 hasChanged = true;
00223 }
00224 else MSG("Dbi",Msg::kWarning)
00225 << "Illegal SimFlagAssociation registry item: " << key
00226 << " = " << listChars << endl;
00227
00228 reg.RemoveKey(key);
00229 }
00230 key = nextKey;
00231 }
00232
00233 if ( hasChanged ) this->Show();
00234 }
00235
00236
00237
00238 void DbiSimFlagAssociation::Show() {
00239
00240
00241
00242
00243 MSG("Dbi",Msg::kInfo) << *this << endl;
00244
00245
00246 }
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278