|
libFAUDES
Sections
Index
|
cfl_registry.cppGo to the documentation of this file.00001 /** @file cfl_registry.cpp Runtime interface, registry for faudes types and functions */ 00002 00003 /* FAU Discrete Event Systems Library (libfaudes) 00004 00005 Copyright (C) 2009 Ruediger Berndt 00006 Copyright (C) 2009 Thomas Moor 00007 00008 This library is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU Lesser General Public 00010 License as published by the Free Software Foundation; either 00011 version 2.1 of the License, or (at your option) any later version. 00012 00013 This library is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 Lesser General Public License for more details. 00017 00018 You should have received a copy of the GNU Lesser General Public 00019 License along with this library; if not, write to the Free Software 00020 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 00021 00022 00023 00024 #include "cfl_registry.h" 00025 #include "corefaudes.h" 00026 00027 // auto install types 00028 #ifndef FAUDES_MUTE_RTIAUTOLOAD 00029 #include "allplugins.h" 00030 #include "rtiautoload.h" 00031 #include "rtiautoload.cpp" 00032 #endif 00033 00034 00035 00036 namespace faudes{ 00037 00038 00039 00040 /* 00041 ******************************************************************** 00042 ******************************************************************** 00043 ******************************************************************** 00044 00045 Implemantation of faudes TypeRegistry 00046 00047 ******************************************************************** 00048 ******************************************************************** 00049 ******************************************************************** 00050 */ 00051 00052 // static members: ref to the only one instance 00053 TypeRegistry* TypeRegistry::mpInstance = 0; 00054 00055 // static member: access to singleton 00056 TypeRegistry* TypeRegistry::G(){ 00057 // lazy initialization 00058 if(!mpInstance){ 00059 FD_DREG("TypeRegistry(): Constrtuct singleton"); 00060 mpInstance = new TypeRegistry(); 00061 } 00062 return(mpInstance); 00063 } 00064 00065 // clear except autoregistered 00066 void TypeRegistry::Clear() { 00067 FD_DREG("TypeRegistry::Clear(): begin with #" << Size()); 00068 // prepare: delete all typedefs contained in map, except fpr autoregistered 00069 std::map<std::string, TypeDefinition*>::iterator mit; 00070 for(mit = mNameToTypeDef.begin(); mit != mNameToTypeDef.end(); mit++){ 00071 if(mit->second != NULL) 00072 if(!mit->second->AutoRegister()){ 00073 delete mit->second; 00074 mit->second = NULL; 00075 } 00076 if(mit->second != NULL) 00077 if(mit->second->AutoRegister()){ 00078 FD_DREG("TypeRegistry::Clear(): detect autoreg " << mit->second->Name()); 00079 } 00080 } 00081 // delete in NameToTypeDef 00082 std::map<std::string, TypeDefinition*>::iterator dit; 00083 for(mit = mNameToTypeDef.begin(); mit != mNameToTypeDef.end();){ 00084 dit=mit; mit++; 00085 if(dit->second == NULL) mNameToTypeDef.erase(dit); 00086 } 00087 // fix Id map (this only works if autoregisreded typeids have no doublet faudes names) 00088 mIdToTypeDef.clear(); 00089 for(mit = mNameToTypeDef.begin(); mit != mNameToTypeDef.end(); mit++){ 00090 TypeDefinition* ptdef=mit->second; 00091 FD_DREG("TypeRegistry::Clear(): keeping " << ptdef->Name()); 00092 if(ptdef->Prototype()) 00093 if(mIdToTypeDef.find(typeid(*(ptdef->Prototype())).name())== 00094 mIdToTypeDef.end()) 00095 mIdToTypeDef[typeid(*(ptdef->Prototype())).name()]=ptdef; 00096 } 00097 } 00098 00099 // clear all. 00100 void TypeRegistry::ClearAll(void) { 00101 FD_DREG("TypeRegistry::ClearAll()"); 00102 // delete all typedefs contained in map 00103 std::map<std::string, TypeDefinition*>::iterator mit; 00104 for(mit = mNameToTypeDef.begin(); mit != mNameToTypeDef.end(); mit++){ 00105 if(mit->second != NULL){ 00106 delete mit->second; 00107 mit->second = NULL; 00108 } 00109 } 00110 // delete maps 00111 mNameToTypeDef.clear(); 00112 mIdToTypeDef.clear(); 00113 } 00114 00115 // query number of entries 00116 int TypeRegistry::Size() const{ 00117 return(mNameToTypeDef.size()); 00118 } 00119 00120 // read access on type map 00121 TypeRegistry::Iterator TypeRegistry::Begin(void) const{ 00122 return(mNameToTypeDef.begin()); 00123 } 00124 00125 // read access on type map 00126 TypeRegistry::Iterator TypeRegistry::End(void) const{ 00127 return(mNameToTypeDef.end()); 00128 } 00129 00130 // insert new entry 00131 void TypeRegistry::Insert(TypeDefinition* pTypeDef){ 00132 #ifdef FAUDES_DEBUG_REGISTRY 00133 if(pTypeDef->Prototype()) { 00134 FD_DREG("TypeRegistry::Insert(): definition for " << pTypeDef->Name()); 00135 } else { 00136 //FD_DREG("TypeRegistry::Insert(): fake entry for " << pTypeDef->Name()); 00137 } 00138 #endif 00139 // test existence that match: ignore 00140 if(Exists(pTypeDef->Name())){ 00141 const TypeDefinition* otdef = Definitionp(pTypeDef->Name()); 00142 if(typeid(*(pTypeDef->Prototype())).name() == typeid(*(otdef->Prototype())).name()) { 00143 FD_DREG("TypeRegistry::Insert(): ignore doublet " << pTypeDef->Name()); 00144 return; 00145 } 00146 } 00147 // test existence that differ: error 00148 if(Exists(pTypeDef->Name())){ 00149 std::stringstream err; 00150 err << "Cannot overwrite existing entry with type " << pTypeDef->Name() << std::endl; 00151 throw Exception("TypeRegistry::Insert()", err.str(), 46); 00152 } 00153 // test for name 00154 if(pTypeDef->Name()=="") { 00155 std::stringstream err; 00156 err << "Cannot have empty name"<< std::endl; 00157 throw Exception("TypeRegistry::Insert()", err.str(), 46); 00158 }; 00159 // record in main map 00160 mNameToTypeDef[pTypeDef->Name()]=pTypeDef; 00161 // record in id map (first entry wins) 00162 if(pTypeDef->Prototype()) 00163 if(mIdToTypeDef.find(typeid(*(pTypeDef->Prototype())).name())== 00164 mIdToTypeDef.end()) 00165 mIdToTypeDef[typeid(*(pTypeDef->Prototype())).name()]=pTypeDef; 00166 } 00167 00168 00169 // scan token stream for type definitions 00170 void TypeRegistry::MergeDocumentation(TokenReader& rTr) { 00171 FD_DREG("TypeRegistry::MergeDocumentation(): using " << rTr.FileName()); 00172 // scan file 00173 Token token; 00174 while(rTr.Peek(token)) { 00175 // test for TypeDefinition with name 00176 if(!token.IsBegin()) { rTr.Get(token); continue; } 00177 if(token.StringValue()!="TypeDefinition") { rTr.Get(token); continue; } 00178 if(!token.ExistsAttributeString("name")) { rTr.Get(token); continue; } 00179 // found type def in file, extract ftype 00180 std::string ftype=token.AttributeStringValue("name"); 00181 size_t pos=ftype.find("::"); 00182 if(pos!=std::string::npos) ftype=ftype.substr(pos+2); 00183 // locate type def in map 00184 Iterator tit = mNameToTypeDef.find(ftype); 00185 // case 1: type exists: add documentaion 00186 if(tit!=mNameToTypeDef.end()) { 00187 tit->second->MergeDocumentation(rTr); 00188 continue; 00189 } 00190 // case 2: type does not exist: insert fake entry 00191 TypeDefinition* tdef = new TypeDefinition(ftype); 00192 tdef->MergeDocumentation(rTr); 00193 Insert(tdef); 00194 } 00195 } 00196 00197 // scan file for type definitions 00198 void TypeRegistry::MergeDocumentation(const std::string& rFileName) { 00199 TokenReader tr(rFileName); 00200 MergeDocumentation(tr); 00201 } 00202 00203 00204 // set XML element tag 00205 void TypeRegistry::XElementTag(const std::string& rTypeName, const std::string& rTag) { 00206 Iterator mit=mNameToTypeDef.find(rTypeName); 00207 if(mit == End()) return; 00208 mit->second->XElementTag(rTag); 00209 } 00210 00211 // get XML element tag 00212 const std::string& TypeRegistry::XElementTag(const std::string& rTypeName) const { 00213 Iterator mit=mNameToTypeDef.find(rTypeName); 00214 static std::string estr=""; 00215 if(mit == End()) return estr; 00216 return mit->second->XElementTag(); 00217 } 00218 00219 00220 // set auto-register flag 00221 void TypeRegistry::AutoRegister(const std::string& rTypeName, bool flag) { 00222 Iterator mit=mNameToTypeDef.find(rTypeName); 00223 if(mit == End()) { 00224 FD_DREG("TypeRegistry::AutoRegister(...): cannot access definition for faudes type " << rTypeName); 00225 return; 00226 } 00227 mit->second->AutoRegister(flag); 00228 } 00229 00230 // get auto-register flag 00231 bool TypeRegistry::AutoRegister(const std::string& rTypeName) const { 00232 Iterator mit=mNameToTypeDef.find(rTypeName); 00233 if(mit == End()) return false; 00234 return mit->second->AutoRegister(); 00235 } 00236 00237 00238 // construct faudes object by typename 00239 Type* TypeRegistry::NewObject(const std::string& rName) const{ 00240 FD_DRTI("TypeRegistry::NewObject(\"" << rName << "\")"); 00241 Iterator mit=mNameToTypeDef.find(rName); 00242 if(mit == End()) { 00243 std::stringstream err; 00244 err << "Unknown Type " << rName << std::endl; 00245 throw Exception("TypeRegistry::NewObject()", err.str(), 47); 00246 } 00247 Type* res=mit->second->NewObject(); 00248 if(!res) { 00249 std::stringstream err; 00250 err << "Failed to instatiate new " << rName << std::endl; 00251 throw Exception("TypeRegistry::NewObject()", err.str(), 47); 00252 } 00253 return res; 00254 } 00255 00256 // construct faudes object by typed reference 00257 Type* TypeRegistry::NewObject(const Type& rType) const{ 00258 FD_DRTI("TypeRegistry::NewObject(prototype): typeid " << typeid(rType).name()); 00259 Iterator mit; 00260 mit=mIdToTypeDef.find(typeid(rType).name()); 00261 if(mit == mIdToTypeDef.end()) { 00262 std::stringstream err; 00263 err << "Unknown type by reference" << std::endl; 00264 throw Exception("TypeRegistry::NewObject()", err.str(), 47); 00265 } 00266 return(rType.New()); 00267 } 00268 00269 // access type definition by type name 00270 const TypeDefinition& TypeRegistry::Definition(const std::string& rName) const{ 00271 FD_DRTI("TypeRegistry::Definition( " << rName << " )"); 00272 Iterator mit=mNameToTypeDef.find(rName); 00273 if(mit == End()) { 00274 std::stringstream err; 00275 err << "Type not found: \"" << rName << "\""; 00276 throw Exception("TypeRegistry::Definition()", err.str(), 46); 00277 } 00278 return(*(mit->second)); 00279 } 00280 00281 // access type definition by typed reference 00282 const TypeDefinition& TypeRegistry::Definition(const Type& rType) const{ 00283 FD_DRTI("TypeRegistry::Definition(): typeid " << typeid(rType).name()); 00284 Iterator mit; 00285 mit=mIdToTypeDef.find(typeid(rType).name()); 00286 if(mit!=mIdToTypeDef.end()) return *(mit->second); 00287 std::stringstream err; 00288 err << "Type not found: " << typeid(rType).name(); 00289 throw Exception("TypeRegistry::Definition()", err.str(), 46); 00290 } 00291 00292 // access type definition by type name 00293 const TypeDefinition* TypeRegistry::Definitionp(const std::string& rName) const{ 00294 FD_DRTI("TypeRegistry::Definitionp( " << rName << " )"); 00295 Iterator mit=mNameToTypeDef.find(rName); 00296 if(mit == End()) return NULL; 00297 return(mit->second); 00298 } 00299 00300 // access type definition by typed reference 00301 const TypeDefinition* TypeRegistry::Definitionp(const Type& rType) const{ 00302 FD_DRTI("TypeRegistry::Definitionp(): typeid " << typeid(rType).name()); 00303 Iterator mit; 00304 mit=mIdToTypeDef.find(typeid(rType).name()); 00305 if(mit==mIdToTypeDef.end()) return NULL; 00306 return(mit->second); 00307 } 00308 00309 // access prototype by type name 00310 const Type* TypeRegistry::Prototype(const std::string& rName) const{ 00311 FD_DRTI("TypeRegistry::Prototype( " << rName << " )"); 00312 Iterator mit=mNameToTypeDef.find(rName); 00313 if(mit == End()) return 0; 00314 return(mit->second->Prototype()); 00315 } 00316 00317 // access type definition by typed reference 00318 const std::string& TypeRegistry::TypeName(const Type& rType) const{ 00319 FD_DRTI("TypeRegistry::TypeName(): typeid " << typeid(rType).name()); 00320 Iterator mit; 00321 mit=mIdToTypeDef.find(typeid(rType).name()); 00322 if(mit!=mIdToTypeDef.end()) return mit->second->Name(); 00323 static std::string empty(""); 00324 return empty; 00325 } 00326 00327 // test existence by type name 00328 bool TypeRegistry::Exists(const std::string& rName) const{ 00329 return mNameToTypeDef.find(rName) != End(); 00330 } 00331 00332 // test existsnce by type name 00333 bool TypeRegistry::Exists(const Type& rType) const{ 00334 return mIdToTypeDef.find(typeid(rType).name()) != mIdToTypeDef.end(); 00335 } 00336 00337 00338 // token write (informative/debugging) 00339 void TypeRegistry::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const { 00340 FD_DRTI("TypeRegistry::DoWrite(): file " << rTw.FileName()); 00341 // ignore label and context 00342 (void) rLabel; 00343 (void) pContext; 00344 // doit 00345 Iterator tit; 00346 for(tit=Begin();tit!=End();tit++) { 00347 // write type definition 00348 rTw.WriteXmlComment("==================================================="); 00349 rTw.WriteXmlComment("==================================================="); 00350 rTw.WriteXmlComment("Faudes Type " + tit->second->Name()); 00351 rTw.WriteXmlComment("==================================================="); 00352 rTw.WriteXmlComment("==================================================="); 00353 rTw << "\n"; 00354 tit->second->Write(rTw); 00355 rTw << "\n" << "\n"; 00356 } 00357 } 00358 00359 00360 /* 00361 ******************************************************************** 00362 ******************************************************************** 00363 ******************************************************************** 00364 00365 Implemantation of faudes FunctionRegistry 00366 00367 ******************************************************************** 00368 ******************************************************************** 00369 ******************************************************************** 00370 */ 00371 00372 // static members: ref to the only one instnace 00373 FunctionRegistry* FunctionRegistry::mpInstance = 0; 00374 00375 // static member: access to signleton 00376 FunctionRegistry* FunctionRegistry::G(){ 00377 // lazy initialization 00378 if(!mpInstance){ 00379 FD_DREG("FunctionRegistry(): Construct singleton"); 00380 mpInstance = new FunctionRegistry(); 00381 } 00382 return(mpInstance); 00383 } 00384 00385 // clear all 00386 void FunctionRegistry::Clear(){ 00387 FD_DREG("FunctionRegistry::Clear()"); 00388 // delete all functiondefs contained in map 00389 std::map<std::string, FunctionDefinition*>::iterator mit; 00390 for(mit = mNameToFunctionDef.begin(); mit != mNameToFunctionDef.end(); mit++){ 00391 if(mit->second != NULL) { 00392 FD_DREG("FunctionRegistry::Clear: removing " << mit->second->Name()); 00393 delete mit->second; 00394 mit->second = NULL; 00395 } 00396 } 00397 // delete maps 00398 mNameToFunctionDef.clear(); 00399 mIdToFunctionDef.clear(); 00400 } 00401 00402 // query number of entries 00403 int FunctionRegistry::Size() const{ 00404 return(mNameToFunctionDef.size()); 00405 } 00406 00407 // read access on function map 00408 FunctionRegistry::Iterator FunctionRegistry::Begin(void) const{ 00409 return(mNameToFunctionDef.begin()); 00410 } 00411 00412 // read access on function map 00413 FunctionRegistry::Iterator FunctionRegistry::End(void) const{ 00414 return(mNameToFunctionDef.end()); 00415 } 00416 00417 // insert new entry 00418 void FunctionRegistry::Insert(FunctionDefinition* pFunctionDef){ 00419 #ifdef FAUDES_DEBUG_REGISTRY 00420 if(pFunctionDef->Prototype()) { 00421 FD_DREG("FunctionRegistry::Insert(): definition for " << pFunctionDef->Name()); 00422 } else { 00423 //FD_DREG("FunctionRegistry::Insert(): fake entry for " << pFunctionDef->Name()); 00424 } 00425 #endif 00426 // test existence 00427 if(Exists(pFunctionDef->Name())){ 00428 std::stringstream err; 00429 err << "Cannot overwrite existing entry with function " << pFunctionDef->Name() << std::endl; 00430 throw Exception("FunctionRegistry::Insert()", err.str(), 46); 00431 } 00432 // test for name 00433 if(pFunctionDef->Name()=="") { 00434 std::stringstream err; 00435 err << "Cannot have empty name"<< std::endl; 00436 throw Exception("FunctionRegistry::Insert()", err.str(), 46); 00437 }; 00438 // record in map 00439 mNameToFunctionDef[pFunctionDef->Name()]=pFunctionDef; 00440 // record in id map 00441 if(pFunctionDef->Prototype()) 00442 mIdToFunctionDef[typeid(*(pFunctionDef->Prototype())).name()]=pFunctionDef; 00443 } 00444 00445 00446 // scan token stream for function definitions 00447 void FunctionRegistry::MergeDocumentation(TokenReader& rTr) { 00448 FD_DREG("FunctionRegistry::MergeDocumentation(): using " << rTr.FileName()); 00449 // scan file 00450 Token token; 00451 while(rTr.Peek(token)) { 00452 // test for TypeDefinition with name 00453 if(!token.IsBegin()) { rTr.Get(token); continue; } 00454 if(token.StringValue()!="FunctionDefinition") { rTr.Get(token); continue; } 00455 if(!token.ExistsAttributeString("name")) { rTr.Get(token); continue; } 00456 // found type def in file, extract ftype 00457 std::string ffunction=token.AttributeStringValue("name"); 00458 size_t pos=ffunction.find("::"); 00459 if(pos!=std::string::npos) ffunction=ffunction.substr(pos+2); 00460 // locate type def in map 00461 Iterator fit = mNameToFunctionDef.find(ffunction); 00462 // case 1: type exists: add documentaion 00463 if(fit!=mNameToFunctionDef.end()) { 00464 fit->second->MergeDocumentation(rTr); 00465 continue; 00466 } 00467 // case 2: type does not exist: insert fake entry 00468 FunctionDefinition* fdef = new FunctionDefinition(ffunction); 00469 fdef->MergeDocumentation(rTr); 00470 Insert(fdef); 00471 } 00472 } 00473 00474 00475 // scan file for function definitions 00476 void FunctionRegistry::MergeDocumentation(const std::string& rFileName) { 00477 TokenReader tr(rFileName); 00478 MergeDocumentation(tr); 00479 } 00480 00481 00482 // construct faudes object by functionname 00483 Function* FunctionRegistry::NewFunction(const std::string& rName) const{ 00484 FD_DRTI("FunctionRegistry::NewFunction(\"" << rName << "\")"); 00485 Iterator mit=mNameToFunctionDef.find(rName); 00486 if(mit == End()) { 00487 std::stringstream err; 00488 err << "Unknown function " << rName << std::endl; 00489 throw Exception("FunctionRegistry::NewFunction()", err.str(), 47); 00490 } 00491 Function* res=mit->second->NewFunction(); 00492 if(!res) { 00493 std::stringstream err; 00494 err << "Failed to instatiate new " << rName << std::endl; 00495 throw Exception("FunctionRegistry::NewFunction()", err.str(), 47); 00496 } 00497 return res; 00498 } 00499 00500 // construct faudes object by function reference 00501 Function* FunctionRegistry::NewFunction(const Function& rFunction) const{ 00502 FD_DRTI("FunctionRegistry::NewFunction(prototype): typeid " << typeid(rFunction).name()); 00503 Iterator mit; 00504 mit=mIdToFunctionDef.find(typeid(rFunction).name()); 00505 if(mit == mIdToFunctionDef.end()) { 00506 std::stringstream err; 00507 err << "Unknown function by reference" << std::endl; 00508 throw Exception("FunctionRegistry::NewFunction()", err.str(), 47); 00509 } 00510 return(rFunction.New()); 00511 } 00512 00513 // access function definition by function name 00514 const FunctionDefinition& FunctionRegistry::Definition(const std::string& rName) const{ 00515 FD_DRTI("FunctionRegistry::Definition( " << rName << " )"); 00516 Iterator mit=mNameToFunctionDef.find(rName); 00517 if(mit == End()) { 00518 std::stringstream err; 00519 err << "Function not found: " << rName; 00520 throw Exception("FunctionRegistry::Definition()", err.str(), 46); 00521 } 00522 return(*(mit->second)); 00523 } 00524 00525 // access function definition by functiond reference 00526 const FunctionDefinition& FunctionRegistry::Definition(const Function& rFunction) const{ 00527 FD_DRTI("FunctionRegistry::Definition(): typeid " << typeid(rFunction).name()); 00528 Iterator mit; 00529 mit=mIdToFunctionDef.find(typeid(rFunction).name()); 00530 if(mit!=mIdToFunctionDef.end()) return *(mit->second); 00531 std::stringstream err; 00532 err << "Function not found: " << typeid(rFunction).name(); 00533 throw Exception("FunctionRegistry::Definition()", err.str(), 46); 00534 } 00535 00536 // access function definition by typed reference 00537 const std::string& FunctionRegistry::FunctionName(const Function& rFunction) const{ 00538 FD_DRTI("FunctionRegistry::FunctionName(): typeid " << typeid(rFunction).name()); 00539 Iterator mit; 00540 mit=mIdToFunctionDef.find(typeid(rFunction).name()); 00541 if(mit!=mIdToFunctionDef.end()) return mit->second->Name(); 00542 static const std::string empty(""); 00543 return empty; 00544 } 00545 00546 // test existence by function name 00547 bool FunctionRegistry::Exists(const std::string& rName) const{ 00548 return mNameToFunctionDef.find(rName) != End(); 00549 } 00550 00551 // test existsnce by function 00552 bool FunctionRegistry::Exists(const Function& rFunction) const{ 00553 return mIdToFunctionDef.find(typeid(rFunction).name()) != mIdToFunctionDef.end(); 00554 } 00555 00556 00557 // token write (informative/debugging) 00558 void FunctionRegistry::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const { 00559 FD_DREG("FunctionRegistry::DoWrite(): file " << rTw.FileName()); 00560 // ignore label and context 00561 (void) rLabel; 00562 (void) pContext; 00563 // doit 00564 Iterator tit; 00565 for(tit=Begin();tit!=End();tit++) { 00566 // write function definition 00567 rTw.WriteXmlComment("==================================================="); 00568 rTw.WriteXmlComment("==================================================="); 00569 rTw.WriteXmlComment("Faudes Function " + tit->second->Name()); 00570 rTw.WriteXmlComment("==================================================="); 00571 rTw.WriteXmlComment("==================================================="); 00572 rTw << "\n"; 00573 tit->second->Write(rTw); 00574 rTw << "\n" << "\n"; 00575 } 00576 } 00577 00578 00579 /* 00580 ******************************************************************** 00581 ******************************************************************** 00582 ******************************************************************** 00583 00584 Implemantation of LoadRegistry 00585 00586 ******************************************************************** 00587 ******************************************************************** 00588 ******************************************************************** 00589 */ 00590 00591 // load from file 00592 void LoadRegistry(const std::string& rPath) { 00593 FD_DRTI("LoadRegistry(" << rPath << ")"); 00594 // default path 00595 std::string rtipath = rPath; 00596 if(rtipath=="") rtipath="./libfaudes.rti"; // todo: plattform/configure 00597 // clear 00598 TypeRegistry::G()->Clear(); 00599 FunctionRegistry::G()->Clear(); 00600 00601 // auto install types extracted from rti file 00602 #ifndef FAUDES_MUTE_RTIAUTOLOAD 00603 LoadRegisteredTypes(); 00604 #endif 00605 00606 // allow build system load registry programmatic contributions defined in plugins 00607 #ifdef FAUDES_PLUGINS_RTILOAD 00608 FAUDES_PLUGINS_RTILOAD; 00609 #endif 00610 00611 // auto install functions extracted from rti file 00612 #ifndef FAUDES_MUTE_RTIAUTOLOAD 00613 LoadRegisteredFunctions(); 00614 #endif 00615 00616 // merge documentation 00617 TypeRegistry::G()->MergeDocumentation(rtipath); 00618 FunctionRegistry::G()->MergeDocumentation(rtipath); 00619 00620 // test and report status 00621 #ifdef FAUDES_CHECKED 00622 #ifndef FAUDES_MUTE_RTIAUTOLOAD 00623 TypeRegistry::Iterator tit; 00624 for(tit=TypeRegistry::G()->Begin(); tit!=TypeRegistry::G()->End(); tit++) { 00625 // should have prototype 00626 if(tit->second->Prototype()==NULL) 00627 FD_WARN("TypeRegistry: " << tit->second->Name() << " has no prototype"); 00628 } 00629 FunctionRegistry::Iterator fit; 00630 for(fit=FunctionRegistry::G()->Begin(); fit!=FunctionRegistry::G()->End(); fit++) { 00631 // should have prototype 00632 if(fit->second->Prototype()==NULL) 00633 FD_WARN("FunctionRegistry: " << fit->second->Name() << " has no prototype"); 00634 } 00635 #endif 00636 #endif 00637 00638 FD_DRTI("LoadRegistry(" << rPath << "): done"); 00639 } 00640 00641 00642 // save to file or std out 00643 void SaveRegistry(const std::string& rPath) { 00644 FD_DRTI("SaveRegistry(" << rPath << ")"); 00645 // have a tokenwriter 00646 TokenWriter* ptw; 00647 if(rPath=="") { 00648 ptw = new TokenWriter(TokenWriter::Stdout); 00649 } else { 00650 ptw = new TokenWriter(rPath,"Registry"); 00651 } 00652 // do the write 00653 ptw->WriteBegin("Registry"); 00654 TypeRegistry::G()->Write(*ptw); 00655 FunctionRegistry::G()->Write(*ptw); 00656 ptw->WriteEnd("Registry"); 00657 // dispose 00658 delete ptw; 00659 } 00660 00661 00662 // clear all 00663 void ClearRegistry(void) { 00664 FD_DRTI("ClearRegistry()"); 00665 // clear 00666 FunctionRegistry::G()->Clear(); 00667 TypeRegistry::G()->ClearAll(); 00668 } 00669 00670 // conveience access to singleton 00671 Type* NewFaudesObject(const std::string& rTypeName) { return TypeRegistry::G()->NewObject(rTypeName);} 00672 Function* NewFaudesFunction(const std::string& rFunctName) { return FunctionRegistry::G()->NewFunction(rFunctName);} 00673 const std::string& FaudesTypeName(const Type& rObject) { return TypeRegistry::G()->TypeName(rObject);} 00674 const std::string& FaudesFunctionName(const Function& rObject) { return FunctionRegistry::G()->FunctionName(rObject);} 00675 00676 00677 } // namespace |
libFAUDES 2.18b --- 2010-12-17 --- c++ source docu by doxygen 1.6.3