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.ReadBegin("Documentation");
624  mTextDoc = rTr.ReadText();
625  rTr.ReadEnd("Documentation");
626  continue;
627  }
628  // do the read: keys
629  if(token.IsBegin())
630  if(token.StringValue()=="Keywords") {
631  rTr.ReadBegin("Keywords");
632  while(!rTr.Eos("Keywords"))
633  AddKeyword(rTr.ReadString());
634  rTr.ReadEnd("Keywords");
635  continue;
636  }
637  // unknown -> derived class take over
638  break;
639  }
640 }
641 
642 
643 // token write
644 void Documentation::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
645  // ignore
646  (void) pContext;
647  // figure my section
648  std::string label = rLabel;
649  if(label=="") label="Documentation";
650  // begin tag
651  Token btag;
652  btag.SetBegin(label);
653  if(mPlugIn!="" && mName!="")
654  btag.InsAttribute("name",mPlugIn+"::"+mName);
655  if(mPlugIn=="" && mName!="")
656  btag.InsAttribute("name",mName);
657  if(mCType!="")
658  btag.InsAttribute("ctype",mCType);
659  if(mAutoRegistered)
660  btag.InsAttributeBoolean("autoregister",true);
661  rTw << btag << "\n";
662  // data
663  DoWriteCore(rTw);
664  // end tag
665  rTw.WriteEnd(label);
666 }
667 
668 // token write
670  // write text doc
671  if(mTextDoc!="" || mHtmlDoc!="") {
672  Token btag;
673  btag.SetBegin("Documentation");
674  if(mHtmlDoc!="")
675  btag.InsAttributeString("ref",mHtmlDoc);
676  rTw.WriteText(btag,mTextDoc);
677  }
678  // write keys
679  int ksz=KeywordsSize();
680  if(ksz>0) {
681  rTw.WriteBegin("Keywords");
682  for(int i=0; i<ksz; i++)
683  rTw.WriteString(KeywordAt(i));
684  rTw.WriteEnd("Keywords");
685  }
686  rTw << "\n";
687 }
688 
689 
690 
691 /*
692 ********************************************************************
693 ********************************************************************
694 ********************************************************************
695 
696 Implementation of class TypeDefinition
697 
698 ********************************************************************
699 ********************************************************************
700 ********************************************************************
701 */
702 
703 
704 // faudes type (cannot do autoregister)
710 
711 
712 // Typedefinition constructor function
713 TypeDefinition* TypeDefinition::Constructor(Type* pProto, const std::string& rTypeName){
714  FD_DRTI("TypeDefinition::Construct(" << typeid(*pProto).name() << ", " << rTypeName << ")");
715  TypeDefinition* td = new TypeDefinition();
716  td->Prototype(pProto);
717  std::string name=rTypeName;
718  if(name=="") name=typeid(*pProto).name();
719  td->Name(name);
720  return(td);
721 }
722 
723 
724 // clear (all except prototype)
726  FD_DRTI("TypeDefinition::Clear()");
727  // call base
729  // my members
730  mXElementTag="";
731 }
732 
733 
734 // std faudes type
736  // assign base members
738  // assign my members
740  // special member
741  if(mpType) delete mpType;
742  mpType=0;
743  if(rSrc.mpType)
744  mpType=rSrc.mpType->New();
745 }
746 
747 // std faudes type
748 bool TypeDefinition::DoEqual(const TypeDefinition& rOther) const {
749  // test base members
750  if(!Documentation::DoEqual(rOther)) return false;
751  // test my members
752  if(mXElementTag!=rOther.mXElementTag) return false;
753  return true;
754 }
755 
756 
757 // token io
758 void TypeDefinition::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
759  FD_DRTI("TypeDefinition::DoRead(): file " << rTr.FileName());
760  // ignore
761  (void) pContext;
762  // figure my section
763  std::string label = rLabel;
764  if(label=="") label="TypeDefinition";
765  // base can handle this
766  Documentation::DoRead(rTr,label,pContext);
767  // my members
768 }
769 
770 // token io
772  FD_DRTI("TypeDefinition::DoReadCore(): file " << rTr.FileName());
773  // call base core
775  // my data
776  while(true) {
777  Token token;
778  rTr.Peek(token);
779  // element tag
780  if(token.IsBegin())
781  if(token.StringValue()=="XElementTag") {
782  rTr.ReadBegin("XElementTag",token);
783  if(token.ExistsAttributeString("value"))
784  mXElementTag=token.AttributeStringValue("value");
785  rTr.ReadEnd("XElementTag");
786  continue;
787  }
788  // break un unknown
789  break;
790  }
791 }
792 
793 // token io
794 void TypeDefinition::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
795  // label
796  std::string label=rLabel;
797  if(label=="") label="TypeDefinition";
798  // base can handle
799  Documentation::DoWrite(rTw,label,pContext);
800 }
801 
802 // token io
804  FD_DRTI("TypeDefinition::DoWriteCore(): file " << rTw.FileName());
805  // call base core
807  // my data
808  if(mXElementTag!="") {
809  Token etag;
810  etag.SetEmpty("XElementTag");
811  etag.InsAttributeString("value", mXElementTag);
812  rTw << etag;
813  }
814 }
815 
816 
817 // access prototype
818 const Type* TypeDefinition::Prototype(void) const{
819  return(mpType);
820 }
821 
822 // set prototype
824  if(mpType) delete mpType;
825  mpType = pType;
826  // test factory method
827 #ifdef FAUDES_CHECKED
828  if(mpType!=0) {
829  Type* nobj = mpType->New();
830  if(typeid(*nobj) != typeid(*mpType)) {
831  FD_WARN("TypeDefinition::Prototype(): factory method not implemented for c++-type " << typeid(*pType).name());
832  }
833  delete nobj;
834  }
835 #endif
836 }
837 
838 // construct new object with faudes type
840  FD_DRTI("TypeDefinition::NewObject()");
841  // bail out
842  if(!mpType) return NULL;
843  // use prototype
844  return mpType->New();
845 }
846 
847 
848 
849 // parameter access
850 const std::string& TypeDefinition::XElementTag(void) const {
851  return mXElementTag;
852 }
853 
854 // parameter access
855 void TypeDefinition::XElementTag(const std::string& rTag) {
856  mXElementTag=rTag;
857 }
858 
859 
860 
861 } //namspace
862 

libFAUDES 2.24g --- 2014.09.15 --- c++ api documentaion by doxygen