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