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)
347 FAUDES_TYPE_IMPLEMENTATION_CAST(Void,Documentation,Type)
348 FAUDES_TYPE_IMPLEMENTATION_ASSIGN(Void,Documentation,Type)
349 FAUDES_TYPE_IMPLEMENTATION_EQUAL(Void,Documentation,Type)
350 
351 // construct
352 Documentation::Documentation(void) : Type() {
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 

libFAUDES 2.28a --- 2016.09.13 --- c++ api documentaion by doxygen