cfl_types.cpp
Go to the documentation of this file.
1/** @file cfl_types.cpp Runtime interface, faudes types */
2
3/* FAU Discrete Event Systems Library (libfaudes)
4
5Copyright (C) 2009 Ruediger Berndt
6Copyright (C) 2010-2025 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#include "cfl_types.h"
24#include "cfl_registry.h"
25
26namespace faudes{
27
28/*
29********************************************************************
30********************************************************************
31********************************************************************
32
33implemantation of faudes Type
34
35********************************************************************
36********************************************************************
37********************************************************************
38*/
39
40// statics
41std::string Type::msStringVoid("Void");
42std::string Type::msStringEmpty("");
43
44// constructor
45Type::Type(void) {}
46
47// copy constructor
48Type::Type(const Type& rType) {(void) rType;}
49
50// destructor
52
53// pointer constructor
54Type* Type::New(void) const {
55 FD_WARN("Type(" << this << ")::New(): not reimplemented for " << typeid(*this).name());
56 return new Type();
57}
58
59// pointer copy constructor
60Type* Type::Copy(void) const {
61 FD_WARN("Type(" << this << ")::Copy(): not reimplemented for " << typeid(*this).name());
62 return new Type(*this);
63}
64
65// cast
66const Type* Type::Cast(const Type* pOther) const {
67 FD_WARN("Type(" << this << ")::Cast(" << pOther << "): not reimplemented for " << typeid(*this).name());
68 return pOther;
69}
70
71// Clear()
72void Type::Clear(void) {
73 FD_DC("Type::Clear(): not re-implemented in " << typeid(*this).name());
74}
75
76// Clear()
77bool Type::IsDefault(void) const {
78 return false;
79}
80
81// assign
82Type& Type::Assign(const Type& rSource) {
83 FD_DC("Type(" << this << ")::Assign(" << &rSource << ")");
84 Clear();
85 return *this;
86}
87
88// equality (relaxed)
89bool Type::Equal(const Type& rOther) const {
90 return true;
91}
92
93// equality (strict)
94bool Type::operator==(const Type& rOther) const {
95 return DoEqual(rOther);
96}
97
98// equality
99bool Type::operator!=(const Type& rOther) const {
100 return !DoEqual(rOther);
101}
102
103// assign
104Type& Type::operator=(const Type& rSource) {
105 FD_DC("Type(" << this << ")::AssignementOperator(" << &rSource << ")");
106 Clear();
107 DoAssign(rSource);
108 return *this;
109}
110
111// assign
112void Type::DoAssign(const Type& rSource) {
113 FD_DC("Type(" << this << ")::DoAssign(" << &rSource << ")");
114}
115
116// equality
117bool Type::DoEqual(const Type& rOther) const {
118 //typeid(*this)==typeid(rOther); TM 2025
119 return true;
120}
121
122// Name(rName)
123void Type::Name(const std::string& rName) {
124 (void) rName;
125}
126
127// Name()
128const std::string& Type::Name(void) const {
129 return msStringEmpty;
130}
131
132// TypeDefinitionp()
134 return TypeRegistry::G()->Definitionp(*this);
135}
136
137// TypeName()
138const std::string& Type::TypeName(void) const {
139 const TypeDefinition* fdp=TypeDefinitionp();
140 if(!fdp) return msStringEmpty;
141 return fdp->Name();
142}
143
144// Write(context)
145void Type::Write(const Type* pContext) const {
147 DoWrite(tw,"",pContext);
148}
149
150// Write(rFileName, label, context, openmode)
151void Type::Write(const std::string& rFileName, const std::string& rLabel,
152 const Type* pContext, std::ios::openmode openmode) const {
153 try {
154 TokenWriter tw(rFileName, openmode);
155 DoWrite(tw, rLabel, pContext);
156 }
157 catch(std::ios::failure&) {
158 std::stringstream errstr;
159 errstr << "Exception opening/writing file \"" << rFileName << "\"";
160 throw Exception("Type::Write", errstr.str(), 2);
161 }
162}
163
164// Write(rFileName, openmode)
165void Type::Write(const std::string& rFileName, std::ios::openmode openmode) const {
166 Write(rFileName,"",0,openmode);
167}
168
169// Write(tw,label,context)
170void Type::Write(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
171 DoWrite(rTw,rLabel,pContext);
172}
173
174// ToString(label, context)
175std::string Type::ToString(const std::string& rLabel, const Type* pContext) const {
177 tw.Endl(false);
178 DoWrite(tw,rLabel,pContext);
179 return tw.Str();
180}
181
182// ToSText()
183std::string Type::ToSText(void) const {
185 tw.Endl(true);
186 DoSWrite(tw);
187 return tw.Str();
188}
189
190// ToString(label, context)
191std::string Type::ToText(const std::string& rLabel, const Type* pContext) const {
193 tw.Endl(true);
194 DoWrite(tw,rLabel,pContext);
195 return tw.Str();
196}
197
198// XWrite(context)
199void Type::XWrite(const Type* pContext) const {
200 FD_DC("Type(" << this << ")::XWrite(): for " << typeid(*this).name());
202 DoXWrite(tw,"",pContext);
203}
204
205// XWrite(rFileName, label, context)
206void Type::XWrite(const std::string& rFileName, const std::string& rLabel, const Type* pContext) const {
207 std::string ftype=TypeName();
208 if(ftype=="") {
209 std::stringstream errstr;
210 errstr << "Cannot write unregistered faudes-type object \"" << typeid(*this).name() << "\"";
211 throw Exception("Type::XWrite", errstr.str(), 2);
212 }
213 try {
214 TokenWriter tw(rFileName,ftype);
215 XWrite(tw, rLabel, pContext);
216 }
217 catch(std::ios::failure&) {
218 std::stringstream errstr;
219 errstr << "Exception opening/writing file \"" << rFileName << "\"";
220 throw Exception("Type::XWrite", errstr.str(), 2);
221 }
222}
223
224// XWrite(tw,label,context)
225void Type::XWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
226 FD_DC("Type(" << this << ")::XWrrite(): for " << typeid(*this).name());
227 DoXWrite(rTw,rLabel,pContext);
228}
229
230// DWrite(context)
231void Type::DWrite(const Type* pContext) const {
233 DoDWrite(tw,"",pContext);
234}
235
236// DWrite(rFileName, label, context, openmode)
237void Type::DWrite(const std::string& rFileName, const std::string& rLabel,
238 const Type* pContext, std::ios::openmode openmode) const {
239 try {
240 TokenWriter tw(rFileName, openmode);
241 DoDWrite(tw, rLabel, pContext);
242 }
243 catch(std::ios::failure&) {
244 std::stringstream errstr;
245 errstr << "Exception opening/writing file \"" << rFileName << "\"";
246 throw Exception("Type::DWrite", errstr.str(), 2);
247 }
248}
249
250// DWrite(tw,label,context)
251void Type::DWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
252 DoDWrite(rTw,rLabel,pContext);
253}
254
255// SWrite()
256void Type::SWrite(void) const {
258 DoSWrite(tw);
259}
260
261// SWrite(tw)
262void Type::SWrite(TokenWriter& rTw) const {
263 DoSWrite(rTw);
264}
265
266// Read(rFilename, rLabel,context)
267void Type::Read(const std::string& rFilename, const std::string& rLabel, const Type* pContext) {
268 Clear();
269 TokenReader tr(rFilename);
270 if(rLabel!="") tr.SeekBegin(rLabel);
271 DoRead(tr,rLabel,pContext);
272}
273
274// Read(rTr, rLabel, context)
275void Type::Read(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
276 Clear();
277 DoRead(rTr,rLabel,pContext);
278}
279
280// FromString(rString, rLabel, context)
281void Type::FromString(const std::string& rString, const std::string& rLabel, const Type* pContext) {
282 Clear();
284 DoRead(tr,rLabel,pContext);
285}
286
287//DoWrite(rTr,rLabel,pContext)
288void Type::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
289 (void) rTw; (void) rLabel; (void) pContext;
290 FD_DC("Type::DoWrite(): not re-implemented in " << typeid(*this).name());
291}
292
293//DoXWrite(rTr,rLabel,pContext)
294void Type::DoXWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
295 DoWrite(rTw, rLabel, pContext);
296}
297
298//DoDWrite(rTr,rLabel,pContext)
299void Type::DoDWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
300 FD_DC("Type::DoDWrite(): not re-implemented in " << typeid(*this).name() << ", using DoDWrite instead");
301 DoWrite(rTw,rLabel,pContext);
302}
303
304//DoSWrite(rTr,rLabel,pContext)
305void Type::DoSWrite(TokenWriter& rTw) const {
306 FD_DC("Type::DoSWrite(): not re-implemented in " << typeid(*this).name());
307 rTw.WriteComment("");
308 rTw.WriteComment(" Statistics for " + Name());
309 rTw.WriteComment("");
310}
311
312//DoRead(rTr,rLabel,pContext)
313void Type::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
314 (void) rLabel; (void) pContext; (void) rTr;
315 FD_DC("Type::DoRead(): not re-implemented in " << typeid(*this).name());
316}
317
318
319
320// configure begin token
321Token Type::XBeginTag(const std::string& rLabel,const std::string& rFallbackLabel) const {
322 // provided
323 std::string label=rLabel;
324 std::string ftype=TypeName();
325 // fallback label
326 if(label=="") label=ftype;
327 if(label=="") label=rFallbackLabel;
328 Token btag;
329 btag.SetBegin(label);
330 if(Name()!=label && Name()!="") btag.InsAttributeString("name",Name());
331 if(ftype!=label && ftype!="") btag.InsAttributeString("ftype",ftype);
332 // done
333 return btag;
334}
335
336
337
338/*
339********************************************************************
340********************************************************************
341********************************************************************
342
343Implementation of class ExtType
344
345********************************************************************
346********************************************************************
347********************************************************************
348*/
349
350// faudes type
352
353// constructor
356}
357
358// constructor
359AttrType::AttrType(const AttrType& rOther) : Type(rOther) {
360 FAUDES_OBJCOUNT_INC("AttrType");
361}
362
363// destructor
365 FAUDES_OBJCOUNT_DEC("AttrType");
366}
367
368//Skip(rTr)
370 FD_DC("AttrType::Skip()");
371 Token token;
372 while(rTr.Peek(token)) {
373 // break on index or name, since this is the next element
374 if((token.Type()==Token::String) || (token.Type()==Token::Integer)) {
375 break;
376 }
377 // break on end, since this is the end of the container
378 if(token.Type()==Token::End) {
379 break;
380 }
381 // break on Consecutive section, since this belongs to the container
382 if((token.Type()==Token::Begin) && (token.StringValue() == "Consecutive")) {
383 break;
384 }
385 // skip any attribute section from other file format
386 if(token.Type()==Token::Begin){
387 rTr.ReadBegin(token.StringValue());
388 rTr.ReadEnd(token.StringValue());
389 continue;
390 }
391 // skip any other token from other file format
392 rTr.Get(token);
393 }
394}
395
396
397/*
398********************************************************************
399********************************************************************
400********************************************************************
401
402Implementation of class ExtType
403
404********************************************************************
405********************************************************************
406********************************************************************
407*/
408
409// std faudes type methods
411
412// constructor
413ExtType::ExtType(void) : AttrType(), pTypeDefinition(nullptr) {}
414
415// copy constructor
416ExtType::ExtType(const ExtType& rType) : AttrType(), pTypeDefinition(nullptr) {(void) rType;}
417
418// destructor
420
421// Name
422const std::string& ExtType::Name(void) const {
423 return mObjectName;
424}
425
426// Name
427void ExtType::Name(const std::string& rName) {
428 mObjectName = rName;
429}
430
431// TypeDefinitionp()
432// Note: fake const construct
434 if(!pTypeDefinition) {
435 // provide fake const
436 ExtType* fake_const = const_cast< ExtType* >(this);
437 fake_const->pTypeDefinition=TypeRegistry::G()->Definitionp(*this);
438 }
439 return pTypeDefinition;
440}
441
442// Faudes Type
443const std::string& ExtType::TypeName(void) const {
444 if(mFaudesTypeName.empty()) {
445 // provide fake const
446 ExtType* fake_const = const_cast< ExtType* >(this);
447 const TypeDefinition* fdp=TypeDefinitionp();
448 if(fdp) fake_const->mFaudesTypeName=fdp->Name();
449 }
450 return mFaudesTypeName;
451}
452
453// Faudes Type
454void ExtType::TypeName(const std::string& rType) {
455 mFaudesTypeName=rType;
456}
457
458// ElementTag
459const std::string& ExtType::ElementTag(void) const {
460 FD_DRTI("ExtType::ElementTag(" << typeid(*this).name() <<")");
461 if(mElementTag.empty()) {
462 // provide fake const
463 ExtType* fake_const = const_cast< ExtType* >(this);
464 fake_const->mElementTag=mElementTagDef;
465 const TypeDefinition* fdp=TypeDefinitionp();
466 if(fdp) {
467 FD_DRTI("Type::ElementTag: type " << fdp->TypeName() << "etag " << fdp->ElementTag());
468 if(!fdp->ElementTag().empty()) fake_const->mElementTag=fdp->ElementTag();
469 }
470 }
471 FD_DRTI("Type::ElementTag(" << typeid(*this).name() <<"): using tag: " << mElementTag);
472 return mElementTag;
473}
474
475// ElementTag
476void ExtType::ElementTag(const std::string& rTag) {
477 mElementTag=rTag;
478}
479
480
481// figure element type
482const std::string& ExtType::ElementType(void) const {
483 FD_DRTI("ExtType::ElementType(" << typeid(*this).name() <<")");
484 if(mElementType.empty()) {
485 // provide fake const
486 ExtType* fake_const = const_cast< ExtType* >(this);
487 const TypeDefinition* fdp=TypeDefinitionp();
488 if(fdp) {
489 FD_DRTI("Type::ElementType: type " << fdp->TypeName() << "etype " << fdp->ElementType());
490 if(!fdp->ElementType().empty()) fake_const->mElementType=fdp->ElementType();
491 }
492 }
493 FD_DRTI("Type::ElementType(" << typeid(*this).name() <<"): using tag: " << mElementType);
494 return mElementType;
495}
496
497
498
499
500
501/*
502********************************************************************
503********************************************************************
504********************************************************************
505
506Implementation of class Documentation
507
508********************************************************************
509********************************************************************
510********************************************************************
511*/
512
513// faudes type (cannot do autoregister)
519
520// construct
522 mAutoRegistered=false;
523 mApplicationRegistered=false;
524}
525
526// construct
528 DoAssign(rOther);
529}
530
531// std faudes type
533 // assign my members
534 mName=rSrc.mName;
535 mPlugIn=rSrc.mPlugIn;
536 mHtmlDoc=rSrc.mHtmlDoc;
537 mTextDoc=rSrc.mTextDoc;
538 mKeywords=rSrc.mKeywords;
539}
540
541// std faudes type
542bool Documentation::DoEqual(const Documentation& rOther) const {
543 // test my members
544 if(mName!=rOther.mName) return false;
545 if(mPlugIn!=rOther.mPlugIn) return false;
546 if(mHtmlDoc!=rOther.mHtmlDoc) return false;
547 if(mTextDoc!=rOther.mTextDoc) return false;
548 if(mKeywords!=rOther.mKeywords) return false;
549 return true;
550}
551
552// clear all
554 FD_DRTI("Documentation::Clear()");
555 mName="";
556 mPlugIn="CoreFaudes";
557 mHtmlDoc="";
558 mTextDoc="";
559 mKeywords="";
560 mAutoRegistered=false;
562}
563
564// read access members
565const std::string& Documentation::Name(void) const{ return mName; }
566const std::string& Documentation::PlugIn(void) const{ return mPlugIn; }
567const std::string& Documentation::CType(void) const{ return mCType; }
568const std::string& Documentation::TextDoc() const{ return mTextDoc; }
569const std::string& Documentation::HtmlDoc() const{ return mHtmlDoc; }
570const std::string& Documentation::Keywords() const{ return mKeywords; }
573
574// write access members
575void Documentation::Name(const std::string& name){mName = name; }
576void Documentation::PlugIn(const std::string& plugin){mPlugIn = plugin; }
577void Documentation::CType(const std::string& name){mCType = name; }
578void Documentation::TextDoc(const std::string& textdoc){mTextDoc = textdoc;}
579void Documentation::HtmlDoc(const std::string& fname){mHtmlDoc = fname;}
582
583// write access keyword
584void Documentation::AddKeyword(const std::string& rKeyword){
585 if(mKeywords.empty()){
586 mKeywords = rKeyword;
587 } else{
588 mKeywords.append(1, mDelim);
589 mKeywords.append(rKeyword);
590 }
591}
592
593// regex match keywords (todo)
594std::string Documentation::MatchKeyword(const std::string& rPattern) const{
595 FD_DRTI("Documentation::MatchKeyword(" << rPattern << ")");
596 // be case insensitive (inefficient)
597 std::string keys = mKeywords;
598 std::transform(keys.begin(), keys.end(), keys.begin(), tolower);
599 std::string match = rPattern;
600 std::transform(match.begin(), match.end(), match.begin(), tolower);
601 // find match
602 std::string res="";
603 std::size_t posk=keys.find(match);
604 if(posk==std::string::npos) return res;
605 // find delimiters
606 std::size_t posa=0;
607 std::size_t posb=keys.length();
608 while(true) {
609 posb=keys.find(mDelim,posa);
610 if(posb==std::string::npos) posb=mKeywords.length();
611 if(posb>posk) break;
612 posa=posb+1;
613 };
614 // return original case match
615 FD_DRTI("Documentation::MatchKeyword(" << rPattern << "): " << mKeywords.substr(posa,posb-posa));
616 return mKeywords.substr(posa,posb-posa);
617}
618
619
620// positional keyword
621std::string Documentation::KeywordAt(int pos) const{
622 FD_DRTI("Documentation::KeywordAt(" << pos << ")");
623 // default result
624 std::string res="";
625 // find delimiter
626 std::size_t posa=0;
627 std::size_t posb=mKeywords.length();
628 while(pos>0) {
629 if(posa>=mKeywords.length()) return res;
630 posb=mKeywords.find(mDelim,posa);
631 if(posb==std::string::npos) return res;
632 posa=posb+1;
633 pos--;
634 };
635 // default result
636 res=mKeywords.substr(posa);
637 // find next delimiter
638 posb=res.find(mDelim);
639 if(posb==std::string::npos) return res;
640 res=res.substr(0,posb);
641 return res;
642}
643
644// keyword
646 int cnt=0;
647 // find delimiter
648 std::size_t pos=0;
649 while(pos<mKeywords.length()) {
650 cnt++;
651 pos=mKeywords.find(mDelim,pos);
652 if(pos==std::string::npos) break;
653 pos++;
654 };
655 return cnt;
656}
657
658
659// merge with docu from token io
661 FD_DRTI("Documentation::MergeDocumentation(): for " << mName);
662 // get first token to test type definition
663 Token token;
664 rTr.Peek(token);
665 if(!token.IsBegin()) return;
666 std::string label=token.StringValue();
667 // get ftype and test for match
668 std::string ftype=token.AttributeStringValue("name");
669 size_t pos=ftype.find("::");
670 if(pos!=std::string::npos) ftype=ftype.substr(pos+2);
671 // match?
672 if( (mName!=ftype && mName!="") || (ftype=="")) {
673 std::stringstream errstr;
674 errstr << "Documentation mismatch in file \"" << rTr.FileName() << "\" : " << mName << "!=" << ftype;
675 throw Exception("Documentation::MergeDocumentation", errstr.str(), 48);
676 };
677 // do read
678 DoRead(rTr,label);
679}
680
681// token io
682void Documentation::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
683 FD_DRTI("Documentation::DoRead(): file " << rTr.FileName());
684 // ignore
685 (void) pContext;
686 // figure my section
687 std::string label = rLabel;
688 if(label=="") label="Documentation";
689 // get first token for ftype and ctype
690 Token token;
691 rTr.ReadBegin(label,token);
692
693 // sense and digest pre 2.16b format
694 if(!token.ExistsAttributeString("name")) {
695 Token ptoken;
696 rTr.Peek(ptoken);
697 mName=ptoken.StringValue();
698 size_t pos=mName.find("::");
699 if(pos!=std::string::npos) mName=mName.substr(pos+2);
700 mPlugIn=ptoken.StringValue();
701 pos=mPlugIn.find("::");
702 if(pos!=std::string::npos) mPlugIn=mPlugIn.substr(0,pos);
703 else mPlugIn = "CoreFaudes";
704 DoReadCore(rTr);
705 rTr.ReadEnd(label);
706 return;
707 } // end pre 2.16b format
708
709 // get ftype
710 mName=token.AttributeStringValue("name");
711 size_t pos=mName.find("::");
712 if(pos!=std::string::npos) mName=mName.substr(pos+2);
713 // get plugin
714 mPlugIn=token.AttributeStringValue("name");
715 pos=mPlugIn.find("::");
716 if(pos!=std::string::npos) mPlugIn=mPlugIn.substr(0,pos);
717 else mPlugIn = "CoreFaudes";
718 // get ctype
719 mCType=token.AttributeStringValue("ctype");
720
721 // get autoreg flag (note: let flag survive if originally set and no attribute)
722 if(token.ExistsAttributeInteger("autoregister"))
723 mAutoRegistered = (token.AttributeIntegerValue("autoregister"));
724 // report
725 FD_DRTI("Documentation::DoRead(): found " << mName << " " << mCType);
726 // do read
727 DoReadCore(rTr);
728 // done
729 rTr.ReadEnd(label);
730}
731
732// token read
734 FD_DRTI("Documentation::DoReadCore()");
735 Token token;
736 mTextDoc="";
737 mHtmlDoc="";
738 mKeywords="";
739
740 // sense and digest pre 2.16 format
741 rTr.Peek(token);
742 if(token.IsString()) {
743 mName=token.StringValue();
744 size_t pos=mName.find("::");
745 if(pos!=std::string::npos) mName=mName.substr(pos+2);
746 mPlugIn=token.StringValue();
747 pos=mPlugIn.find("::");
748 if(pos!=std::string::npos) mPlugIn=mPlugIn.substr(0,pos);
749 else mPlugIn = "CoreFaudes";
750 rTr.ReadString();
751 mCType="";
752 rTr.Peek(token);
753 if(token.IsOption())
754 mCType = rTr.ReadOption();
755 while(true) {
756 rTr.Peek(token);
757 if(token.IsBegin())
758 if(token.StringValue()=="TextDoc") {
759 rTr.ReadBegin("TextDoc");
760 mTextDoc = rTr.ReadString();
761 rTr.ReadEnd("TextDoc");
762 continue;
763 }
764 if(token.IsBegin())
765 if(token.StringValue()=="HtmlDoc") {
766 rTr.ReadBegin("HtmlDoc");
767 mHtmlDoc = rTr.ReadString();
768 rTr.ReadEnd("HtmlDoc");
769 continue;
770 }
771 if(token.IsBegin())
772 if(token.StringValue()=="Keywords") {
773 rTr.ReadBegin("Keywords");
774 while(!rTr.Eos("Keywords"))
775 AddKeyword(rTr.ReadString());
776 rTr.ReadEnd("Keywords");
777 continue;
778 }
779 break;
780 }
781 return;
782 } // end pre 2.16 format
783
784 // loop other known entries
785 while(true) {
786 rTr.Peek(token);
787 // do the read: docu
788 if(token.IsBegin())
789 if(token.StringValue()=="Documentation") {
790 if(token.ExistsAttributeString("ref"))
791 mHtmlDoc=token.AttributeStringValue("ref");
792 rTr.ReadText("Documentation",mTextDoc);
793 continue;
794 }
795 // do the read: keys
796 if(token.IsBegin())
797 if(token.StringValue()=="Keywords") {
798 rTr.ReadBegin("Keywords");
799 while(!rTr.Eos("Keywords"))
800 AddKeyword(rTr.ReadString());
801 rTr.ReadEnd("Keywords");
802 continue;
803 }
804 // unknown -> derived class take over
805 break;
806 }
807}
808
809
810// token write
811void Documentation::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
812 // ignore
813 (void) pContext;
814 // figure my section
815 std::string label = rLabel;
816 if(label=="") label="Documentation";
817 // begin tag
818 Token btag;
819 btag.SetBegin(label);
820 if(mPlugIn!="" && mName!="")
821 btag.InsAttribute("name",mPlugIn+"::"+mName);
822 if(mPlugIn=="" && mName!="")
823 btag.InsAttribute("name",mName);
824 if(mCType!="")
825 btag.InsAttribute("ctype",mCType);
827 btag.InsAttributeBoolean("autoregister",true);
828 rTw << btag;
829 // data
830 DoWriteCore(rTw);
831 // end tag
832 rTw.WriteEnd(label);
833}
834
835// token write
837 // write text doc
838 if(mTextDoc!="" || mHtmlDoc!="") {
839 Token btag;
840 btag.SetBegin("Documentation");
841 if(mHtmlDoc!="")
842 btag.InsAttributeString("ref",mHtmlDoc);
843 rTw.WriteText(btag,mTextDoc);
844 }
845 // write keys
846 int ksz=KeywordsSize();
847 if(ksz>0) {
848 rTw.WriteBegin("Keywords");
849 for(int i=0; i<ksz; i++)
850 rTw.WriteString(KeywordAt(i));
851 rTw.WriteEnd("Keywords");
852 }
853}
854
855
856
857/*
858********************************************************************
859********************************************************************
860********************************************************************
861
862Implementation of class TypeDefinition
863
864********************************************************************
865********************************************************************
866********************************************************************
867*/
868
869
870// faudes type (cannot do autoregister)
876
877
878// Typedefinition constructor function
879TypeDefinition* TypeDefinition::Constructor(Type* pProto, const std::string& rTypeName){
880 FD_DRTI("TypeDefinition::Construct(" << typeid(*pProto).name() << ", " << rTypeName << ")");
881 TypeDefinition* td = new TypeDefinition();
882 td->Prototype(pProto);
883 std::string name=rTypeName;
884 if(name=="") name=typeid(*pProto).name();
885 td->Name(name);
886 return(td);
887}
888
889
890// clear (all except prototype)
892 FD_DRTI("TypeDefinition::Clear()");
893 // call base
895 // my members
896 mElementTag="";
897 mElementType="";
898}
899
900
901// std faudes type
903 // assign base members
905 // assign my members
908 // special member
909 if(mpType) delete mpType;
910 mpType=0;
911 if(rSrc.mpType)
912 mpType=rSrc.mpType->New();
913}
914
915// std faudes type
916bool TypeDefinition::DoEqual(const TypeDefinition& rOther) const {
917 // test base members
918 if(!Documentation::DoEqual(rOther)) return false;
919 // test my members
920 if(mElementTag!=rOther.mElementTag) return false;
921 if(mElementType!=rOther.mElementType) return false;
922 return true;
923}
924
925
926// token io
927void TypeDefinition::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
928 FD_DRTI("TypeDefinition::DoRead(): file " << rTr.FileName());
929 // ignore
930 (void) pContext;
931 // figure my section
932 std::string label = rLabel;
933 if(label=="") label="TypeDefinition";
934 // base can handle this
935 Documentation::DoRead(rTr,label,pContext);
936 // my members
937}
938
939// token io
941 FD_DRTI("TypeDefinition::DoReadCore(): file " << rTr.FileName());
942 // call base core
944 // my data
945 while(true) {
946 Token token;
947 rTr.Peek(token);
948 // element tag
949 if(token.IsBegin())
950 if(token.StringValue()=="ElementTag") {
951 rTr.ReadBegin("ElementTag",token);
952 if(token.ExistsAttributeString("value"))
953 mElementTag=token.AttributeStringValue("value");
954 rTr.ReadEnd("ElementTag");
955 continue;
956 }
957 // element type
958 if(token.IsBegin())
959 if(token.StringValue()=="ElementType") {
960 rTr.ReadBegin("ElementType",token);
961 if(token.ExistsAttributeString("value"))
962 mElementType=token.AttributeStringValue("value");
963 rTr.ReadEnd("ElementType");
964 continue;
965 }
966 // break un unknown
967 break;
968 }
969}
970
971// token io
972void TypeDefinition::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
973 // label
974 std::string label=rLabel;
975 if(label=="") label="TypeDefinition";
976 // base can handle
977 Documentation::DoWrite(rTw,label,pContext);
978}
979
980// token io
982 FD_DRTI("TypeDefinition::DoWriteCore(): file " << rTw.FileName());
983 // call base core
985 // my data
986 if(mElementTag!="") {
987 Token etag;
988 etag.SetEmpty("ElementTag");
989 etag.InsAttributeString("value", mElementTag);
990 rTw << etag;
991 }
992 // my data
993 if(mElementType!="") {
994 Token etype;
995 etype.SetEmpty("ElementType");
996 etype.InsAttributeString("value", mElementType);
997 rTw << etype;
998 }
999}
1000
1001
1002// access prototype
1004 return(mpType);
1005}
1006
1007// set prototype
1009 if(mpType) delete mpType;
1010 mpType = pType;
1011 // test factory method
1012#ifdef FAUDES_CHECKED
1013 if(mpType!=0) {
1014 Type* nobj = mpType->New();
1015 if(typeid(*nobj) != typeid(*mpType)) {
1016 FD_WARN("TypeDefinition::Prototype(): factory method not implemented for c++-type " << typeid(*pType).name());
1017 }
1018 delete nobj;
1019 }
1020#endif
1021}
1022
1023// construct new object with faudes type
1025 FD_DRTI("TypeDefinition::NewObject()");
1026 // bail out
1027 if(!mpType) return NULL;
1028 // use prototype
1029 return mpType->New();
1030}
1031
1032
1033// parameter access
1034const std::string& TypeDefinition::ElementTag(void) const {
1035 return mElementTag;
1036}
1037
1038// parameter access
1039void TypeDefinition::ElementTag(const std::string& rTag) {
1040 mElementTag=rTag;
1041}
1042
1043// parameter access
1044const std::string& TypeDefinition::ElementType(void) const {
1045 return mElementType;
1046}
1047
1048// parameter access
1049void TypeDefinition::ElementType(const std::string& rType) {
1050 mElementType=rType;
1051}
1052
1053
1054
1055} //namspace
1056
#define FD_DC(message)
#define FD_DRTI(message)
#define FD_WARN(message)
#define FAUDES_OBJCOUNT_DEC(type)
#define FAUDES_OBJCOUNT_INC(type)
#define FAUDES_TYPE_IMPLEMENTATION(ftype, ctype, cbase)
Definition cfl_types.h:958
#define FAUDES_TYPE_IMPLEMENTATION_EQUAL(ftype, ctype, cbase)
Definition cfl_types.h:916
#define FAUDES_TYPE_IMPLEMENTATION_COPY(ftype, ctype, cbase)
Definition cfl_types.h:903
#define FAUDES_TYPE_IMPLEMENTATION_CAST(ftype, ctype, cbase)
Definition cfl_types.h:905
#define FAUDES_TYPE_IMPLEMENTATION_ASSIGN(ftype, ctype, cbase)
Definition cfl_types.h:908
#define FAUDES_TYPE_IMPLEMENTATION_NEW(ftype, ctype, cbase)
Definition cfl_types.h:901
static void Skip(TokenReader &rTr)
virtual ~AttrType(void)
int KeywordsSize(void) const
virtual void DoWriteCore(TokenWriter &rTw) const
bool DoEqual(const Documentation &rOther) const
std::string mKeywords
Definition cfl_types.h:1568
void AddKeyword(const std::string &rKeyword)
virtual void MergeDocumentation(TokenReader &rTr)
const std::string & HtmlDoc(void) const
const std::string & Name(void) const
std::string KeywordAt(int pos) const
const std::string & Keywords(void) const
static const char mDelim
Definition cfl_types.h:1571
bool ApplicationRegistered(void) const
const std::string & PlugIn(void) const
std::string MatchKeyword(const std::string &rPattern) const
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
const std::string & TextDoc(void) const
const std::string & CType(void) const
bool AutoRegistered(void) const
void DoAssign(const Documentation &rSrc)
virtual void DoReadCore(TokenReader &rTr)
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
std::string mElementTagDef
Definition cfl_types.h:1228
std::string mObjectName
Definition cfl_types.h:1231
std::string mElementType
Definition cfl_types.h:1225
std::string mElementTag
Definition cfl_types.h:1220
virtual const std::string & ElementType(void) const
std::string mFaudesTypeName
Definition cfl_types.h:1217
virtual const std::string & ElementTag(void) const
const std::string & Name(void) const
virtual ~ExtType(void)
virtual const std::string & TypeName(void) const
const TypeDefinition * pTypeDefinition
Definition cfl_types.h:1214
virtual const TypeDefinition * TypeDefinitionp(void) const
void ReadText(const std::string &rLabel, std::string &rText)
std::string ReadOption(void)
bool Eos(const std::string &rLabel)
void SeekBegin(const std::string &rLabel)
void ReadEnd(const std::string &rLabel)
std::string ReadString(void)
void ReadBegin(const std::string &rLabel)
bool Get(Token &token)
bool Peek(Token &token)
std::string FileName(void) const
std::string FileName(void) const
std::string Str(void)
void WriteText(const std::string &rText)
void WriteComment(const std::string &rComment)
void WriteString(const std::string &rString)
void WriteEnd(const std::string &rLabel)
void WriteBegin(const std::string &rLabel)
const std::string & StringValue(void) const
Int AttributeIntegerValue(const std::string &name)
@ Integer
1234 (non-negative integer)
Definition cfl_token.h:88
@ End
<\label> (end of section)
Definition cfl_token.h:85
@ Begin
<label> (begin of section)
Definition cfl_token.h:84
@ String
any string, space separated or quoted, must start with a letter
Definition cfl_token.h:86
bool IsString(void) const
void InsAttributeBoolean(const std::string &name, Int value)
bool ExistsAttributeString(const std::string &name)
bool IsBegin(void) const
void SetEmpty(const std::string &rName)
void InsAttribute(const std::string &name, const std::string &value)
void SetBegin(const std::string &rName)
Definition cfl_token.cpp:92
bool ExistsAttributeInteger(const std::string &name)
void InsAttributeString(const std::string &name, const std::string &value)
bool IsOption(void) const
const std::string & AttributeStringValue(const std::string &name)
TokenType Type(void) const
std::string mElementTag
Definition cfl_types.h:1859
bool DoEqual(const TypeDefinition &rOther) const
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
virtual void DoReadCore(TokenReader &rTr)
const std::string & ElementTag(void) const
const std::string & ElementType(void) const
virtual void DoWriteCore(TokenWriter &rTw) const
void DoAssign(const TypeDefinition &rSrc)
std::string mElementType
Definition cfl_types.h:1856
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
const Type * Prototype(void) const
Type * NewObject(void) const
static TypeRegistry * G()
const TypeDefinition * Definitionp(const std::string &rTypeName) const
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
virtual const TypeDefinition * TypeDefinitionp(void) const
bool DoEqual(const Type &rOther) const
bool operator==(const Type &rOther) const
Definition cfl_types.cpp:94
void DWrite(const Type *pContext=0) const
virtual Token XBeginTag(const std::string &rLabel="", const std::string &rFallbackLabel="") const
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
virtual const std::string & Name(void) const
Type & operator=(const Type &rSrc)
std::string ToSText(void) const
static std::string msStringEmpty
Definition cfl_types.h:872
std::string ToString(const std::string &rLabel="", const Type *pContext=0) const
void FromString(const std::string &rString, const std::string &rLabel="", const Type *pContext=0)
virtual void XWrite(const std::string &pFileName, const std::string &rLabel="", const Type *pContext=0) const
virtual ~Type(void)
Definition cfl_types.cpp:51
virtual void Clear(void)
Definition cfl_types.cpp:72
virtual Type & Assign(const Type &rSrc)
Definition cfl_types.cpp:82
virtual Type * New(void) const
Definition cfl_types.cpp:54
virtual void DoSWrite(TokenWriter &rTw) const
void SWrite(void) const
virtual void DoXWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
virtual Type * Copy(void) const
Definition cfl_types.cpp:60
virtual bool IsDefault(void) const
Definition cfl_types.cpp:77
std::string ToText(const std::string &rLabel="", const Type *pContext=0) const
static std::string msStringVoid
Definition cfl_types.h:871
void Write(const Type *pContext=0) const
virtual void DoDWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
bool operator!=(const Type &rOther) const
Definition cfl_types.cpp:99
void DoAssign(const Type &rSrc)
virtual const std::string & TypeName(void) const
virtual bool Equal(const Type &rOther) const
Definition cfl_types.cpp:89
virtual const Type * Cast(const Type *pOther) const
Definition cfl_types.cpp:66

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