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