About
User Reference
C++ API
luafaudes
Developer
Links
libFAUDES online
libFAUDES

Sections

Index

cfl_registry.cpp

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

libFAUDES 2.22k --- 2013.04.02 --- c++ source docu by doxygen