|
libFAUDES
Sections
Index
|
cfl_types.cppGo to the documentation of this file.00001 /** @file cfl_types.cpp Runtime interface, faudes types */ 00002 00003 /* FAU Discrete Event Systems Library (libfaudes) 00004 00005 Copyright (C) 2009 Ruediger Berndt 00006 Copyright (C) 2010 Thomas Moor 00007 00008 This library is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU Lesser General Public 00010 License as published by the Free Software Foundation; either 00011 version 2.1 of the License, or (at your option) any later version. 00012 00013 This library is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 Lesser General Public License for more details. 00017 00018 You should have received a copy of the GNU Lesser General Public 00019 License along with this library; if not, write to the Free Software 00020 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 00021 00022 00023 #include "cfl_types.h" 00024 #include "cfl_registry.h" 00025 00026 namespace faudes{ 00027 00028 /* 00029 ******************************************************************** 00030 ******************************************************************** 00031 ******************************************************************** 00032 00033 implemantation of faudes Type 00034 00035 ******************************************************************** 00036 ******************************************************************** 00037 ******************************************************************** 00038 */ 00039 00040 // statics 00041 std::string Type::msStringVoid("Void"); 00042 std::string Type::msStringEmpty(""); 00043 00044 // constructor 00045 Type::Type(void) {} 00046 00047 // copy constructor 00048 Type::Type(const Type& rType) {(void) rType;} 00049 00050 // destructor 00051 Type::~Type(void) {} 00052 00053 // pointer constructor 00054 Type* Type::New(void) const { 00055 return new Type(); 00056 } 00057 00058 // pointer copy constructor 00059 Type* Type::Copy(void) const { 00060 return new Type(*this); 00061 } 00062 00063 // cast 00064 const Type* Type::Cast(const Type* pOther) const { 00065 return pOther; 00066 } 00067 00068 // Clear() 00069 void Type::Clear(void) { 00070 FD_DC("Type::Clear(): not re-implemented in " << typeid(*this).name()); 00071 } 00072 00073 // assign 00074 Type& Type::Assign(const Type& rSource) { 00075 FD_DC("Type(" << this << ")::Assign(" << &rSource << ")"); 00076 Clear(); 00077 return *this; 00078 } 00079 00080 // equality (relaxed) 00081 bool Type::Equal(const Type& rOther) const { 00082 return true; 00083 } 00084 00085 // equality (strict) 00086 bool Type::operator==(const Type& rOther) const { 00087 return typeid(*this)==typeid(rOther); 00088 } 00089 00090 // equality 00091 bool Type::operator!=(const Type& rOther) const { 00092 return ! operator==(rOther); 00093 } 00094 00095 // assign 00096 Type& Type::operator=(const Type& rSource) { 00097 FD_DC("Type(" << this << ")::AssignementOperator(" << &rSource << ")"); 00098 Clear(); 00099 return *this; 00100 } 00101 00102 // assign 00103 void Type::DoAssign(const Type& rSource) { 00104 FD_DC("Type(" << this << ")::DoAssign(" << &rSource << ")"); 00105 } 00106 00107 // equality 00108 bool Type::DoEqual(const Type& rOther) const { 00109 FD_WARN("Type(" << this << ")::DoEqual(" << &rOther << ")"); 00110 return true; 00111 } 00112 00113 // Name(rName) 00114 void Type::Name(const std::string& rName) { 00115 (void) rName; 00116 } 00117 00118 // Name() 00119 const std::string& Type::Name(void) const { 00120 return msStringEmpty; 00121 } 00122 00123 // TypeDefinitionp() 00124 const TypeDefinition* Type::TypeDefinitionp(void) const { 00125 return TypeRegistry::G()->Definitionp(*this); 00126 } 00127 00128 // TypeName() 00129 const std::string& Type::TypeName(void) const { 00130 const TypeDefinition* fdp=TypeDefinitionp(); 00131 if(!fdp) return msStringEmpty; 00132 return fdp->Name(); 00133 } 00134 00135 // Write(context) 00136 void Type::Write(const Type* pContext) const { 00137 TokenWriter tw(TokenWriter::Stdout); 00138 DoWrite(tw,"",pContext); 00139 } 00140 00141 // Write(rFileName, label, context, openmode) 00142 void Type::Write(const std::string& rFileName, const std::string& rLabel, 00143 const Type* pContext, std::ios::openmode openmode) const { 00144 try { 00145 TokenWriter tw(rFileName, openmode); 00146 DoWrite(tw, rLabel, pContext); 00147 } 00148 catch(std::ios::failure&) { 00149 std::stringstream errstr; 00150 errstr << "Exception opening/writing file \"" << rFileName << "\""; 00151 throw Exception("Type::Write", errstr.str(), 2); 00152 } 00153 } 00154 00155 // Write(rFileName, openmode) 00156 void Type::Write(const std::string& rFileName, std::ios::openmode openmode) const { 00157 Write(rFileName,"",0,openmode); 00158 } 00159 00160 // Write(tw,label,context) 00161 void Type::Write(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const { 00162 DoWrite(rTw,rLabel,pContext); 00163 } 00164 00165 // ToString(label, context) 00166 std::string Type::ToString(const std::string& rLabel, const Type* pContext) const { 00167 TokenWriter tw(TokenWriter::String); 00168 tw.Endl(false); 00169 DoWrite(tw,rLabel,pContext); 00170 return tw.Str(); 00171 } 00172 00173 // ToSText() 00174 std::string Type::ToSText(void) const { 00175 TokenWriter tw(TokenWriter::String); 00176 tw.Endl(true); 00177 DoSWrite(tw); 00178 return tw.Str(); 00179 } 00180 00181 // ToString(label, context) 00182 std::string Type::ToText(const std::string& rLabel, const Type* pContext) const { 00183 TokenWriter tw(TokenWriter::String); 00184 tw.Endl(true); 00185 DoWrite(tw,rLabel,pContext); 00186 return tw.Str(); 00187 } 00188 00189 // XWrite(context) 00190 void Type::XWrite(const Type* pContext) const { 00191 FD_DC("Type(" << this << ")::XWrite(): for " << typeid(*this).name()); 00192 TokenWriter tw(TokenWriter::Stdout); 00193 DoXWrite(tw,"",pContext); 00194 } 00195 00196 // XWrite(rFileName, label, context) 00197 void Type::XWrite(const std::string& rFileName, const std::string& rLabel, const Type* pContext) const { 00198 std::string ftype=TypeName(); 00199 if(ftype=="") { 00200 std::stringstream errstr; 00201 errstr << "Cannot write unregistered faudes-type object \"" << typeid(*this).name() << "\""; 00202 throw Exception("Type::XWrite", errstr.str(), 2); 00203 } 00204 try { 00205 TokenWriter tw(rFileName,ftype); 00206 XWrite(tw, rLabel, pContext); 00207 } 00208 catch(std::ios::failure&) { 00209 std::stringstream errstr; 00210 errstr << "Exception opening/writing file \"" << rFileName << "\""; 00211 throw Exception("Type::XWrite", errstr.str(), 2); 00212 } 00213 } 00214 00215 // XWrite(tw,label,context) 00216 void Type::XWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const { 00217 FD_DC("Type(" << this << ")::XWrrite(): for " << typeid(*this).name()); 00218 DoXWrite(rTw,rLabel,pContext); 00219 } 00220 00221 // DWrite(context) 00222 void Type::DWrite(const Type* pContext) const { 00223 TokenWriter tw(TokenWriter::Stdout); 00224 DoDWrite(tw,"",pContext); 00225 } 00226 00227 // DWrite(rFileName, label, context, openmode) 00228 void Type::DWrite(const std::string& rFileName, const std::string& rLabel, 00229 const Type* pContext, std::ios::openmode openmode) const { 00230 try { 00231 TokenWriter tw(rFileName, openmode); 00232 DoDWrite(tw, rLabel, pContext); 00233 } 00234 catch(std::ios::failure&) { 00235 std::stringstream errstr; 00236 errstr << "Exception opening/writing file \"" << rFileName << "\""; 00237 throw Exception("Type::DWrite", errstr.str(), 2); 00238 } 00239 } 00240 00241 // DWrite(tw,label,context) 00242 void Type::DWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const { 00243 DoDWrite(rTw,rLabel,pContext); 00244 } 00245 00246 // SWrite() 00247 void Type::SWrite(void) const { 00248 TokenWriter tw(TokenWriter::Stdout); 00249 DoSWrite(tw); 00250 } 00251 00252 // SWrite(tw) 00253 void Type::SWrite(TokenWriter& rTw) const { 00254 DoSWrite(rTw); 00255 } 00256 00257 // Read(rFilename, rLabel,context) 00258 void Type::Read(const std::string& rFilename, const std::string& rLabel, const Type* pContext) { 00259 Clear(); 00260 TokenReader tr(rFilename); 00261 if(rLabel!="") tr.SeekBegin(rLabel); 00262 DoRead(tr,rLabel,pContext); 00263 } 00264 00265 // Read(rTr, rLabel, context) 00266 void Type::Read(TokenReader& rTr, const std::string& rLabel, const Type* pContext) { 00267 Clear(); 00268 DoRead(rTr,rLabel,pContext); 00269 } 00270 00271 // FromString(rString, rLabel, context) 00272 void Type::FromString(const std::string& rString, const std::string& rLabel, const Type* pContext) { 00273 Clear(); 00274 TokenReader tr(TokenReader::String,rString); 00275 DoRead(tr,rLabel,pContext); 00276 } 00277 00278 //DoWrite(rTr,rLabel,pContext) 00279 void Type::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const { 00280 (void) rTw; (void) rLabel; (void) pContext; 00281 FD_DC("Type::DoWrite(): not re-implemented in " << typeid(*this).name()); 00282 } 00283 00284 //DoXWrite(rTr,rLabel,pContext) 00285 void Type::DoXWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const { 00286 DoWrite(rTw, rLabel, pContext); 00287 } 00288 00289 //DoDWrite(rTr,rLabel,pContext) 00290 void Type::DoDWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const { 00291 FD_DC("Type::DoDWrite(): not re-implemented in " << typeid(*this).name() << ", using DoDWrite instead"); 00292 DoWrite(rTw,rLabel,pContext); 00293 } 00294 00295 //DoSWrite(rTr,rLabel,pContext) 00296 void Type::DoSWrite(TokenWriter& rTw) const { 00297 FD_DC("Type::DoSWrite(): not re-implemented in " << typeid(*this).name()); 00298 rTw.WriteComment(""); 00299 rTw.WriteComment(" Statistics for " + Name()); 00300 rTw.WriteComment(""); 00301 } 00302 00303 //DoRead(rTr,rLabel,pContext) 00304 void Type::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) { 00305 (void) rLabel; (void) pContext; (void) rTr; 00306 FD_DC("Type::DoRead(): not re-implemented in " << typeid(*this).name()); 00307 } 00308 00309 00310 00311 /* 00312 ******************************************************************** 00313 ******************************************************************** 00314 ******************************************************************** 00315 00316 Implementation of class Documentation 00317 00318 ******************************************************************** 00319 ******************************************************************** 00320 ******************************************************************** 00321 */ 00322 00323 // faudes type (cannot do autoregister) 00324 FAUDES_TYPE_IMPLEMENTATION_NEW(Void,Documentation,Type) 00325 FAUDES_TYPE_IMPLEMENTATION_COPY(Void,Documentation,Type) 00326 FAUDES_TYPE_IMPLEMENTATION_CAST(Void,Documentation,Type) 00327 FAUDES_TYPE_IMPLEMENTATION_ASSIGN(Void,Documentation,Type) 00328 FAUDES_TYPE_IMPLEMENTATION_EQUAL(Void,Documentation,Type) 00329 00330 // construct 00331 Documentation::Documentation(void) : Type() { 00332 mAutoRegister=false; 00333 } 00334 00335 // construct 00336 Documentation::Documentation(const Documentation& rOther) : Type() { 00337 DoAssign(rOther); 00338 } 00339 00340 // std faudes type 00341 void Documentation::DoAssign(const Documentation& rSrc) { 00342 // assign my members 00343 mName=rSrc.mName; 00344 mPlugIn=rSrc.mPlugIn; 00345 mHtmlDoc=rSrc.mHtmlDoc; 00346 mTextDoc=rSrc.mTextDoc; 00347 mKeywords=rSrc.mKeywords; 00348 } 00349 00350 // std faudes type 00351 bool Documentation::DoEqual(const Documentation& rOther) const { 00352 // test my members 00353 if(mName!=rOther.mName) return false; 00354 if(mPlugIn!=rOther.mPlugIn) return false; 00355 if(mHtmlDoc!=rOther.mHtmlDoc) return false; 00356 if(mTextDoc!=rOther.mTextDoc) return false; 00357 if(mKeywords!=rOther.mKeywords) return false; 00358 return true; 00359 } 00360 00361 // clear all 00362 void Documentation::Clear(void){ 00363 FD_DRTI("Documentation::Clear()"); 00364 mName=""; 00365 mPlugIn="CoreFaudes"; 00366 mHtmlDoc=""; 00367 mTextDoc=""; 00368 mKeywords=""; 00369 mAutoRegister=false; 00370 } 00371 00372 // read access members 00373 const std::string& Documentation::Name(void) const{ return mName; } 00374 const std::string& Documentation::PlugIn(void) const{ return mPlugIn; } 00375 const std::string& Documentation::CType(void) const{ return mCType; } 00376 const std::string& Documentation::TextDoc() const{ return mTextDoc; } 00377 const std::string& Documentation::HtmlDoc() const{ return mHtmlDoc; } 00378 const std::string& Documentation::Keywords() const{ return mKeywords; } 00379 bool Documentation::AutoRegister(void) const{ return mAutoRegister; } 00380 00381 // write access members 00382 void Documentation::Name(const std::string& name){mName = name; } 00383 void Documentation::PlugIn(const std::string& plugin){mPlugIn = plugin; } 00384 void Documentation::CType(const std::string& name){mCType = name; } 00385 void Documentation::TextDoc(const std::string& textdoc){mTextDoc = textdoc;} 00386 void Documentation::HtmlDoc(const std::string& fname){mHtmlDoc = fname;} 00387 void Documentation::AutoRegister(bool flag){ mAutoRegister = flag;} 00388 00389 // write access keyword 00390 void Documentation::AddKeyword(const std::string& rKeyword){ 00391 if(mKeywords.empty()){ 00392 mKeywords = rKeyword; 00393 } else{ 00394 mKeywords.append(1, mDelim); 00395 mKeywords.append(rKeyword); 00396 } 00397 } 00398 00399 // regex match keywords (todo) 00400 std::string Documentation::MatchKeyword(const std::string& rPattern) const{ 00401 FD_DRTI("Documentation::MatchKeyword(" << rPattern << ")"); 00402 // be case insensitive (inefficient) 00403 std::string keys = mKeywords; 00404 std::transform(keys.begin(), keys.end(), keys.begin(), tolower); 00405 std::string match = rPattern; 00406 std::transform(match.begin(), match.end(), match.begin(), tolower); 00407 // find match 00408 std::string res=""; 00409 std::size_t posk=keys.find(match); 00410 if(posk==std::string::npos) return res; 00411 // find delimiters 00412 std::size_t posa=0; 00413 std::size_t posb=keys.length(); 00414 while(true) { 00415 posb=keys.find(mDelim,posa); 00416 if(posb==std::string::npos) posb=mKeywords.length(); 00417 if(posb>posk) break; 00418 posa=posb+1; 00419 }; 00420 // return original case match 00421 FD_DRTI("Documentation::MatchKeyword(" << rPattern << "): " << mKeywords.substr(posa,posb-posa)); 00422 return mKeywords.substr(posa,posb-posa); 00423 } 00424 00425 00426 // positional keyword 00427 std::string Documentation::KeywordAt(int pos) const{ 00428 FD_DRTI("Documentation::KeywordAt(" << pos << ")"); 00429 // default result 00430 std::string res=""; 00431 // find delimiter 00432 std::size_t posa=0; 00433 std::size_t posb=mKeywords.length(); 00434 while(pos>0) { 00435 if(posa>=mKeywords.length()) return res; 00436 posb=mKeywords.find(mDelim,posa); 00437 if(posb==std::string::npos) return res; 00438 posa=posb+1; 00439 pos--; 00440 }; 00441 // default result 00442 res=mKeywords.substr(posa); 00443 // find next delimiter 00444 posb=res.find(mDelim); 00445 if(posb==std::string::npos) return res; 00446 res=res.substr(0,posb); 00447 return res; 00448 } 00449 00450 // keyword 00451 int Documentation::KeywordsSize(void) const{ 00452 int cnt=0; 00453 // find delimiter 00454 std::size_t pos=0; 00455 while(pos<mKeywords.length()) { 00456 cnt++; 00457 pos=mKeywords.find(mDelim,pos); 00458 if(pos==std::string::npos) break; 00459 pos++; 00460 }; 00461 return cnt; 00462 } 00463 00464 00465 // merge with docu from token io 00466 void Documentation::MergeDocumentation(TokenReader& rTr) { 00467 FD_DRTI("Documentation::MergeDocumentation(): for " << mName); 00468 // get first token to test type definition 00469 Token token; 00470 rTr.Peek(token); 00471 if(!token.IsBegin()) return; 00472 // get ftype and test for match 00473 std::string ftype=token.AttributeStringValue("name"); 00474 size_t pos=ftype.find("::"); 00475 if(pos!=std::string::npos) ftype=ftype.substr(pos+2); 00476 // match? 00477 if( (mName!=ftype && mName!="") || (ftype=="")) { 00478 std::stringstream errstr; 00479 errstr << "Documentation mismatch in file \"" << rTr.FileName() << "\" : " << mName << "!=" << ftype; 00480 throw Exception("Documentation::MergeDocumentation", errstr.str(), 48); 00481 }; 00482 // do read 00483 DoRead(rTr); 00484 } 00485 00486 // token io 00487 void Documentation::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) { 00488 FD_DRTI("Documentation::DoRead(): file " << rTr.FileName()); 00489 // ignore 00490 (void) pContext; 00491 // figure my section 00492 std::string label = rLabel; 00493 if(label=="") label="Documentation"; 00494 // get first token for ftype and ctype 00495 Token token; 00496 rTr.ReadBegin(label,token); 00497 00498 // sense and digest pre 2.16b format 00499 if(!token.ExistsAttributeString("name")) { 00500 Token ptoken; 00501 rTr.Peek(ptoken); 00502 mName=ptoken.StringValue(); 00503 size_t pos=mName.find("::"); 00504 if(pos!=std::string::npos) mName=mName.substr(pos+2); 00505 mPlugIn=ptoken.StringValue(); 00506 pos=mPlugIn.find("::"); 00507 if(pos!=std::string::npos) mPlugIn=mPlugIn.substr(0,pos); 00508 else mPlugIn = "CoreFaudes"; 00509 DoReadCore(rTr); 00510 rTr.ReadEnd(label); 00511 return; 00512 } // end pre 2.16b format 00513 00514 // get ftype 00515 mName=token.AttributeStringValue("name"); 00516 size_t pos=mName.find("::"); 00517 if(pos!=std::string::npos) mName=mName.substr(pos+2); 00518 // get plugin 00519 mPlugIn=token.AttributeStringValue("name"); 00520 pos=mPlugIn.find("::"); 00521 if(pos!=std::string::npos) mPlugIn=mPlugIn.substr(0,pos); 00522 else mPlugIn = "CoreFaudes"; 00523 // get ctype 00524 mCType=token.AttributeStringValue("ctype"); 00525 00526 // get autoreg flag (note: let flag survive if originally set and no attribute) 00527 if(token.ExistsAttributeInteger("autoregister")) 00528 mAutoRegister = (token.AttributeIntegerValue("autoregister")); 00529 // report 00530 FD_DRTI("Documentation::DoRead(): found " << mName << " " << mCType); 00531 // do read 00532 DoReadCore(rTr); 00533 // done 00534 rTr.ReadEnd(label); 00535 } 00536 00537 // token read 00538 void Documentation::DoReadCore(TokenReader& rTr) { 00539 FD_DRTI("Documentation::DoReadCore()"); 00540 Token token; 00541 mTextDoc=""; 00542 mHtmlDoc=""; 00543 mKeywords=""; 00544 00545 // sense and digest pre 2.16 format 00546 rTr.Peek(token); 00547 if(token.IsString()) { 00548 mName=token.StringValue(); 00549 size_t pos=mName.find("::"); 00550 if(pos!=std::string::npos) mName=mName.substr(pos+2); 00551 mPlugIn=token.StringValue(); 00552 pos=mPlugIn.find("::"); 00553 if(pos!=std::string::npos) mPlugIn=mPlugIn.substr(0,pos); 00554 else mPlugIn = "CoreFaudes"; 00555 rTr.ReadString(); 00556 mCType=""; 00557 rTr.Peek(token); 00558 if(token.IsOption()) 00559 mCType = rTr.ReadOption(); 00560 while(true) { 00561 rTr.Peek(token); 00562 if(token.IsBegin()) 00563 if(token.StringValue()=="TextDoc") { 00564 rTr.ReadBegin("TextDoc"); 00565 mTextDoc = rTr.ReadString(); 00566 rTr.ReadEnd("TextDoc"); 00567 continue; 00568 } 00569 if(token.IsBegin()) 00570 if(token.StringValue()=="HtmlDoc") { 00571 rTr.ReadBegin("HtmlDoc"); 00572 mHtmlDoc = rTr.ReadString(); 00573 rTr.ReadEnd("HtmlDoc"); 00574 continue; 00575 } 00576 if(token.IsBegin()) 00577 if(token.StringValue()=="Keywords") { 00578 rTr.ReadBegin("Keywords"); 00579 while(!rTr.Eos("Keywords")) 00580 AddKeyword(rTr.ReadString()); 00581 rTr.ReadEnd("Keywords"); 00582 continue; 00583 } 00584 break; 00585 } 00586 return; 00587 } // end pre 2.16 format 00588 00589 // loop other known entries 00590 while(true) { 00591 rTr.Peek(token); 00592 // do the read: docu 00593 if(token.IsBegin()) 00594 if(token.StringValue()=="Documentation") { 00595 if(token.ExistsAttributeString("ref")) 00596 mHtmlDoc=token.AttributeStringValue("ref"); 00597 rTr.ReadBegin("Documentation"); 00598 mTextDoc = rTr.ReadText(); 00599 rTr.ReadEnd("Documentation"); 00600 continue; 00601 } 00602 // do the read: keys 00603 if(token.IsBegin()) 00604 if(token.StringValue()=="Keywords") { 00605 rTr.ReadBegin("Keywords"); 00606 while(!rTr.Eos("Keywords")) 00607 AddKeyword(rTr.ReadString()); 00608 rTr.ReadEnd("Keywords"); 00609 continue; 00610 } 00611 // unknown -> derived class take over 00612 break; 00613 } 00614 } 00615 00616 00617 // token write 00618 void Documentation::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const { 00619 // ignore 00620 (void) pContext; 00621 // figure my section 00622 std::string label = rLabel; 00623 if(label=="") label="Documentation"; 00624 // begin tag 00625 Token btag; 00626 btag.SetBegin(label); 00627 if(mPlugIn!="" && mName!="") 00628 btag.InsAttribute("name",mPlugIn+"::"+mName); 00629 if(mPlugIn=="" && mName!="") 00630 btag.InsAttribute("name",mName); 00631 if(mCType!="") 00632 btag.InsAttribute("ctype",mCType); 00633 if(mAutoRegister) 00634 btag.InsAttributeBoolean("autoregister",true); 00635 rTw << btag << "\n"; 00636 // data 00637 DoWriteCore(rTw); 00638 // end tag 00639 rTw.WriteEnd(label); 00640 } 00641 00642 // token write 00643 void Documentation::DoWriteCore(TokenWriter& rTw) const { 00644 // write text doc 00645 if(mTextDoc!="" || mHtmlDoc!="") { 00646 Token btag; 00647 btag.SetBegin("Documentation"); 00648 if(mHtmlDoc!="") 00649 btag.InsAttributeString("ref",mHtmlDoc); 00650 rTw.WriteText(btag,mTextDoc); 00651 } 00652 // write keys 00653 int ksz=KeywordsSize(); 00654 if(ksz>0) { 00655 rTw.WriteBegin("Keywords"); 00656 for(int i=0; i<ksz; i++) 00657 rTw.WriteString(KeywordAt(i)); 00658 rTw.WriteEnd("Keywords"); 00659 } 00660 rTw << "\n"; 00661 } 00662 00663 00664 00665 /* 00666 ******************************************************************** 00667 ******************************************************************** 00668 ******************************************************************** 00669 00670 Implementation of class TypeDefinition 00671 00672 ******************************************************************** 00673 ******************************************************************** 00674 ******************************************************************** 00675 */ 00676 00677 00678 // faudes type (cannot do autoregister) 00679 FAUDES_TYPE_IMPLEMENTATION_NEW(Void,TypeDefinition,Documentation) 00680 FAUDES_TYPE_IMPLEMENTATION_COPY(Void,TypeDefinition,Documentation) 00681 FAUDES_TYPE_IMPLEMENTATION_ASSIGN(Void,TypeDefinition,Documentation) 00682 FAUDES_TYPE_IMPLEMENTATION_CAST(Void,TypeDefinition,Documentation) 00683 FAUDES_TYPE_IMPLEMENTATION_EQUAL(Void,TypeDefinition,Documentation) 00684 00685 00686 // Typedefinition constructor function 00687 TypeDefinition* TypeDefinition::Constructor(Type* pProto, const std::string& rTypeName){ 00688 FD_DRTI("TypeDefinition::Construct(" << typeid(*pProto).name() << ", " << rTypeName << ")"); 00689 TypeDefinition* td = new TypeDefinition(); 00690 td->Prototype(pProto); 00691 std::string name=rTypeName; 00692 if(name=="") name=typeid(*pProto).name(); 00693 td->Name(name); 00694 return(td); 00695 } 00696 00697 00698 // clear (all except prototype) 00699 void TypeDefinition::Clear(){ 00700 FD_DRTI("TypeDefinition::Clear()"); 00701 // call base 00702 Documentation::Clear(); 00703 // my members 00704 mXElementTag=""; 00705 } 00706 00707 00708 // std faudes type 00709 void TypeDefinition::DoAssign(const TypeDefinition& rSrc) { 00710 // assign base members 00711 Documentation::DoAssign(rSrc); 00712 // assign my members 00713 mXElementTag=rSrc.mXElementTag; 00714 // special member 00715 if(mpType) delete mpType; 00716 mpType=0; 00717 if(rSrc.mpType) 00718 mpType=rSrc.mpType->New(); 00719 } 00720 00721 // std faudes type 00722 bool TypeDefinition::DoEqual(const TypeDefinition& rOther) const { 00723 // test base members 00724 if(!Documentation::DoEqual(rOther)) return false; 00725 // test my members 00726 if(mXElementTag!=rOther.mXElementTag) return false; 00727 return true; 00728 } 00729 00730 00731 // token io 00732 void TypeDefinition::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) { 00733 FD_DRTI("TypeDefinition::DoRead(): file " << rTr.FileName()); 00734 // ignore 00735 (void) pContext; 00736 // figure my section 00737 std::string label = rLabel; 00738 if(label=="") label="TypeDefinition"; 00739 // base can handle this 00740 Documentation::DoRead(rTr,label,pContext); 00741 // my members 00742 } 00743 00744 // token io 00745 void TypeDefinition::DoReadCore(TokenReader& rTr) { 00746 FD_DRTI("TypeDefinition::DoReadCore(): file " << rTr.FileName()); 00747 // call base core 00748 Documentation::DoReadCore(rTr); 00749 // my data 00750 while(true) { 00751 Token token; 00752 rTr.Peek(token); 00753 // element tag 00754 if(token.IsBegin()) 00755 if(token.StringValue()=="XElementTag") { 00756 rTr.ReadBegin("XElementTag",token); 00757 if(token.ExistsAttributeString("value")) 00758 mXElementTag=token.AttributeStringValue("value"); 00759 rTr.ReadEnd("XElementTag"); 00760 continue; 00761 } 00762 // break un unknown 00763 break; 00764 } 00765 } 00766 00767 // token io 00768 void TypeDefinition::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const { 00769 // label 00770 std::string label=rLabel; 00771 if(label=="") label="TypeDefinition"; 00772 // base can handle 00773 Documentation::DoWrite(rTw,label,pContext); 00774 } 00775 00776 // token io 00777 void TypeDefinition::DoWriteCore(TokenWriter& rTw) const { 00778 FD_DRTI("TypeDefinition::DoWriteCore(): file " << rTw.FileName()); 00779 // call base core 00780 Documentation::DoWriteCore(rTw); 00781 // my data 00782 if(mXElementTag!="") { 00783 Token etag; 00784 etag.SetEmpty("XElementTag"); 00785 etag.InsAttributeString("value", mXElementTag); 00786 rTw << etag; 00787 } 00788 } 00789 00790 00791 // access prototype 00792 const Type* TypeDefinition::Prototype(void) const{ 00793 return(mpType); 00794 } 00795 00796 // set prototype 00797 void TypeDefinition::Prototype(faudes::Type* pType){ 00798 if(mpType) delete mpType; 00799 mpType = pType; 00800 // test factory method 00801 if(mpType!=0) { 00802 Type* nobj = mpType->New(); 00803 if(typeid(*nobj) != typeid(*mpType)) 00804 FD_WARN("TypeDefinition::Prototype(): factory method not implemented for c++-type " << typeid(*pType).name()) 00805 } 00806 } 00807 00808 // construct new object with faudes type 00809 Type* TypeDefinition::NewObject() const{ 00810 FD_DRTI("TypeDefinition::NewObject()"); 00811 // bail out 00812 if(!mpType) return NULL; 00813 // use prototype 00814 return mpType->New(); 00815 } 00816 00817 00818 00819 // parameter access 00820 const std::string& TypeDefinition::XElementTag(void) const { 00821 return mXElementTag; 00822 } 00823 00824 // parameter access 00825 void TypeDefinition::XElementTag(const std::string& rTag) { 00826 mXElementTag=rTag; 00827 } 00828 00829 00830 00831 } //namspace 00832 |
libFAUDES 2.18b --- 2010-12-17 --- c++ source docu by doxygen 1.6.3