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