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

libFAUDES 2.34d --- 2026.03.11 --- c++ api documentaion by doxygen