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 //rTw.WriteComment("serialisation not implemented for this type");
312 //FD_WARN("Type::DoWrite(): not re-implemented in " << typeid(*this).name());
313}
314
315//DoXWrite(rTr,rLabel,pContext)
316void Type::DoXWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
317 DoWrite(rTw, rLabel, pContext);
318}
319
320//DoDWrite(rTr,rLabel,pContext)
321void Type::DoDWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
322 FD_DC("Type::DoDWrite(): not re-implemented in " << typeid(*this).name() << ", using DoDWrite instead");
323 DoWrite(rTw,rLabel,pContext);
324}
325
326//DoSWrite(rTr,rLabel,pContext)
327void Type::DoSWrite(TokenWriter& rTw) const {
328 FD_DC("Type::DoSWrite(): not re-implemented in " << typeid(*this).name());
329 rTw.WriteComment("");
330 rTw.WriteComment(" Statistics not available " + Name());
331 rTw.WriteComment("");
332}
333
334//DoRead(rTr,rLabel,pContext)
335void Type::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
336 (void) rLabel; (void) pContext; (void) rTr;
337 FD_DC("Type::DoRead(): not re-implemented in " << typeid(*this).name());
338}
339
340
341
342// configure begin token
343Token Type::XBeginTag(const std::string& rLabel,const std::string& rFallbackLabel) const {
344 // provided
345 std::string label=rLabel;
346 std::string ftype=TypeName();
347 // fallback label
348 if(label=="") label=ftype;
349 if(label=="") label=rFallbackLabel;
350 Token btag;
351 btag.SetBegin(label);
352 if(Name()!=label && Name()!="") btag.InsAttributeString("name",Name());
353 if(ftype!=label && ftype!="") btag.InsAttributeString("ftype",ftype);
354 // done
355 return btag;
356}
357
358
359
360/*
361********************************************************************
362********************************************************************
363********************************************************************
364
365Implementation of class AttrType
366
367********************************************************************
368********************************************************************
369********************************************************************
370*/
371
372// faudes type
374
375// constructor
377 FAUDES_OBJCOUNT_INC("AttrType");
378}
379
380// constructor
381AttrType::AttrType(const AttrType& rOther) : Type(rOther) {
382 FAUDES_OBJCOUNT_INC("AttrType");
384
385// destructor
387 FAUDES_OBJCOUNT_DEC("AttrType");
388}
389
390//Skip(rTr)
392 FD_DC("AttrType::Skip()");
393 Token token;
394 while(rTr.Peek(token)) {
395 // break on index or name, since this is the next element
396 if((token.Type()==Token::String) || (token.Type()==Token::Integer)) {
397 break;
398 }
399 // break on end, since this is the end of the container
400 if(token.Type()==Token::End) {
401 break;
402 }
403 // break on Consecutive section, since this belongs to the container
404 if((token.Type()==Token::Begin) && (token.StringValue() == "Consecutive")) {
405 break;
406 }
407 // skip any attribute section from other file format
408 if(token.Type()==Token::Begin){
409 rTr.ReadBegin(token.StringValue());
410 rTr.ReadEnd(token.StringValue());
411 continue;
412 }
413 // skip any other token from other file format
414 rTr.Get(token);
415 }
416}
417
418//Skip(rTr)
419std::string AttrType::Str(void) const {
420 return std::string();
421}
422
423
424/*
425********************************************************************
426********************************************************************
427********************************************************************
428
429Implementation of class ExtType
430
431********************************************************************
432********************************************************************
433********************************************************************
435
436// std faudes type methods
438
439// constructor
440ExtType::ExtType(void) : AttrType(), pTypeDefinition(nullptr) {}
441
442// copy constructor
443ExtType::ExtType(const ExtType& rType) : AttrType(), pTypeDefinition(nullptr) {(void) rType;}
444
445// destructor
447
448// Name
449const std::string& ExtType::Name(void) const {
450 return mObjectName;
451}
452
453// Name
454void ExtType::Name(const std::string& rName) {
455 mObjectName = rName;
456}
457
458// TypeDefinitionp()
459// Note: fake const construct
461 if(!pTypeDefinition) {
462 // provide fake const
463 ExtType* fake_const = const_cast< ExtType* >(this);
464 fake_const->pTypeDefinition=TypeRegistry::G()->Definitionp(*this);
465 }
466 return pTypeDefinition;
467}
468
469// Faudes Type
470const std::string& ExtType::TypeName(void) const {
471 if(mFaudesTypeName.empty()) {
472 // provide fake const
473 ExtType* fake_const = const_cast< ExtType* >(this);
474 const TypeDefinition* fdp=TypeDefinitionp();
475 if(fdp) fake_const->mFaudesTypeName=fdp->Name();
476 }
477 return mFaudesTypeName;
478}
479
480// Faudes Type
481void ExtType::TypeName(const std::string& rType) {
482 mFaudesTypeName=rType;
483}
484
485// ElementTag
486const std::string& ExtType::ElementTag(void) const {
487 FD_DRTI("ExtType::ElementTag(" << typeid(*this).name() <<")");
488 if(mElementTag.empty()) {
489 // provide fake const
490 ExtType* fake_const = const_cast< ExtType* >(this);
491 fake_const->mElementTag=mElementTagDef;
492 const TypeDefinition* fdp=TypeDefinitionp();
493 if(fdp) {
494 FD_DRTI("Type::ElementTag: type " << fdp->TypeName() << "etag " << fdp->ElementTag());
495 if(!fdp->ElementTag().empty()) fake_const->mElementTag=fdp->ElementTag();
496 }
497 }
498 FD_DRTI("Type::ElementTag(" << typeid(*this).name() <<"): using tag: " << mElementTag);
499 return mElementTag;
500}
501
502// ElementTag
503void ExtType::ElementTag(const std::string& rTag) {
504 mElementTag=rTag;
505}
506
507
508// figure element type
509const std::string& ExtType::ElementType(void) const {
510 FD_DRTI("ExtType::ElementType(" << typeid(*this).name() <<")");
511 if(mElementType.empty()) {
512 // provide fake const
513 ExtType* fake_const = const_cast< ExtType* >(this);
514 const TypeDefinition* fdp=TypeDefinitionp();
515 if(fdp) {
516 FD_DRTI("Type::ElementType: type " << fdp->TypeName() << "etype " << fdp->ElementType());
517 if(!fdp->ElementType().empty()) fake_const->mElementType=fdp->ElementType();
518 }
519 }
520 FD_DRTI("Type::ElementType(" << typeid(*this).name() <<"): using tag: " << mElementType);
521 return mElementType;
522}
523
524
525//DoSWrite(rTr,rLabel,pContext)
527 FD_DC("ExtType::DoSWrite(): not re-implemented in " << typeid(*this).name());
528 rTw.WriteComment("");
529 rTw.WriteComment(" Statistics for " + Name());
530 rTw.WriteComment("");
531}
532
533
534
535/*
536********************************************************************
537********************************************************************
538********************************************************************
539
540Implementation of class Documentation
541
542********************************************************************
543********************************************************************
544********************************************************************
545*/
546
547// faudes type (cannot do autoregister)
554
555// construct
557 mAutoRegistered=true;
558 mApplicationRegistered=false;
559}
560
561// construct
563 DoCopy(rOther);
564}
565
566// std faudes type
568 // call base (inkl virt Clear())
569 Type::DoCopy(rSrc);
570 // assign my members
571 mName=rSrc.mName;
572 mPlugIn=rSrc.mPlugIn;
573 mHtmlDoc=rSrc.mHtmlDoc;
574 mTextDoc=rSrc.mTextDoc;
575 mKeywords=rSrc.mKeywords;
576}
577
578// std faudes type
579bool Documentation::DoEqual(const Documentation& rOther) const {
580 // test my members
581 if(mName!=rOther.mName) return false;
582 if(mPlugIn!=rOther.mPlugIn) return false;
583 if(mHtmlDoc!=rOther.mHtmlDoc) return false;
584 if(mTextDoc!=rOther.mTextDoc) return false;
585 if(mKeywords!=rOther.mKeywords) return false;
586 return true;
587}
588
589// clear all
591 FD_DRTI("Documentation::Clear()");
592 mName="";
593 mPlugIn="CoreFaudes";
594 mHtmlDoc="";
595 mTextDoc="";
596 mKeywords="";
597 mAutoRegistered=true;
599}
600
601// read access members
602const std::string& Documentation::Name(void) const{ return mName; }
603const std::string& Documentation::PlugIn(void) const{ return mPlugIn; }
604const std::string& Documentation::CType(void) const{ return mCType; }
605const std::string& Documentation::TextDoc() const{ return mTextDoc; }
606const std::string& Documentation::HtmlDoc() const{ return mHtmlDoc; }
607const std::string& Documentation::Keywords() const{ return mKeywords; }
610
611// write access members
612void Documentation::Name(const std::string& name){mName = name; }
613void Documentation::PlugIn(const std::string& plugin){mPlugIn = plugin; }
614void Documentation::CType(const std::string& name){mCType = name; }
615void Documentation::TextDoc(const std::string& textdoc){mTextDoc = textdoc;}
616void Documentation::HtmlDoc(const std::string& fname){mHtmlDoc = fname;}
619
620// write access keyword
621void Documentation::AddKeyword(const std::string& rKeyword){
622 if(mKeywords.empty()){
623 mKeywords = rKeyword;
624 } else{
625 mKeywords.append(1, mDelim);
626 mKeywords.append(rKeyword);
627 }
628}
629
630// regex match keywords (todo)
631std::string Documentation::MatchKeyword(const std::string& rPattern) const{
632 FD_DRTI("Documentation::MatchKeyword(" << rPattern << ")");
633 // be case insensitive (inefficient)
634 std::string keys = mKeywords;
635 std::transform(keys.begin(), keys.end(), keys.begin(), tolower);
636 std::string match = rPattern;
637 std::transform(match.begin(), match.end(), match.begin(), tolower);
638 // find match
639 std::string res="";
640 std::size_t posk=keys.find(match);
641 if(posk==std::string::npos) return res;
642 // find delimiters
643 std::size_t posa=0;
644 std::size_t posb=keys.length();
645 while(true) {
646 posb=keys.find(mDelim,posa);
647 if(posb==std::string::npos) posb=mKeywords.length();
648 if(posb>posk) break;
649 posa=posb+1;
650 };
651 // return original case match
652 FD_DRTI("Documentation::MatchKeyword(" << rPattern << "): " << mKeywords.substr(posa,posb-posa));
653 return mKeywords.substr(posa,posb-posa);
654}
655
656
657// positional keyword
658std::string Documentation::KeywordAt(int pos) const{
659 FD_DRTI("Documentation::KeywordAt(" << pos << ")");
660 // default result
661 std::string res="";
662 // find delimiter
663 std::size_t posa=0;
664 std::size_t posb=mKeywords.length();
665 while(pos>0) {
666 if(posa>=mKeywords.length()) return res;
667 posb=mKeywords.find(mDelim,posa);
668 if(posb==std::string::npos) return res;
669 posa=posb+1;
670 pos--;
671 };
672 // default result
673 res=mKeywords.substr(posa);
674 // find next delimiter
675 posb=res.find(mDelim);
676 if(posb==std::string::npos) return res;
677 res=res.substr(0,posb);
678 return res;
679}
680
681// keyword
683 int cnt=0;
684 // find delimiter
685 std::size_t pos=0;
686 while(pos<mKeywords.length()) {
687 cnt++;
688 pos=mKeywords.find(mDelim,pos);
689 if(pos==std::string::npos) break;
690 pos++;
691 };
692 return cnt;
693}
694
695
696// merge with docu from token io
698 FD_DRTI("Documentation::MergeDocumentation(): for " << mName);
699 // get first token to test type definition
700 Token token;
701 rTr.Peek(token);
702 if(!token.IsBegin()) return;
703 std::string label=token.StringValue();
704 // get ftype and test for match
705 std::string ftype=token.AttributeStringValue("name");
706 size_t pos=ftype.find("::");
707 if(pos!=std::string::npos) ftype=ftype.substr(pos+2);
708 // match?
709 if( (mName!=ftype && mName!="") || (ftype=="")) {
710 std::stringstream errstr;
711 errstr << "Documentation mismatch in file \"" << rTr.FileName() << "\" : " << mName << "!=" << ftype;
712 throw Exception("Documentation::MergeDocumentation", errstr.str(), 48);
713 };
714 // do read
715 DoRead(rTr,label);
716}
717
718// token io
719void Documentation::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
720 FD_DRTI("Documentation::DoRead(): file " << rTr.FileName());
721 // ignore
722 (void) pContext;
723 // figure my section
724 std::string label = rLabel;
725 if(label=="") label="Documentation";
726 // get first token for ftype and ctype
727 Token token;
728 rTr.ReadBegin(label,token);
729
730 // sense and digest pre 2.16b format
731 if(!token.ExistsAttributeString("name")) {
732 Token ptoken;
733 rTr.Peek(ptoken);
734 mName=ptoken.StringValue();
735 size_t pos=mName.find("::");
736 if(pos!=std::string::npos) mName=mName.substr(pos+2);
737 mPlugIn=ptoken.StringValue();
738 pos=mPlugIn.find("::");
739 if(pos!=std::string::npos) mPlugIn=mPlugIn.substr(0,pos);
740 else mPlugIn = "CoreFaudes";
741 DoReadCore(rTr);
742 rTr.ReadEnd(label);
743 return;
744 } // end pre 2.16b format
745
746 // get ftype
747 mName=token.AttributeStringValue("name");
748 size_t pos=mName.find("::");
749 if(pos!=std::string::npos) mName=mName.substr(pos+2);
750 // get plugin
751 mPlugIn=token.AttributeStringValue("name");
752 pos=mPlugIn.find("::");
753 if(pos!=std::string::npos) mPlugIn=mPlugIn.substr(0,pos);
754 else mPlugIn = "CoreFaudes";
755 // get ctype
756 mCType=token.AttributeStringValue("ctype");
757
758 // get autoreg flag (note: let flag survive if originally set and no attribute)
759 if(token.ExistsAttributeInteger("autoregister"))
760 mAutoRegistered = (token.AttributeIntegerValue("autoregister"));
761 // report
762 FD_DRTI("Documentation::DoRead(): found " << mName << " " << mCType);
763 // do read
764 DoReadCore(rTr);
765 // done
766 rTr.ReadEnd(label);
767}
768
769// token read
771 FD_DRTI("Documentation::DoReadCore()");
772 Token token;
773 mTextDoc="";
774 mHtmlDoc="";
775 mKeywords="";
776
777 // sense and digest pre 2.16 format
778 rTr.Peek(token);
779 if(token.IsString()) {
780 mName=token.StringValue();
781 size_t pos=mName.find("::");
782 if(pos!=std::string::npos) mName=mName.substr(pos+2);
783 mPlugIn=token.StringValue();
784 pos=mPlugIn.find("::");
785 if(pos!=std::string::npos) mPlugIn=mPlugIn.substr(0,pos);
786 else mPlugIn = "CoreFaudes";
787 rTr.ReadString();
788 mCType="";
789 rTr.Peek(token);
790 if(token.IsOption())
791 mCType = rTr.ReadOption();
792 while(true) {
793 rTr.Peek(token);
794 if(token.IsBegin())
795 if(token.StringValue()=="TextDoc") {
796 rTr.ReadBegin("TextDoc");
797 mTextDoc = rTr.ReadString();
798 rTr.ReadEnd("TextDoc");
799 continue;
800 }
801 if(token.IsBegin())
802 if(token.StringValue()=="HtmlDoc") {
803 rTr.ReadBegin("HtmlDoc");
804 mHtmlDoc = rTr.ReadString();
805 rTr.ReadEnd("HtmlDoc");
806 continue;
807 }
808 if(token.IsBegin())
809 if(token.StringValue()=="Keywords") {
810 rTr.ReadBegin("Keywords");
811 while(!rTr.Eos("Keywords"))
812 AddKeyword(rTr.ReadString());
813 rTr.ReadEnd("Keywords");
814 continue;
815 }
816 break;
817 }
818 return;
819 } // end pre 2.16 format
820
821 // loop other known entries
822 while(true) {
823 rTr.Peek(token);
824 // do the read: docu
825 if(token.IsBegin())
826 if(token.StringValue()=="Documentation") {
827 if(token.ExistsAttributeString("ref"))
828 mHtmlDoc=token.AttributeStringValue("ref");
829 rTr.ReadText("Documentation",mTextDoc);
830 continue;
831 }
832 // do the read: keys
833 if(token.IsBegin())
834 if(token.StringValue()=="Keywords") {
835 rTr.ReadBegin("Keywords");
836 while(!rTr.Eos("Keywords"))
837 AddKeyword(rTr.ReadString());
838 rTr.ReadEnd("Keywords");
839 continue;
840 }
841 // unknown -> derived class take over
842 break;
843 }
844}
845
846
847// token write
848void Documentation::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
849 // ignore
850 (void) pContext;
851 // figure my section
852 std::string label = rLabel;
853 if(label=="") label="Documentation";
854 // begin tag
855 Token btag;
856 btag.SetBegin(label);
857 if(mPlugIn!="" && mName!="")
858 btag.InsAttribute("name",mPlugIn+"::"+mName);
859 if(mPlugIn=="" && mName!="")
860 btag.InsAttribute("name",mName);
861 if(mCType!="")
862 btag.InsAttribute("ctype",mCType);
863 if(!mAutoRegistered)
864 btag.InsAttributeBoolean("autoregister",false);
865 rTw << btag;
866 // data
867 DoWriteCore(rTw);
868 // end tag
869 rTw.WriteEnd(label);
870}
871
872// token write
874 // write text doc
875 if(mTextDoc!="" || mHtmlDoc!="") {
876 Token btag;
877 btag.SetBegin("Documentation");
878 if(mHtmlDoc!="")
879 btag.InsAttributeString("ref",mHtmlDoc);
880 rTw.WriteText(btag,mTextDoc);
881 }
882 // write keys
883 int ksz=KeywordsSize();
884 if(ksz>0) {
885 rTw.WriteBegin("Keywords");
886 for(int i=0; i<ksz; i++)
887 rTw.WriteString(KeywordAt(i));
888 rTw.WriteEnd("Keywords");
889 }
890}
891
892
893
894/*
895********************************************************************
896********************************************************************
897********************************************************************
898
899Implementation of class TypeDefinition
900
901********************************************************************
902********************************************************************
903********************************************************************
904*/
905
906
907// faudes type (cannot do autoregister)
914
915
916// Typedefinition constructor function
917TypeDefinition* TypeDefinition::Constructor(Type* pProto, const std::string& rTypeName){
918 FD_DRTI("TypeDefinition::Construct(" << typeid(*pProto).name() << ", " << rTypeName << ")");
919 TypeDefinition* td = new TypeDefinition();
920 td->Prototype(pProto);
921 std::string name=rTypeName;
922 if(name=="") name=typeid(*pProto).name();
923 td->Name(name);
924 return(td);
925}
926
927
928// clear (all except prototype)
930 FD_DRTI("TypeDefinition::Clear()");
931 // call base
933 // my members
934 mElementTag="";
935 mElementType="";
936}
937
938
939// std faudes type
941 // assign base members
943 // assign my members
946 // special member
947 if(mpType) delete mpType;
948 mpType=0;
949 if(rSrc.mpType)
950 mpType=rSrc.mpType->New();
951}
952
953// std faudes type
954bool TypeDefinition::DoEqual(const TypeDefinition& rOther) const {
955 // test base members
956 if(!Documentation::DoEqual(rOther)) return false;
957 // test my members
958 if(mElementTag!=rOther.mElementTag) return false;
959 if(mElementType!=rOther.mElementType) return false;
960 return true;
961}
962
963
964// token io
965void TypeDefinition::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
966 FD_DRTI("TypeDefinition::DoRead(): file " << rTr.FileName());
967 // ignore
968 (void) pContext;
969 // figure my section
970 std::string label = rLabel;
971 if(label=="") label="TypeDefinition";
972 // base can handle this
973 Documentation::DoRead(rTr,label,pContext);
974 // my members
975}
976
977// token io
979 FD_DRTI("TypeDefinition::DoReadCore(): file " << rTr.FileName());
980 // call base core
982 // my data
983 while(true) {
984 Token token;
985 rTr.Peek(token);
986 // element tag
987 if(token.IsBegin())
988 if(token.StringValue()=="ElementTag") {
989 rTr.ReadBegin("ElementTag",token);
990 if(token.ExistsAttributeString("value"))
991 mElementTag=token.AttributeStringValue("value");
992 rTr.ReadEnd("ElementTag");
993 continue;
994 }
995 // element type
996 if(token.IsBegin())
997 if(token.StringValue()=="ElementType") {
998 rTr.ReadBegin("ElementType",token);
999 if(token.ExistsAttributeString("value"))
1000 mElementType=token.AttributeStringValue("value");
1001 rTr.ReadEnd("ElementType");
1002 continue;
1003 }
1004 // break un unknown
1005 break;
1006 }
1007}
1008
1009// token io
1010void TypeDefinition::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
1011 // label
1012 std::string label=rLabel;
1013 if(label=="") label="TypeDefinition";
1014 // base can handle
1015 Documentation::DoWrite(rTw,label,pContext);
1016}
1017
1018// token io
1020 FD_DRTI("TypeDefinition::DoWriteCore(): file " << rTw.FileName());
1021 // call base core
1023 // my data
1024 if(mElementTag!="") {
1025 Token etag;
1026 etag.SetEmpty("ElementTag");
1027 etag.InsAttributeString("value", mElementTag);
1028 rTw << etag;
1029 }
1030 // my data
1031 if(mElementType!="") {
1032 Token etype;
1033 etype.SetEmpty("ElementType");
1034 etype.InsAttributeString("value", mElementType);
1035 rTw << etype;
1036 }
1037}
1038
1039
1040// access prototype
1042 return(mpType);
1043}
1044
1045// set prototype
1047 if(mpType) delete mpType;
1048 mpType = pType;
1049 // test factory method
1050#ifdef FAUDES_CHECKED
1051 if(mpType!=0) {
1052 Type* nobj = mpType->New();
1053 if(typeid(*nobj) != typeid(*mpType)) {
1054 FD_WARN("TypeDefinition::Prototype(): factory method not implemented for c++-type " << typeid(*pType).name());
1055 }
1056 delete nobj;
1057 }
1058#endif
1059}
1060
1061// construct new object with faudes type
1063 FD_DRTI("TypeDefinition::NewObject()");
1064 FD_WARN("TypeDefinition::NewObject(): type name " << Name() << " prototype " << mpType);
1065 // bail out
1066 if(!mpType) return NULL;
1067 // use prototype
1068 return mpType->New();
1069}
1070
1071
1072// parameter access
1073const std::string& TypeDefinition::ElementTag(void) const {
1074 return mElementTag;
1075}
1076
1077// parameter access
1078void TypeDefinition::ElementTag(const std::string& rTag) {
1079 mElementTag=rTag;
1080}
1081
1082// parameter access
1083const std::string& TypeDefinition::ElementType(void) const {
1084 return mElementType;
1085}
1086
1087// parameter access
1088void TypeDefinition::ElementType(const std::string& rType) {
1089 mElementType=rType;
1090}
1091
1092
1093
1094} //namspace
1095
#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)
virtual std::string Str(void) const
int KeywordsSize(void) const
virtual void DoWriteCore(TokenWriter &rTw) const
bool DoEqual(const Documentation &rOther) const
std::string mKeywords
Definition cfl_types.h:1662
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:1665
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:1322
std::string mObjectName
Definition cfl_types.h:1325
std::string mElementType
Definition cfl_types.h:1319
std::string mElementTag
Definition cfl_types.h:1301
virtual const std::string & ElementType(void) const
std::string mFaudesTypeName
Definition cfl_types.h:1298
virtual void DoSWrite(TokenWriter &rTw) const
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:1295
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:1953
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:1950
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.34g --- 2026.04.09 --- c++ api documentaion by doxygen