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

libFAUDES 2.33k --- 2025.09.16 --- c++ api documentaion by doxygen