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 
5 Copyright (C) 2009 Ruediger Berndt
6 Copyright (C) 2010 Thomas Moor
7 
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12 
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
21 
22 
23 #include "cfl_types.h"
24 #include "cfl_registry.h"
25 
26 namespace faudes{
27 
28 /*
29 ********************************************************************
30 ********************************************************************
31 ********************************************************************
32 
33 implemantation of faudes Type
34 
35 ********************************************************************
36 ********************************************************************
37 ********************************************************************
38 */
39 
40 // statics
41 std::string Type::msStringVoid("Void");
42 std::string Type::msStringEmpty("");
43 
44 // constructor
45 Type::Type(void) {}
46 
47 // copy constructor
48 Type::Type(const Type& rType) {(void) rType;}
49 
50 // destructor
51 Type::~Type(void) {}
52 
53 // pointer constructor
54 Type* 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
60 Type* 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
66 const 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()
72 void Type::Clear(void) {
73  FD_DC("Type::Clear(): not re-implemented in " << typeid(*this).name());
74 }
75 
76 // assign
77 Type& Type::Assign(const Type& rSource) {
78  FD_DC("Type(" << this << ")::Assign(" << &rSource << ")");
79  Clear();
80  return *this;
81 }
82 
83 // equality (relaxed)
84 bool Type::Equal(const Type& rOther) const {
85  return true;
86 }
87 
88 // equality (strict)
89 bool Type::operator==(const Type& rOther) const {
90  return typeid(*this)==typeid(rOther);
91 }
92 
93 // equality
94 bool Type::operator!=(const Type& rOther) const {
95  return ! operator==(rOther);
96 }
97 
98 // assign
99 Type& Type::operator=(const Type& rSource) {
100  FD_DC("Type(" << this << ")::AssignementOperator(" << &rSource << ")");
101  Clear();
102  return *this;
103 }
104 
105 // assign
106 void Type::DoAssign(const Type& rSource) {
107  FD_DC("Type(" << this << ")::DoAssign(" << &rSource << ")");
108 }
109 
110 // equality
111 bool Type::DoEqual(const Type& rOther) const {
112  FD_WARN("Type(" << this << ")::DoEqual(" << &rOther << ")");
113  return true;
114 }
115 
116 // Name(rName)
117 void Type::Name(const std::string& rName) {
118  (void) rName;
119 }
120 
121 // Name()
122 const std::string& Type::Name(void) const {
123  return msStringEmpty;
124 }
125 
126 // TypeDefinitionp()
128  return TypeRegistry::G()->Definitionp(*this);
129 }
130 
131 // TypeName()
132 const std::string& Type::TypeName(void) const {
133  const TypeDefinition* fdp=TypeDefinitionp();
134  if(!fdp) return msStringEmpty;
135  return fdp->Name();
136 }
137 
138 // Write(context)
139 void Type::Write(const Type* pContext) const {
141  DoWrite(tw,"",pContext);
142 }
143 
144 // Write(rFileName, label, context, openmode)
145 void Type::Write(const std::string& rFileName, const std::string& rLabel,
146  const Type* pContext, std::ios::openmode openmode) const {
147  try {
148  TokenWriter tw(rFileName, openmode);
149  DoWrite(tw, rLabel, pContext);
150  }
151  catch(std::ios::failure&) {
152  std::stringstream errstr;
153  errstr << "Exception opening/writing file \"" << rFileName << "\"";
154  throw Exception("Type::Write", errstr.str(), 2);
155  }
156 }
157 
158 // Write(rFileName, openmode)
159 void Type::Write(const std::string& rFileName, std::ios::openmode openmode) const {
160  Write(rFileName,"",0,openmode);
161 }
162 
163 // Write(tw,label,context)
164 void Type::Write(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
165  DoWrite(rTw,rLabel,pContext);
166 }
167 
168 // ToString(label, context)
169 std::string Type::ToString(const std::string& rLabel, const Type* pContext) const {
171  tw.Endl(false);
172  DoWrite(tw,rLabel,pContext);
173  return tw.Str();
174 }
175 
176 // ToSText()
177 std::string Type::ToSText(void) const {
179  tw.Endl(true);
180  DoSWrite(tw);
181  return tw.Str();
182 }
183 
184 // ToString(label, context)
185 std::string Type::ToText(const std::string& rLabel, const Type* pContext) const {
187  tw.Endl(true);
188  DoWrite(tw,rLabel,pContext);
189  return tw.Str();
190 }
191 
192 // XWrite(context)
193 void Type::XWrite(const Type* pContext) const {
194  FD_DC("Type(" << this << ")::XWrite(): for " << typeid(*this).name());
196  DoXWrite(tw,"",pContext);
197 }
198 
199 // XWrite(rFileName, label, context)
200 void Type::XWrite(const std::string& rFileName, const std::string& rLabel, const Type* pContext) const {
201  std::string ftype=TypeName();
202  if(ftype=="") {
203  std::stringstream errstr;
204  errstr << "Cannot write unregistered faudes-type object \"" << typeid(*this).name() << "\"";
205  throw Exception("Type::XWrite", errstr.str(), 2);
206  }
207  try {
208  TokenWriter tw(rFileName,ftype);
209  XWrite(tw, rLabel, pContext);
210  }
211  catch(std::ios::failure&) {
212  std::stringstream errstr;
213  errstr << "Exception opening/writing file \"" << rFileName << "\"";
214  throw Exception("Type::XWrite", errstr.str(), 2);
215  }
216 }
217 
218 // XWrite(tw,label,context)
219 void Type::XWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
220  FD_DC("Type(" << this << ")::XWrrite(): for " << typeid(*this).name());
221  DoXWrite(rTw,rLabel,pContext);
222 }
223 
224 // DWrite(context)
225 void Type::DWrite(const Type* pContext) const {
227  DoDWrite(tw,"",pContext);
228 }
229 
230 // DWrite(rFileName, label, context, openmode)
231 void Type::DWrite(const std::string& rFileName, const std::string& rLabel,
232  const Type* pContext, std::ios::openmode openmode) const {
233  try {
234  TokenWriter tw(rFileName, openmode);
235  DoDWrite(tw, rLabel, pContext);
236  }
237  catch(std::ios::failure&) {
238  std::stringstream errstr;
239  errstr << "Exception opening/writing file \"" << rFileName << "\"";
240  throw Exception("Type::DWrite", errstr.str(), 2);
241  }
242 }
243 
244 // DWrite(tw,label,context)
245 void Type::DWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
246  DoDWrite(rTw,rLabel,pContext);
247 }
248 
249 // SWrite()
250 void Type::SWrite(void) const {
252  DoSWrite(tw);
253 }
254 
255 // SWrite(tw)
256 void Type::SWrite(TokenWriter& rTw) const {
257  DoSWrite(rTw);
258 }
259 
260 // Read(rFilename, rLabel,context)
261 void Type::Read(const std::string& rFilename, const std::string& rLabel, const Type* pContext) {
262  Clear();
263  TokenReader tr(rFilename);
264  if(rLabel!="") tr.SeekBegin(rLabel);
265  DoRead(tr,rLabel,pContext);
266 }
267 
268 // Read(rTr, rLabel, context)
269 void Type::Read(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
270  Clear();
271  DoRead(rTr,rLabel,pContext);
272 }
273 
274 // FromString(rString, rLabel, context)
275 void Type::FromString(const std::string& rString, const std::string& rLabel, const Type* pContext) {
276  Clear();
277  TokenReader tr(TokenReader::String,rString);
278  DoRead(tr,rLabel,pContext);
279 }
280 
281 //DoWrite(rTr,rLabel,pContext)
282 void Type::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
283  (void) rTw; (void) rLabel; (void) pContext;
284  FD_DC("Type::DoWrite(): not re-implemented in " << typeid(*this).name());
285 }
286 
287 //DoXWrite(rTr,rLabel,pContext)
288 void Type::DoXWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
289  DoWrite(rTw, rLabel, pContext);
290 }
291 
292 //DoDWrite(rTr,rLabel,pContext)
293 void Type::DoDWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
294  FD_DC("Type::DoDWrite(): not re-implemented in " << typeid(*this).name() << ", using DoDWrite instead");
295  DoWrite(rTw,rLabel,pContext);
296 }
297 
298 //DoSWrite(rTr,rLabel,pContext)
299 void Type::DoSWrite(TokenWriter& rTw) const {
300  FD_DC("Type::DoSWrite(): not re-implemented in " << typeid(*this).name());
301  rTw.WriteComment("");
302  rTw.WriteComment(" Statistics for " + Name());
303  rTw.WriteComment("");
304 }
305 
306 //DoRead(rTr,rLabel,pContext)
307 void Type::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
308  (void) rLabel; (void) pContext; (void) rTr;
309  FD_DC("Type::DoRead(): not re-implemented in " << typeid(*this).name());
310 }
311 
312 
313 
314 // configure begin token
315 Token Type::XBeginTag(const std::string& rLabel,const std::string& rFallbackLabel) const {
316  // provided
317  std::string label=rLabel;
318  std::string ftype=TypeName();
319  // fallback label
320  if(label=="") label=ftype;
321  if(label=="") label=rFallbackLabel;
322  Token btag;
323  btag.SetBegin(label);
324  if(Name()!=label && Name()!="") btag.InsAttributeString("name",Name());
325  if(ftype!=label && ftype!="") btag.InsAttributeString("ftype",ftype);
326  // done
327  return btag;
328 }
329 
330 
331 
332 /*
333 ********************************************************************
334 ********************************************************************
335 ********************************************************************
336 
337 Implementation of class Documentation
338 
339 ********************************************************************
340 ********************************************************************
341 ********************************************************************
342 */
343 
344 // faudes type (cannot do autoregister)
350 
351 // construct
353  mAutoRegistered=false;
354  mApplicationRegistered=false;
355 }
356 
357 // construct
359  DoAssign(rOther);
360 }
361 
362 // std faudes type
364  // assign my members
365  mName=rSrc.mName;
366  mPlugIn=rSrc.mPlugIn;
367  mHtmlDoc=rSrc.mHtmlDoc;
368  mTextDoc=rSrc.mTextDoc;
369  mKeywords=rSrc.mKeywords;
370 }
371 
372 // std faudes type
373 bool Documentation::DoEqual(const Documentation& rOther) const {
374  // test my members
375  if(mName!=rOther.mName) return false;
376  if(mPlugIn!=rOther.mPlugIn) return false;
377  if(mHtmlDoc!=rOther.mHtmlDoc) return false;
378  if(mTextDoc!=rOther.mTextDoc) return false;
379  if(mKeywords!=rOther.mKeywords) return false;
380  return true;
381 }
382 
383 // clear all
385  FD_DRTI("Documentation::Clear()");
386  mName="";
387  mPlugIn="CoreFaudes";
388  mHtmlDoc="";
389  mTextDoc="";
390  mKeywords="";
391  mAutoRegistered=false;
393 }
394 
395 // read access members
396 const std::string& Documentation::Name(void) const{ return mName; }
397 const std::string& Documentation::PlugIn(void) const{ return mPlugIn; }
398 const std::string& Documentation::CType(void) const{ return mCType; }
399 const std::string& Documentation::TextDoc() const{ return mTextDoc; }
400 const std::string& Documentation::HtmlDoc() const{ return mHtmlDoc; }
401 const std::string& Documentation::Keywords() const{ return mKeywords; }
404 
405 // write access members
406 void Documentation::Name(const std::string& name){mName = name; }
407 void Documentation::PlugIn(const std::string& plugin){mPlugIn = plugin; }
408 void Documentation::CType(const std::string& name){mCType = name; }
409 void Documentation::TextDoc(const std::string& textdoc){mTextDoc = textdoc;}
410 void Documentation::HtmlDoc(const std::string& fname){mHtmlDoc = fname;}
413 
414 // write access keyword
415 void Documentation::AddKeyword(const std::string& rKeyword){
416  if(mKeywords.empty()){
417  mKeywords = rKeyword;
418  } else{
419  mKeywords.append(1, mDelim);
420  mKeywords.append(rKeyword);
421  }
422 }
423 
424 // regex match keywords (todo)
425 std::string Documentation::MatchKeyword(const std::string& rPattern) const{
426  FD_DRTI("Documentation::MatchKeyword(" << rPattern << ")");
427  // be case insensitive (inefficient)
428  std::string keys = mKeywords;
429  std::transform(keys.begin(), keys.end(), keys.begin(), tolower);
430  std::string match = rPattern;
431  std::transform(match.begin(), match.end(), match.begin(), tolower);
432  // find match
433  std::string res="";
434  std::size_t posk=keys.find(match);
435  if(posk==std::string::npos) return res;
436  // find delimiters
437  std::size_t posa=0;
438  std::size_t posb=keys.length();
439  while(true) {
440  posb=keys.find(mDelim,posa);
441  if(posb==std::string::npos) posb=mKeywords.length();
442  if(posb>posk) break;
443  posa=posb+1;
444  };
445  // return original case match
446  FD_DRTI("Documentation::MatchKeyword(" << rPattern << "): " << mKeywords.substr(posa,posb-posa));
447  return mKeywords.substr(posa,posb-posa);
448 }
449 
450 
451 // positional keyword
452 std::string Documentation::KeywordAt(int pos) const{
453  FD_DRTI("Documentation::KeywordAt(" << pos << ")");
454  // default result
455  std::string res="";
456  // find delimiter
457  std::size_t posa=0;
458  std::size_t posb=mKeywords.length();
459  while(pos>0) {
460  if(posa>=mKeywords.length()) return res;
461  posb=mKeywords.find(mDelim,posa);
462  if(posb==std::string::npos) return res;
463  posa=posb+1;
464  pos--;
465  };
466  // default result
467  res=mKeywords.substr(posa);
468  // find next delimiter
469  posb=res.find(mDelim);
470  if(posb==std::string::npos) return res;
471  res=res.substr(0,posb);
472  return res;
473 }
474 
475 // keyword
477  int cnt=0;
478  // find delimiter
479  std::size_t pos=0;
480  while(pos<mKeywords.length()) {
481  cnt++;
482  pos=mKeywords.find(mDelim,pos);
483  if(pos==std::string::npos) break;
484  pos++;
485  };
486  return cnt;
487 }
488 
489 
490 // merge with docu from token io
492  FD_DRTI("Documentation::MergeDocumentation(): for " << mName);
493  // get first token to test type definition
494  Token token;
495  rTr.Peek(token);
496  if(!token.IsBegin()) return;
497  std::string label=token.StringValue();
498  // get ftype and test for match
499  std::string ftype=token.AttributeStringValue("name");
500  size_t pos=ftype.find("::");
501  if(pos!=std::string::npos) ftype=ftype.substr(pos+2);
502  // match?
503  if( (mName!=ftype && mName!="") || (ftype=="")) {
504  std::stringstream errstr;
505  errstr << "Documentation mismatch in file \"" << rTr.FileName() << "\" : " << mName << "!=" << ftype;
506  throw Exception("Documentation::MergeDocumentation", errstr.str(), 48);
507  };
508  // do read
509  DoRead(rTr,label);
510 }
511 
512 // token io
513 void Documentation::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
514  FD_DRTI("Documentation::DoRead(): file " << rTr.FileName());
515  // ignore
516  (void) pContext;
517  // figure my section
518  std::string label = rLabel;
519  if(label=="") label="Documentation";
520  // get first token for ftype and ctype
521  Token token;
522  rTr.ReadBegin(label,token);
523 
524  // sense and digest pre 2.16b format
525  if(!token.ExistsAttributeString("name")) {
526  Token ptoken;
527  rTr.Peek(ptoken);
528  mName=ptoken.StringValue();
529  size_t pos=mName.find("::");
530  if(pos!=std::string::npos) mName=mName.substr(pos+2);
531  mPlugIn=ptoken.StringValue();
532  pos=mPlugIn.find("::");
533  if(pos!=std::string::npos) mPlugIn=mPlugIn.substr(0,pos);
534  else mPlugIn = "CoreFaudes";
535  DoReadCore(rTr);
536  rTr.ReadEnd(label);
537  return;
538  } // end pre 2.16b format
539 
540  // get ftype
541  mName=token.AttributeStringValue("name");
542  size_t pos=mName.find("::");
543  if(pos!=std::string::npos) mName=mName.substr(pos+2);
544  // get plugin
545  mPlugIn=token.AttributeStringValue("name");
546  pos=mPlugIn.find("::");
547  if(pos!=std::string::npos) mPlugIn=mPlugIn.substr(0,pos);
548  else mPlugIn = "CoreFaudes";
549  // get ctype
550  mCType=token.AttributeStringValue("ctype");
551 
552  // get autoreg flag (note: let flag survive if originally set and no attribute)
553  if(token.ExistsAttributeInteger("autoregister"))
554  mAutoRegistered = (token.AttributeIntegerValue("autoregister"));
555  // report
556  FD_DRTI("Documentation::DoRead(): found " << mName << " " << mCType);
557  // do read
558  DoReadCore(rTr);
559  // done
560  rTr.ReadEnd(label);
561 }
562 
563 // token read
565  FD_DRTI("Documentation::DoReadCore()");
566  Token token;
567  mTextDoc="";
568  mHtmlDoc="";
569  mKeywords="";
570 
571  // sense and digest pre 2.16 format
572  rTr.Peek(token);
573  if(token.IsString()) {
574  mName=token.StringValue();
575  size_t pos=mName.find("::");
576  if(pos!=std::string::npos) mName=mName.substr(pos+2);
577  mPlugIn=token.StringValue();
578  pos=mPlugIn.find("::");
579  if(pos!=std::string::npos) mPlugIn=mPlugIn.substr(0,pos);
580  else mPlugIn = "CoreFaudes";
581  rTr.ReadString();
582  mCType="";
583  rTr.Peek(token);
584  if(token.IsOption())
585  mCType = rTr.ReadOption();
586  while(true) {
587  rTr.Peek(token);
588  if(token.IsBegin())
589  if(token.StringValue()=="TextDoc") {
590  rTr.ReadBegin("TextDoc");
591  mTextDoc = rTr.ReadString();
592  rTr.ReadEnd("TextDoc");
593  continue;
594  }
595  if(token.IsBegin())
596  if(token.StringValue()=="HtmlDoc") {
597  rTr.ReadBegin("HtmlDoc");
598  mHtmlDoc = rTr.ReadString();
599  rTr.ReadEnd("HtmlDoc");
600  continue;
601  }
602  if(token.IsBegin())
603  if(token.StringValue()=="Keywords") {
604  rTr.ReadBegin("Keywords");
605  while(!rTr.Eos("Keywords"))
606  AddKeyword(rTr.ReadString());
607  rTr.ReadEnd("Keywords");
608  continue;
609  }
610  break;
611  }
612  return;
613  } // end pre 2.16 format
614 
615  // loop other known entries
616  while(true) {
617  rTr.Peek(token);
618  // do the read: docu
619  if(token.IsBegin())
620  if(token.StringValue()=="Documentation") {
621  if(token.ExistsAttributeString("ref"))
622  mHtmlDoc=token.AttributeStringValue("ref");
623  rTr.ReadText("Documentation",mTextDoc);
624  continue;
625  }
626  // do the read: keys
627  if(token.IsBegin())
628  if(token.StringValue()=="Keywords") {
629  rTr.ReadBegin("Keywords");
630  while(!rTr.Eos("Keywords"))
631  AddKeyword(rTr.ReadString());
632  rTr.ReadEnd("Keywords");
633  continue;
634  }
635  // unknown -> derived class take over
636  break;
637  }
638 }
639 
640 
641 // token write
642 void Documentation::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
643  // ignore
644  (void) pContext;
645  // figure my section
646  std::string label = rLabel;
647  if(label=="") label="Documentation";
648  // begin tag
649  Token btag;
650  btag.SetBegin(label);
651  if(mPlugIn!="" && mName!="")
652  btag.InsAttribute("name",mPlugIn+"::"+mName);
653  if(mPlugIn=="" && mName!="")
654  btag.InsAttribute("name",mName);
655  if(mCType!="")
656  btag.InsAttribute("ctype",mCType);
657  if(mAutoRegistered)
658  btag.InsAttributeBoolean("autoregister",true);
659  rTw << btag;
660  // data
661  DoWriteCore(rTw);
662  // end tag
663  rTw.WriteEnd(label);
664 }
665 
666 // token write
668  // write text doc
669  if(mTextDoc!="" || mHtmlDoc!="") {
670  Token btag;
671  btag.SetBegin("Documentation");
672  if(mHtmlDoc!="")
673  btag.InsAttributeString("ref",mHtmlDoc);
674  rTw.WriteText(btag,mTextDoc);
675  }
676  // write keys
677  int ksz=KeywordsSize();
678  if(ksz>0) {
679  rTw.WriteBegin("Keywords");
680  for(int i=0; i<ksz; i++)
681  rTw.WriteString(KeywordAt(i));
682  rTw.WriteEnd("Keywords");
683  }
684 }
685 
686 
687 
688 /*
689 ********************************************************************
690 ********************************************************************
691 ********************************************************************
692 
693 Implementation of class TypeDefinition
694 
695 ********************************************************************
696 ********************************************************************
697 ********************************************************************
698 */
699 
700 
701 // faudes type (cannot do autoregister)
707 
708 
709 // Typedefinition constructor function
710 TypeDefinition* TypeDefinition::Constructor(Type* pProto, const std::string& rTypeName){
711  FD_DRTI("TypeDefinition::Construct(" << typeid(*pProto).name() << ", " << rTypeName << ")");
712  TypeDefinition* td = new TypeDefinition();
713  td->Prototype(pProto);
714  std::string name=rTypeName;
715  if(name=="") name=typeid(*pProto).name();
716  td->Name(name);
717  return(td);
718 }
719 
720 
721 // clear (all except prototype)
723  FD_DRTI("TypeDefinition::Clear()");
724  // call base
726  // my members
727  mXElementTag="";
728 }
729 
730 
731 // std faudes type
733  // assign base members
735  // assign my members
737  // special member
738  if(mpType) delete mpType;
739  mpType=0;
740  if(rSrc.mpType)
741  mpType=rSrc.mpType->New();
742 }
743 
744 // std faudes type
745 bool TypeDefinition::DoEqual(const TypeDefinition& rOther) const {
746  // test base members
747  if(!Documentation::DoEqual(rOther)) return false;
748  // test my members
749  if(mXElementTag!=rOther.mXElementTag) return false;
750  return true;
751 }
752 
753 
754 // token io
755 void TypeDefinition::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
756  FD_DRTI("TypeDefinition::DoRead(): file " << rTr.FileName());
757  // ignore
758  (void) pContext;
759  // figure my section
760  std::string label = rLabel;
761  if(label=="") label="TypeDefinition";
762  // base can handle this
763  Documentation::DoRead(rTr,label,pContext);
764  // my members
765 }
766 
767 // token io
769  FD_DRTI("TypeDefinition::DoReadCore(): file " << rTr.FileName());
770  // call base core
772  // my data
773  while(true) {
774  Token token;
775  rTr.Peek(token);
776  // element tag
777  if(token.IsBegin())
778  if(token.StringValue()=="XElementTag") {
779  rTr.ReadBegin("XElementTag",token);
780  if(token.ExistsAttributeString("value"))
781  mXElementTag=token.AttributeStringValue("value");
782  rTr.ReadEnd("XElementTag");
783  continue;
784  }
785  // break un unknown
786  break;
787  }
788 }
789 
790 // token io
791 void TypeDefinition::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
792  // label
793  std::string label=rLabel;
794  if(label=="") label="TypeDefinition";
795  // base can handle
796  Documentation::DoWrite(rTw,label,pContext);
797 }
798 
799 // token io
801  FD_DRTI("TypeDefinition::DoWriteCore(): file " << rTw.FileName());
802  // call base core
804  // my data
805  if(mXElementTag!="") {
806  Token etag;
807  etag.SetEmpty("XElementTag");
808  etag.InsAttributeString("value", mXElementTag);
809  rTw << etag;
810  }
811 }
812 
813 
814 // access prototype
815 const Type* TypeDefinition::Prototype(void) const{
816  return(mpType);
817 }
818 
819 // set prototype
821  if(mpType) delete mpType;
822  mpType = pType;
823  // test factory method
824 #ifdef FAUDES_CHECKED
825  if(mpType!=0) {
826  Type* nobj = mpType->New();
827  if(typeid(*nobj) != typeid(*mpType)) {
828  FD_WARN("TypeDefinition::Prototype(): factory method not implemented for c++-type " << typeid(*pType).name());
829  }
830  delete nobj;
831  }
832 #endif
833 }
834 
835 // construct new object with faudes type
837  FD_DRTI("TypeDefinition::NewObject()");
838  // bail out
839  if(!mpType) return NULL;
840  // use prototype
841  return mpType->New();
842 }
843 
844 
845 
846 // parameter access
847 const std::string& TypeDefinition::XElementTag(void) const {
848  return mXElementTag;
849 }
850 
851 // parameter access
852 void TypeDefinition::XElementTag(const std::string& rTag) {
853  mXElementTag=rTag;
854 }
855 
856 
857 
858 } //namspace
859 
#define FD_DC(message)
Debug: optional report on container operations.
#define FD_DRTI(message)
Debug: optional on function and type definition.
#define FD_WARN(message)
Debug: always report warnings.
Runtime interface, registry for faudes-types and functions.
Runtime interface, faudes types.
#define FAUDES_TYPE_IMPLEMENTATION_EQUAL(ftype, ctype, cbase)
Definition: cfl_types.h:904
#define FAUDES_TYPE_IMPLEMENTATION_COPY(ftype, ctype, cbase)
Definition: cfl_types.h:891
#define FAUDES_TYPE_IMPLEMENTATION_CAST(ftype, ctype, cbase)
Definition: cfl_types.h:893
#define FAUDES_TYPE_IMPLEMENTATION_ASSIGN(ftype, ctype, cbase)
Definition: cfl_types.h:896
#define FAUDES_TYPE_IMPLEMENTATION_NEW(ftype, ctype, cbase)
faudes type implementation macros
Definition: cfl_types.h:889
faudes type implementation macros, overall
Definition: cfl_types.h:1128
bool mAutoRegistered
Flag to indicate automated registration.
Definition: cfl_types.h:1436
Documentation(void)
Constructor.
Definition: cfl_types.cpp:352
void Clear(void)
Clear.
Definition: cfl_types.cpp:384
int KeywordsSize(void) const
Not implemented.
Definition: cfl_types.cpp:476
virtual void DoWriteCore(TokenWriter &rTw) const
Write configuration data of this object to TokenWriter.
Definition: cfl_types.cpp:667
bool DoEqual(const Documentation &rOther) const
Std faudes type interface: test equality.
Definition: cfl_types.cpp:373
std::string mTextDoc
String containing the text-documentation.
Definition: cfl_types.h:1424
std::string mKeywords
Comma-seperated string containing all keywords.
Definition: cfl_types.h:1430
void AddKeyword(const std::string &rKeyword)
Append keyword.
Definition: cfl_types.cpp:415
virtual void MergeDocumentation(TokenReader &rTr)
Merge documentation from token stream.
Definition: cfl_types.cpp:491
const std::string & HtmlDoc(void) const
Definition: cfl_types.cpp:400
const std::string & Name(void) const
Get name of the entety to document (aka faudes-type or faudes-function).
Definition: cfl_types.cpp:396
std::string KeywordAt(int pos) const
Definition: cfl_types.cpp:452
const std::string & Keywords(void) const
Definition: cfl_types.cpp:401
static const char mDelim
Constant characted used to seperate keywords.
Definition: cfl_types.h:1433
bool ApplicationRegistered(void) const
Get application-registered flag.
Definition: cfl_types.cpp:403
bool mApplicationRegistered
Flag to indicate application registration.
Definition: cfl_types.h:1439
std::string mCType
Corresponing C++ type, or "" if no such.
Definition: cfl_types.h:1421
std::string mHtmlDoc
String containing the filename of the corresponding html-documentation.
Definition: cfl_types.h:1427
const std::string & PlugIn(void) const
Get name of plugin.
Definition: cfl_types.cpp:397
std::string MatchKeyword(const std::string &rPattern) const
Search comma-seperated keywords for a substring.
Definition: cfl_types.cpp:425
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Write configuration data of this object to TokenWriter.
Definition: cfl_types.cpp:642
const std::string & TextDoc(void) const
Definition: cfl_types.cpp:399
const std::string & CType(void) const
Get corresponding C++ type.
Definition: cfl_types.cpp:398
bool AutoRegistered(void) const
Get auto-register flag.
Definition: cfl_types.cpp:402
void DoAssign(const Documentation &rSrc)
Std faudes type interface: assignment.
Definition: cfl_types.cpp:363
std::string mName
Faudes name.
Definition: cfl_types.h:1415
std::string mPlugIn
Faudes plugin.
Definition: cfl_types.h:1418
virtual void DoReadCore(TokenReader &rTr)
Read configuration data of this object from TokenReader.
Definition: cfl_types.cpp:564
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Read configuration data of this object from TokenReader.
Definition: cfl_types.cpp:513
Faudes exception class.
A TokenReader reads sequential tokens from a file or string.
void ReadText(const std::string &rLabel, std::string &rText)
Read plain text.
std::string ReadOption(void)
Read option token.
bool Eos(const std::string &rLabel)
Peek a token and check whether it ends the specified section.
void SeekBegin(const std::string &rLabel)
Find specified begin label.
void ReadEnd(const std::string &rLabel)
Close the current section by matching the previous ReadBegin().
std::string ReadString(void)
Read string token.
void ReadBegin(const std::string &rLabel)
Open a section by specified label.
bool Peek(Token &token)
Peek next token.
std::string FileName(void) const
Access the filename.
A TokenWriter writes sequential tokens to a file, a string or stdout.
std::string FileName(void) const
Get the filename.
std::string Str(void)
Retrieve output as string (if in String mode)
void WriteText(const std::string &rText)
Write text.
void WriteComment(const std::string &rComment)
Write comment in faudes format.
void Endl(void)
Write endl separator.
void WriteString(const std::string &rString)
Write string.
void WriteEnd(const std::string &rLabel)
Write end label.
void WriteBegin(const std::string &rLabel)
Write begin label.
Tokens model atomic data for stream IO.
Definition: cfl_token.h:53
const std::string & StringValue(void) const
Get string value of a name token.
Definition: cfl_token.cpp:177
Int AttributeIntegerValue(const std::string &name)
Access attribute value.
Definition: cfl_token.cpp:396
bool IsString(void) const
Test token Type.
Definition: cfl_token.cpp:243
void InsAttributeBoolean(const std::string &name, Int value)
Insert named attribute with boolean value.
Definition: cfl_token.cpp:336
bool ExistsAttributeString(const std::string &name)
Test attibute existence.
Definition: cfl_token.cpp:355
bool IsBegin(void) const
Test token Type.
Definition: cfl_token.cpp:258
void SetEmpty(const std::string &rName)
Initialize as empty-tag token.
Definition: cfl_token.cpp:105
void InsAttribute(const std::string &name, const std::string &value)
Insert named attribute, no type.
Definition: cfl_token.cpp:299
void SetBegin(const std::string &rName)
Initialize as Begin token.
Definition: cfl_token.cpp:91
bool ExistsAttributeInteger(const std::string &name)
Test attibute existence.
Definition: cfl_token.cpp:365
void InsAttributeString(const std::string &name, const std::string &value)
Insert named attribute with string value.
Definition: cfl_token.cpp:309
bool IsOption(void) const
Test token Type.
Definition: cfl_token.cpp:238
const std::string & AttributeStringValue(const std::string &name)
Access attribute value.
Definition: cfl_token.cpp:385
A TypeDefinition defines a faudes-type in that it specifies a faudes-type name to identify the type a...
Definition: cfl_types.h:1462
bool DoEqual(const TypeDefinition &rOther) const
Std faudes type interface: test equality.
Definition: cfl_types.cpp:745
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Write configuration data of this object to TokenWriter.
Definition: cfl_types.cpp:791
virtual void DoReadCore(TokenReader &rTr)
Read configuration data of this object from TokenReader.
Definition: cfl_types.cpp:768
Type * mpType
Type-pointer tp prototype instance.
Definition: cfl_types.h:1693
virtual void DoWriteCore(TokenWriter &rTw) const
Write configuration data of this object to TokenWriter.
Definition: cfl_types.cpp:800
void Clear(void)
Clear documentation-data; do NOT delete prototype (this is for using Read to merge/overwrite document...
Definition: cfl_types.cpp:722
void DoAssign(const TypeDefinition &rSrc)
Std faudes type interface: assignment.
Definition: cfl_types.cpp:732
std::string mXElementTag
Extra documentation/parameter: Xml Element Tag.
Definition: cfl_types.h:1696
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Read configuration data of this object from TokenReader.
Definition: cfl_types.cpp:755
const Type * Prototype(void) const
Return pointer to faudes-object prototype.
Definition: cfl_types.cpp:815
Type * NewObject(void) const
Construct faudes-object on heap.
Definition: cfl_types.cpp:836
const std::string & XElementTag(void) const
Parameter access: Xml Element Tag.
Definition: cfl_types.cpp:847
static TypeRegistry * G()
Method to access the single global instance of the registry.
const TypeDefinition * Definitionp(const std::string &rTypeName) const
Look up the type definition by faudes-type name.
Base class of all libFAUDES objects that participate in the run-time interface.
Definition: cfl_types.h:239
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Read configuration data of this object from TokenReader.
Definition: cfl_types.cpp:307
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Write configuration data of this object to TokenWriter.
Definition: cfl_types.cpp:282
virtual const TypeDefinition * TypeDefinitionp(void) const
Get objects's type definition.
Definition: cfl_types.cpp:127
bool DoEqual(const Type &rOther) const
Test equality of configuration data.
Definition: cfl_types.cpp:111
virtual bool operator==(const Type &rOther) const
Test equality of configuration data.
Definition: cfl_types.cpp:89
void DWrite(const Type *pContext=0) const
Write configuration data to console, debugging format.
Definition: cfl_types.cpp:225
virtual Token XBeginTag(const std::string &rLabel="", const std::string &rFallbackLabel="") const
Definition: cfl_types.cpp:315
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
Read configuration data from file with label specified.
Definition: cfl_types.cpp:261
virtual const std::string & Name(void) const
Get objects's name.
Definition: cfl_types.cpp:122
virtual Type & operator=(const Type &rSrc)
Assign configurationdata from other object.
Definition: cfl_types.cpp:99
std::string ToSText(void) const
Write statistics to a string.
Definition: cfl_types.cpp:177
static std::string msStringEmpty
Definition: cfl_types.h:859
std::string ToString(const std::string &rLabel="", const Type *pContext=0) const
Write configuration data to a string.
Definition: cfl_types.cpp:169
void FromString(const std::string &rString, const std::string &rLabel="", const Type *pContext=0)
Read configuration data from a string.
Definition: cfl_types.cpp:275
virtual void XWrite(const std::string &pFileName, const std::string &rLabel="", const Type *pContext=0) const
Write configuration data to an XML file.
Definition: cfl_types.cpp:200
virtual ~Type(void)
Destructor.
Definition: cfl_types.cpp:51
virtual void Clear(void)
Clear configuration data.
Definition: cfl_types.cpp:72
virtual Type & Assign(const Type &rSrc)
Assign configuration data from other object.
Definition: cfl_types.cpp:77
virtual Type * New(void) const
Construct on heap.
Definition: cfl_types.cpp:54
virtual void DoSWrite(TokenWriter &rTw) const
Write statistical data as a comment to TokenWriter.
Definition: cfl_types.cpp:299
void SWrite(void) const
Write statistics comment to console.
Definition: cfl_types.cpp:250
virtual void DoXWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Write configuration data of this object to TokenWriter in XML format.
Definition: cfl_types.cpp:288
virtual Type * Copy(void) const
Construct on heap.
Definition: cfl_types.cpp:60
std::string ToText(const std::string &rLabel="", const Type *pContext=0) const
Write configuration data to a formated string.
Definition: cfl_types.cpp:185
static std::string msStringVoid
Definition: cfl_types.h:858
void Write(const Type *pContext=0) const
Write configuration data to console.
Definition: cfl_types.cpp:139
virtual void DoDWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Write configuration data in debugging format to TokenWriter.
Definition: cfl_types.cpp:293
virtual bool operator!=(const Type &rOther) const
Test equality of configuration data.
Definition: cfl_types.cpp:94
void DoAssign(const Type &rSrc)
Assign configuration data from other object.
Definition: cfl_types.cpp:106
virtual const std::string & TypeName(void) const
Get objects's type name.
Definition: cfl_types.cpp:132
Type(void)
Constructor.
Definition: cfl_types.cpp:45
virtual bool Equal(const Type &rOther) const
Test equality of configuration data.
Definition: cfl_types.cpp:84
virtual const Type * Cast(const Type *pOther) const
Cast other object to this type.
Definition: cfl_types.cpp:66
libFAUDES resides within the namespace faudes.

libFAUDES 2.32b --- 2024.03.01 --- c++ api documentaion by doxygen