cfl_registry.cpp
Go to the documentation of this file.
1 /** @file cfl_registry.cpp Runtime interface, registry for faudes types and functions */
2 
3 /* FAU Discrete Event Systems Library (libfaudes)
4 
5 Copyright (C) 2009 Ruediger Berndt
6 Copyright (C) 2009 Thomas Moor
7 
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12 
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
21 
22 
23 
24 #include "cfl_registry.h"
25 #include "corefaudes.h"
26 
27 // auto install types
28 #ifndef FAUDES_MUTE_RTIAUTOLOAD
29 #include <map>
30 #include <stack>
31 #include <set>
32 #include <vector>
33 #include <utility>
34 #include <limits>
35 #include "allplugins.h"
36 #include "rtiautoload.h"
37 #include "rtiautoload.cpp"
38 #endif
39 
40 
41 
42 namespace faudes{
43 
44 
45 
46 /*
47 ********************************************************************
48 ********************************************************************
49 ********************************************************************
50 
51 Implemantation of faudes TypeRegistry
52 
53 ********************************************************************
54 ********************************************************************
55 ********************************************************************
56 */
57 
58 // static members: ref to the only one instance
59 TypeRegistry* TypeRegistry::mpInstance = 0;
60 
61 // static member: access to singleton
63  // lazy initialization
64  if(!mpInstance){
65  FD_DREG("TypeRegistry(): Constrtuct singleton");
66  mpInstance = new TypeRegistry();
67  }
68  return(mpInstance);
69 }
70 
71 // clear except C++-autoregistered
73  FD_DREG("TypeRegistry::Clear(): begin with #" << Size());
74  // prepare: delete all typedefs contained in map, except fpr autoregistered
75  std::map<std::string, TypeDefinition*>::iterator mit;
76  for(mit = mNameToTypeDef.begin(); mit != mNameToTypeDef.end(); mit++){
77  if(mit->second != NULL)
78  if(!mit->second->AutoRegistered()){
79  delete mit->second;
80  mit->second = NULL;
81  }
82  if(mit->second != NULL)
83  if(mit->second->AutoRegistered()){
84  FD_DREG("TypeRegistry::Clear(): detect autoreg " << mit->second->Name());
85  }
86  }
87  // delete in NameToTypeDef
88  std::map<std::string, TypeDefinition*>::iterator dit;
89  for(mit = mNameToTypeDef.begin(); mit != mNameToTypeDef.end();){
90  dit=mit; mit++;
91  if(dit->second == NULL) mNameToTypeDef.erase(dit);
92  }
93  // fix Id map (this only works if autoregisreded typeids have no doublet faudes names)
94  mIdToTypeDef.clear();
95  for(mit = mNameToTypeDef.begin(); mit != mNameToTypeDef.end(); mit++){
96  TypeDefinition* ptdef=mit->second;
97  const Type* pt=ptdef->Prototype();
98  FD_DREG("TypeRegistry::Clear(): keeping " << ptdef->Name());
99  if(pt)
100  if(mIdToTypeDef.find(typeid(*pt).name())==mIdToTypeDef.end())
101  mIdToTypeDef[typeid(*pt).name()]=ptdef;
102  }
103 }
104 
105 // clear all.
107  FD_DREG("TypeRegistry::ClearAll()");
108  // delete all typedefs contained in map
109  std::map<std::string, TypeDefinition*>::iterator mit;
110  for(mit = mNameToTypeDef.begin(); mit != mNameToTypeDef.end(); mit++){
111  if(mit->second != NULL){
112  delete mit->second;
113  mit->second = NULL;
114  }
115  }
116  // delete maps
117  mNameToTypeDef.clear();
118  mIdToTypeDef.clear();
119 }
120 
121 // query number of entries
122 int TypeRegistry::Size() const{
123  return(mNameToTypeDef.size());
124 }
125 
126 // read access on type map
128  return(mNameToTypeDef.begin());
129 }
130 
131 // read access on type map
133  return(mNameToTypeDef.end());
134 }
135 
136 // insert new entry
138 #ifdef FAUDES_DEBUG_REGISTRY
139  if(pTypeDef->Prototype()) {
140  FD_DREG("TypeRegistry::Insert(): definition for " << pTypeDef->Name());
141  } else {
142  FD_DREG("TypeRegistry::Insert(): dummy prototype for " << pTypeDef->Name());
143  }
144 #endif
145  // test existence that match: ignore
146  const Type* pt=pTypeDef->Prototype();
147  if(Exists(pTypeDef->Name())){
148  const TypeDefinition* otdef = Definitionp(pTypeDef->Name());
149  const Type* opt=otdef->Prototype();
150  if((pt!=0) && (opt!=0))
151  if(typeid(*pt).name() == typeid(*opt).name()) {
152  FD_DREG("TypeRegistry::Insert(): ignoring doublet " << pTypeDef->Name());
153  return;
154  }
155  }
156  // test existence that differ: error
157  if(Exists(pTypeDef->Name())){
158  std::stringstream err;
159  err << "Cannot overwrite existing entry with type " << pTypeDef->Name() << std::endl;
160  throw Exception("TypeRegistry::Insert()", err.str(), 46);
161  }
162  // test for name
163  if(pTypeDef->Name()=="") {
164  std::stringstream err;
165  err << "Cannot have empty name"<< std::endl;
166  throw Exception("TypeRegistry::Insert()", err.str(), 46);
167  };
168  // record in main map
169  mNameToTypeDef[pTypeDef->Name()]=pTypeDef;
170  // record in id map (first entry wins)
171  if(pt)
172  if(mIdToTypeDef.find(typeid(*pt).name())==mIdToTypeDef.end())
173  mIdToTypeDef[typeid(*pt).name()]=pTypeDef;
174 }
175 
176 
177 // scan token stream for type definitions
179  FD_DV("TypeRegistry::MergeDocumentation(): using " << rTr.FileName());
180  // scan file
181  Token token;
182  while(rTr.Peek(token)) {
183  // test for TypeDefinition with name
184  if(!token.IsBegin("TypeDefinition")) { rTr.Get(token); continue; }
185  if(!token.ExistsAttributeString("name")) { rTr.Get(token); continue; }
186  // found type def in file, extract ftype
187  std::string ftype=token.AttributeStringValue("name");
188  size_t pos=ftype.find("::");
189  if(pos!=std::string::npos) ftype=ftype.substr(pos+2);
190  FD_DRTI("TypeRegistry::MergeDocumentation(): " << ftype);
191  // locate type def in map
192  Iterator tit = mNameToTypeDef.find(ftype);
193  // case 1: type exists (from LoadRegistry or c++-Autoregister): add documentaion
194  if(tit!=mNameToTypeDef.end()) {
195  tit->second->MergeDocumentation(rTr);
196  continue;
197  }
198  // case 2: type does not exist (e.g. with ref2html): insert fake entry
199  TypeDefinition* tdef = new TypeDefinition(ftype);
200  tdef->MergeDocumentation(rTr);
201  Insert(tdef);
202  }
203 }
204 
205 // scan file for type definitions
206 void TypeRegistry::MergeDocumentation(const std::string& rFileName) {
207  TokenReader tr(rFileName);
208  MergeDocumentation(tr);
209 }
210 
211 
212 // set XML element tag
213 void TypeRegistry::XElementTag(const std::string& rTypeName, const std::string& rTag) {
214  Iterator mit=mNameToTypeDef.find(rTypeName);
215  if(mit == End()) return;
216  mit->second->XElementTag(rTag);
217 }
218 
219 // get XML element tag
220 const std::string& TypeRegistry::XElementTag(const std::string& rTypeName) const {
221  Iterator mit=mNameToTypeDef.find(rTypeName);
222  static std::string estr="";
223  if(mit == End()) return estr;
224  return mit->second->XElementTag();
225 }
226 
227 
228 // set auto-register flag
229 void TypeRegistry::AutoRegistered(const std::string& rTypeName, bool flag) {
230  Iterator mit=mNameToTypeDef.find(rTypeName);
231  if(mit == End()) {
232  FD_DREG("TypeRegistry::AutoRegistered(...): cannot access definition for faudes type " << rTypeName);
233  return;
234  }
235  mit->second->AutoRegistered(flag);
236 }
237 
238 // get auto-register flag
239 bool TypeRegistry::AutoRegistered(const std::string& rTypeName) const {
240  Iterator mit=mNameToTypeDef.find(rTypeName);
241  if(mit == End()) return false;
242  return mit->second->AutoRegistered();
243 }
244 
245 
246 // construct faudes object by typename
247 Type* TypeRegistry::NewObject(const std::string& rName) const{
248  FD_DRTI("TypeRegistry::NewObject(\"" << rName << "\")");
249  Iterator mit=mNameToTypeDef.find(rName);
250  if(mit == End()) {
251  std::stringstream err;
252  err << "Unknown Type " << rName << std::endl;
253  throw Exception("TypeRegistry::NewObject()", err.str(), 47);
254  }
255  Type* res=mit->second->NewObject();
256  if(!res) {
257  std::stringstream err;
258  err << "Failed to instatiate new " << rName << std::endl;
259  throw Exception("TypeRegistry::NewObject()", err.str(), 47);
260  }
261  return res;
262 }
263 
264 // construct faudes object by typed reference
265 Type* TypeRegistry::NewObject(const Type& rType) const{
266  FD_DRTI("TypeRegistry::NewObject(prototype): typeid " << typeid(rType).name());
267  Iterator mit;
268  mit=mIdToTypeDef.find(typeid(rType).name());
269  if(mit == mIdToTypeDef.end()) {
270  std::stringstream err;
271  err << "Unknown type by reference" << std::endl;
272  throw Exception("TypeRegistry::NewObject()", err.str(), 47);
273  }
274  return(rType.New());
275 }
276 
277 // access type definition by type name
278 const TypeDefinition& TypeRegistry::Definition(const std::string& rName) const{
279  FD_DRTI("TypeRegistry::Definition( " << rName << " )");
280  Iterator mit=mNameToTypeDef.find(rName);
281  if(mit == End()) {
282  std::stringstream err;
283  err << "Type not found: \"" << rName << "\"";
284  throw Exception("TypeRegistry::Definition()", err.str(), 46);
285  }
286  return(*(mit->second));
287 }
288 
289 // access type definition by typed reference
290 const TypeDefinition& TypeRegistry::Definition(const Type& rType) const{
291  FD_DRTI("TypeRegistry::Definition(): typeid " << typeid(rType).name());
292  Iterator mit;
293  mit=mIdToTypeDef.find(typeid(rType).name());
294  if(mit!=mIdToTypeDef.end()) return *(mit->second);
295  std::stringstream err;
296  err << "Type not found: " << typeid(rType).name();
297  throw Exception("TypeRegistry::Definition()", err.str(), 46);
298 }
299 
300 // access type definition by type name
301 const TypeDefinition* TypeRegistry::Definitionp(const std::string& rName) const{
302  FD_DRTI("TypeRegistry::Definitionp( " << rName << " )");
303  Iterator mit=mNameToTypeDef.find(rName);
304  if(mit == End()) return NULL;
305  return(mit->second);
306 }
307 
308 // access type definition by typed reference
309 const TypeDefinition* TypeRegistry::Definitionp(const Type& rType) const{
310  FD_DRTI("TypeRegistry::Definitionp(): typeid " << typeid(rType).name());
311  Iterator mit;
312  mit=mIdToTypeDef.find(typeid(rType).name());
313  if(mit==mIdToTypeDef.end()) return NULL;
314  return(mit->second);
315 }
316 
317 // access prototype by type name
318 const Type* TypeRegistry::Prototype(const std::string& rName) const{
319  FD_DRTI("TypeRegistry::Prototype( " << rName << " )");
320  Iterator mit=mNameToTypeDef.find(rName);
321  if(mit == End()) return 0;
322  return(mit->second->Prototype());
323 }
324 
325 // access type definition by typed reference
326 const std::string& TypeRegistry::TypeName(const Type& rType) const{
327  FD_DRTI("TypeRegistry::TypeName(): typeid " << typeid(rType).name());
328  Iterator mit;
329  mit=mIdToTypeDef.find(typeid(rType).name());
330  if(mit!=mIdToTypeDef.end()) return mit->second->Name();
331  static std::string empty("");
332  return empty;
333 }
334 
335 // test type compatibility
336 bool TypeRegistry::TypeTest(const std::string& rTypeName, const Type& rObject) const {
337  FD_DRTI("TypeRegistry::TypeTest(): typeid " << typeid(rObject).name());
338  Iterator mit=mNameToTypeDef.find(rTypeName);
339  if(mit == End()) return false;
340  if(!mit->second->Prototype()) return false;
341  FD_DRTI("TypeRegistry::TypeTest(): dst ftype " << rTypeName<< " src typeid " << typeid(rObject).name()
342  << " res " << (mit->second->Prototype()->Cast(&rObject) != 0));
343  return ( mit->second->Prototype()->Cast(&rObject) != 0 );
344 }
345 
346 // test existence by type name
347 bool TypeRegistry::Exists(const std::string& rName) const{
348  return mNameToTypeDef.find(rName) != End();
349 }
350 
351 // test existsnce by type name
352 bool TypeRegistry::Exists(const Type& rType) const{
353  return mIdToTypeDef.find(typeid(rType).name()) != mIdToTypeDef.end();
354 }
355 
356 
357 // token write (informative/debugging)
358 void TypeRegistry::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
359  FD_DRTI("TypeRegistry::DoWrite(): file " << rTw.FileName());
360  // ignore label and context
361  (void) rLabel;
362  (void) pContext;
363  // doit
364  Iterator tit;
365  for(tit=Begin();tit!=End();tit++) {
366  // write type definition
367  rTw.WriteXmlComment("===================================================");
368  rTw.WriteXmlComment("===================================================");
369  rTw.WriteXmlComment("Faudes Type " + tit->second->Name());
370  rTw.WriteXmlComment("===================================================");
371  rTw.WriteXmlComment("===================================================");
372  rTw.Endl();
373  tit->second->Write(rTw);
374  rTw.Endl();
375  rTw.Endl();
376  }
377 }
378 
379 
380 /*
381 ********************************************************************
382 ********************************************************************
383 ********************************************************************
384 
385 Implemantation of faudes FunctionRegistry
386 
387 ********************************************************************
388 ********************************************************************
389 ********************************************************************
390 */
391 
392 // static members: ref to the only one instnace
394 
395 // static member: access to signleton
397  // lazy initialization
398  if(!mpInstance){
399  FD_DREG("FunctionRegistry(): Construct singleton");
401  }
402  return(mpInstance);
403 }
404 
405 // clear all
407  FD_DREG("FunctionRegistry::Clear()");
408  // delete all functiondefs contained in map
409  std::map<std::string, FunctionDefinition*>::iterator mit;
410  for(mit = mNameToFunctionDef.begin(); mit != mNameToFunctionDef.end(); mit++){
411  if(mit->second != NULL) {
412  FD_DREG("FunctionRegistry::Clear: removing " << mit->second->Name());
413  delete mit->second;
414  mit->second = NULL;
415  }
416  }
417  // delete maps
418  mNameToFunctionDef.clear();
419  mIdToFunctionDef.clear();
420 }
421 
422 // query number of entries
424  return(mNameToFunctionDef.size());
425 }
426 
427 // read access on function map
429  return(mNameToFunctionDef.begin());
430 }
431 
432 // read access on function map
434  return(mNameToFunctionDef.end());
435 }
436 
437 // insert new entry
439 #ifdef FAUDES_DEBUG_REGISTRY
440  if(pFunctionDef->Prototype()) {
441  FD_DREG("FunctionRegistry::Insert(): definition for " << pFunctionDef->Name());
442  } else {
443  FD_DREG("FunctionRegistry::Insert(): fake entry for " << pFunctionDef->Name());
444  }
445 #endif
446  // test existence
447  if(Exists(pFunctionDef->Name())){
448  std::stringstream err;
449  err << "Cannot overwrite existing entry with function " << pFunctionDef->Name() << std::endl;
450  throw Exception("FunctionRegistry::Insert()", err.str(), 46);
451  }
452  // test for name
453  if(pFunctionDef->Name()=="") {
454  std::stringstream err;
455  err << "Cannot have empty name"<< std::endl;
456  throw Exception("FunctionRegistry::Insert()", err.str(), 46);
457  };
458  // record in maps
459  mNameToFunctionDef[pFunctionDef->Name()]=pFunctionDef;
460  const Type* pt=pFunctionDef->Prototype();
461  if(pt)
462  mIdToFunctionDef[typeid(*pt).name()]=pFunctionDef;
463 }
464 
465 
466 // scan token stream for function definitions
468  FD_DREG("FunctionRegistry::MergeDocumentation(): using " << rTr.FileName());
469  // scan file
470  Token token;
471  while(rTr.Peek(token)) {
472  // test for FunctionDefinition with name
473  // note: we intentionally accept LuaFunctionDefinitions for RTI documentation
474  if(!token.IsBegin())
475  { rTr.Get(token); continue; }
476  if((token.StringValue()!="FunctionDefinition") && (token.StringValue()!="LuaFunctionDefinition"))
477  { rTr.Get(token); continue; }
478  if(!token.ExistsAttributeString("name"))
479  { rTr.Get(token); continue; }
480  // found function def in file, extract ftype
481  std::string ffunction=token.AttributeStringValue("name");
482  size_t pos=ffunction.find("::");
483  if(pos!=std::string::npos) ffunction=ffunction.substr(pos+2);
484  // locate functiondef in map
485  Iterator fit = mNameToFunctionDef.find(ffunction);
486  // case 1: function exists (from LoadRegistry or c++-Autoregister): add documentaion
487  if(fit!=mNameToFunctionDef.end()) {
488  fit->second->MergeDocumentation(rTr);
489  continue;
490  }
491  // case 2: function does not exist (e.g. with ref2html): insert fake entry
492  FunctionDefinition* fdef = new FunctionDefinition(ffunction);
493  fdef->MergeDocumentation(rTr);
494  Insert(fdef);
495  }
496 }
497 
498 
499 // scan file for function definitions
500 void FunctionRegistry::MergeDocumentation(const std::string& rFileName) {
501  TokenReader tr(rFileName);
502  MergeDocumentation(tr);
503 }
504 
505 
506 // construct faudes object by functionname
507 Function* FunctionRegistry::NewFunction(const std::string& rName) const{
508  FD_DRTI("FunctionRegistry::NewFunction(\"" << rName << "\")");
509  Iterator mit=mNameToFunctionDef.find(rName);
510  if(mit == End()) {
511  std::stringstream err;
512  err << "Unknown function " << rName << std::endl;
513  throw Exception("FunctionRegistry::NewFunction()", err.str(), 47);
514  }
515  Function* res=mit->second->NewFunction();
516  if(!res) {
517  std::stringstream err;
518  err << "Failed to instatiate new " << rName << std::endl;
519  throw Exception("FunctionRegistry::NewFunction()", err.str(), 47);
520  }
521  return res;
522 }
523 
524 // construct faudes object by function reference
526  FD_DRTI("FunctionRegistry::NewFunction(prototype): typeid " << typeid(rFunction).name());
527  Iterator mit;
528  mit=mIdToFunctionDef.find(typeid(rFunction).name());
529  if(mit == mIdToFunctionDef.end()) {
530  std::stringstream err;
531  err << "Unknown function by reference" << std::endl;
532  throw Exception("FunctionRegistry::NewFunction()", err.str(), 47);
533  }
534  return(rFunction.New());
535 }
536 
537 // access function definition by function name
538 const FunctionDefinition& FunctionRegistry::Definition(const std::string& rName) const{
539  FD_DRTI("FunctionRegistry::Definition( " << rName << " )");
540  Iterator mit=mNameToFunctionDef.find(rName);
541  if(mit == End()) {
542  std::stringstream err;
543  err << "Function not found: " << rName;
544  throw Exception("FunctionRegistry::Definition()", err.str(), 46);
545  }
546  return(*(mit->second));
547 }
548 
549 // access function definition by functiond reference
551  FD_DRTI("FunctionRegistry::Definition(): typeid " << typeid(rFunction).name());
552  Iterator mit;
553  mit=mIdToFunctionDef.find(typeid(rFunction).name());
554  if(mit!=mIdToFunctionDef.end()) return *(mit->second);
555  std::stringstream err;
556  err << "Function not found: " << typeid(rFunction).name();
557  throw Exception("FunctionRegistry::Definition()", err.str(), 46);
558 }
559 
560 // access function definition by typed reference
561 const std::string& FunctionRegistry::FunctionName(const Function& rFunction) const{
562  FD_DRTI("FunctionRegistry::FunctionName(): typeid " << typeid(rFunction).name());
563  Iterator mit;
564  mit=mIdToFunctionDef.find(typeid(rFunction).name());
565  if(mit!=mIdToFunctionDef.end()) return mit->second->Name();
566  static const std::string empty("");
567  return empty;
568 }
569 
570 // test existence by function name
571 bool FunctionRegistry::Exists(const std::string& rName) const{
572  return mNameToFunctionDef.find(rName) != End();
573 }
574 
575 // test existsnce by function
576 bool FunctionRegistry::Exists(const Function& rFunction) const{
577  return mIdToFunctionDef.find(typeid(rFunction).name()) != mIdToFunctionDef.end();
578 }
579 
580 
581 // token write (informative/debugging)
582 void FunctionRegistry::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
583  FD_DREG("FunctionRegistry::DoWrite(): file " << rTw.FileName());
584  // ignore label and context
585  (void) rLabel;
586  (void) pContext;
587  // doit
588  Iterator tit;
589  for(tit=Begin();tit!=End();tit++) {
590  // write function definition
591  rTw.WriteXmlComment("===================================================");
592  rTw.WriteXmlComment("===================================================");
593  rTw.WriteXmlComment("Faudes Function " + tit->second->Name());
594  rTw.WriteXmlComment("===================================================");
595  rTw.WriteXmlComment("===================================================");
596  rTw << "\n";
597  tit->second->Write(rTw);
598  rTw << "\n" << "\n";
599  }
600 }
601 
602 
603 /*
604 ********************************************************************
605 ********************************************************************
606 ********************************************************************
607 
608 Implemantation of LoadRegistry
609 
610 ********************************************************************
611 ********************************************************************
612 ********************************************************************
613 */
614 
615 // load from file
616 void LoadRegistry(const std::string& rPath) {
617  FD_DREG("LoadRegistry(" << rPath << ")");
618  // default path
619  std::string rtipath = rPath;
620  if(rtipath=="") rtipath="./libfaudes.rti"; // todo: plattform/configure
621  // clear
622  TypeRegistry::G()->Clear(); // note: we do not clear "c++-autoregistered" types
624 
625  // auto install types extracted from rti file
626 #ifndef FAUDES_MUTE_RTIAUTOLOAD
627  LoadRegisteredTypes(); // note: this does not load "c++-autoregistered" types
628 #endif
629 
630  // allow build system load registry programmatic contributions defined in plugins
631  // (this is currently not used by any plug-in)
632 #ifdef FAUDES_PLUGINS_RTILOAD
633  FAUDES_PLUGINS_RTILOAD;
634 #endif
635 
636  // auto install functions extracted from rti file
637  // (this is currently not used by any plug-in)
638 #ifndef FAUDES_MUTE_RTIAUTOLOAD
639  LoadRegisteredFunctions();
640 #endif
641 
642  // merge documentation
645 
646  // test and report status
647 #ifdef FAUDES_CHECKED
648 #ifndef FAUDES_MUTE_RTIAUTOLOAD
650  for(tit=TypeRegistry::G()->Begin(); tit!=TypeRegistry::G()->End(); tit++) {
651  // should have prototype
652  if(tit->second->PlugIn()!="IODevice")
653  if(tit->second->Prototype()==NULL)
654  FD_WARN("TypeRegistry: " << tit->second->Name() << " has no prototype");
655  }
657  for(fit=FunctionRegistry::G()->Begin(); fit!=FunctionRegistry::G()->End(); fit++) {
658  // should have prototype
659  if(fit->second->Prototype()==NULL)
660  FD_WARN("FunctionRegistry: " << fit->second->Name() << " has no prototype");
661  }
662 #endif
663 #endif
664 
665  FD_DREG("LoadRegistry(" << rPath << "): done");
666 }
667 
668 
669 // save to file or std out
670 void SaveRegistry(const std::string& rPath) {
671  FD_DRTI("SaveRegistry(" << rPath << ")");
672  // have a tokenwriter
673  TokenWriter* ptw;
674  if(rPath=="") {
675  ptw = new TokenWriter(TokenWriter::Stdout);
676  } else {
677  ptw = new TokenWriter(rPath,"Registry");
678  }
679  // do the write
680  ptw->WriteBegin("Registry");
681  ptw->Endl();
682  TypeRegistry::G()->Write(*ptw);
683  FunctionRegistry::G()->Write(*ptw);
684  ptw->Endl();
685  ptw->WriteEnd("Registry");
686  // dispose
687  delete ptw;
688 }
689 
690 
691 // clear all
692 void ClearRegistry(void) {
693  FD_DRTI("ClearRegistry()");
694  // clear
697 }
698 
699 // conveience access to singleton
700 Type* NewFaudesObject(const std::string& rTypeName) { return TypeRegistry::G()->NewObject(rTypeName);}
701 Function* NewFaudesFunction(const std::string& rFunctName) { return FunctionRegistry::G()->NewFunction(rFunctName);}
702 const std::string& FaudesTypeName(const Type& rObject) { return TypeRegistry::G()->TypeName(rObject);}
703 bool FaudesTypeTest(const std::string& rTypeName, const Type& rObject) { return TypeRegistry::G()->TypeTest(rTypeName,rObject);}
704 const std::string& FaudesFunctionName(const Function& rObject) { return FunctionRegistry::G()->FunctionName(rObject);}
705 
706 
707 } // namespace
#define FD_DREG(message)
Debug: optional report registry operations.
#define FD_DV(message)
Debug: optional low-level report on iterations and token IO.
#define FD_DRTI(message)
Debug: optional on function and type definition.
#define FD_WARN(message)
Debug: always report warnings.
Runtime interface, registry for faudes-types and functions.
virtual void MergeDocumentation(TokenReader &rTr)
Merge documentation from token stream.
Definition: cfl_types.cpp:491
const std::string & Name(void) const
Get name of the entety to document (aka faudes-type or faudes-function).
Definition: cfl_types.cpp:396
Faudes exception class.
A FunctionDefinition defines the interface to a faudes-function.
const Function * Prototype(void) const
Return pointer to function object prototype.
The FunctionRegistry registers faudes-functions.
Definition: cfl_registry.h:496
Iterator End(void) const
STL interator to the internal function-name map.
bool Exists(const std::string &rName) const
Test existence of a faudes-function by its name.
static FunctionRegistry * G()
Method to access the single global instance of the registry.
void Clear()
Clear all registered function definitions.
std::map< std::string, FunctionDefinition * >::const_iterator Iterator
Convenience typedef to access registry entries.
Definition: cfl_registry.h:501
static FunctionRegistry * mpInstance
Singleton instance.
Definition: cfl_registry.h:723
int Size() const
Return number of registered function definitions.
const FunctionDefinition & Definition(const std::string &rFunctionName) const
Look up the function definition by faudes-function name.
Function * NewFunction(const std::string &rFunctionName) const
Construct a faudes object by function name.
FunctionRegistry()
Constructor.
Definition: cfl_registry.h:726
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Write registry data of this to TokenWriter.
void Insert(FunctionDefinition *pFunctionDef)
Add another function definition to the registry.
void MergeDocumentation(TokenReader &rTr)
Scan token input for function documentation.
std::map< std::string, FunctionDefinition * > mNameToFunctionDef
Map to associate labels and faudes::FunctionDefinitions.
Definition: cfl_registry.h:734
const std::string & FunctionName(const Function &rFunction) const
Look up the function name by faudes object.
std::map< std::string, FunctionDefinition * > mIdToFunctionDef
Definition: cfl_registry.h:735
Iterator Begin(void) const
STL interator to the internal function-name map.
A faudes-function hosts parameter values of some faudes type and provides a method to perform an oper...
virtual Function * New() const =0
Construct on heap.
A TokenReader reads sequential tokens from a file or string.
bool Get(Token &token)
Get next token.
bool Peek(Token &token)
Peek next token.
std::string FileName(void) const
Access the filename.
A TokenWriter writes sequential tokens to a file, a string or stdout.
std::string FileName(void) const
Get the filename.
void WriteXmlComment(const std::string &rComment)
Write comment in Xml format.
void Write(Token &rToken)
Write next token.
void Endl(void)
Write endl separator.
void WriteEnd(const std::string &rLabel)
Write end label.
void WriteBegin(const std::string &rLabel)
Write begin label.
Tokens model atomic data for stream IO.
Definition: cfl_token.h:53
const std::string & StringValue(void) const
Get string value of a name token.
Definition: cfl_token.cpp:177
bool ExistsAttributeString(const std::string &name)
Test attibute existence.
Definition: cfl_token.cpp:355
bool IsBegin(void) const
Test token Type.
Definition: cfl_token.cpp:258
const std::string & AttributeStringValue(const std::string &name)
Access attribute value.
Definition: cfl_token.cpp:385
A TypeDefinition defines a faudes-type in that it specifies a faudes-type name to identify the type a...
Definition: cfl_types.h:1462
const Type * Prototype(void) const
Return pointer to faudes-object prototype.
Definition: cfl_types.cpp:815
The TypeRegistry registers faudes-types.
Definition: cfl_registry.h:47
Type * NewObject(const std::string &rTypeName) const
Construct a faudes object by type name.
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Write registry data of this to TokenWriter.
const std::string & TypeName(const Type &rType) const
Look up the type name by faudes object.
const Type * Prototype(const std::string &rTypeName) const
Look up the prototype object by faudes-type name.
void XElementTag(const std::string &rTypeName, const std::string &rTag)
Set Xml element tag for given faudes-type.
std::map< std::string, TypeDefinition * > mIdToTypeDef
Definition: cfl_registry.h:436
void MergeDocumentation(TokenReader &rTr)
Scan token input for type documentation.
TypeRegistry()
Constructor.
Definition: cfl_registry.h:427
const TypeDefinition & Definition(const std::string &rTypeName) const
Look up the type definition by faudes-type name.
static TypeRegistry * G()
Method to access the single global instance of the registry.
static TypeRegistry * mpInstance
Singleton instance.
Definition: cfl_registry.h:424
void Insert(TypeDefinition *pTypeDef)
Add another type definition to the registry.
const TypeDefinition * Definitionp(const std::string &rTypeName) const
Look up the type definition by faudes-type name.
int Size() const
Return number of registered type definitions.
bool AutoRegistered(const std::string &rTypeName) const
Get AutoRegister flag for given faudes-type.
Iterator Begin(void) const
STL interator to the internal type-name map.
virtual const std::string & TypeName(void) const
Cosmetic: fix compile warning for recent LLVM/clang++.
Definition: cfl_types.cpp:132
void ClearAll()
Clear all registered type definitions.
bool TypeTest(const std::string &rTypeName, const Type &rObject) const
Test type compatibility.
std::map< std::string, TypeDefinition * > mNameToTypeDef
Map to associate labels and faudes::TypeDefinitions.
Definition: cfl_registry.h:435
void Clear()
Clear all registered type definitions.
bool Exists(const std::string &rName) const
Test existence of a faudes-type by its name.
Iterator End(void) const
STL interator to the internal type-name map.
std::map< std::string, TypeDefinition * >::const_iterator Iterator
Convenience typedef to access registry entries.
Definition: cfl_registry.h:52
Base class of all libFAUDES objects that participate in the run-time interface.
Definition: cfl_types.h:239
virtual Type * New(void) const
Construct on heap.
Definition: cfl_types.cpp:54
void Write(const Type *pContext=0) const
Write configuration data to console.
Definition: cfl_types.cpp:139
Includes all libFAUDES headers, no plugins.
void SaveRegistry(const std::string &rPath)
Dump all registered types and functions.
bool FaudesTypeTest(const std::string &rTypeName, const Type &rObject)
Test type compatibility.
Function * NewFaudesFunction(const std::string &rFunctName)
Instantiate faudes function objects by function name.
void ClearRegistry(void)
Clear all registry.
void LoadRegistry(const std::string &rPath)
Load all registered types and functions.
const std::string & FaudesTypeName(const Type &rObject)
Query type name.
Type * NewFaudesObject(const std::string &rTypeName)
Instantiate faudes typed objects by type name.
libFAUDES resides within the namespace faudes.
const std::string & FaudesFunctionName(const Function &rObject)

libFAUDES 2.32b --- 2024.03.01 --- c++ api documentaion by doxygen