libFAUDES

Sections

Index

rtitypes.cpp

Go to the documentation of this file.
00001 /** @file rtitypes.cpp Runtime interface, faudes types */
00002 
00003 /* FAU Discrete Event Systems Library (libfaudes)
00004 
00005 Copyright (C) 2009 Ruediger Berndt
00006 Copyright (C) 2009 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 "rtitypes.h"
00024 
00025 namespace faudes{
00026 
00027 /*
00028 ********************************************************************
00029 ********************************************************************
00030 ********************************************************************
00031 
00032 implemantation of faudes Type
00033 
00034 ********************************************************************
00035 ********************************************************************
00036 ********************************************************************
00037 */
00038 
00039 // static members: ref to the only one instance
00040 const std::string Type::mName("TypeStdName");
00041 
00042 // constructor
00043 Type::Type(void)  {}
00044 
00045 // copy constructor
00046 Type::Type(const Type& rType)  {(void) rType;}
00047 
00048 // destructor
00049 Type::~Type(void) {}
00050 
00051 // pointer constructor
00052 Type* Type::New(void) const { 
00053   return new Type(); 
00054 }
00055 
00056 // pointer copy constructor
00057 Type* Type::Copy(void) const { 
00058   return new Type(*this); 
00059 }
00060 
00061 // cast
00062 const Type* Type::Cast(const Type* pOther) const {
00063   return pOther;
00064 }
00065 
00066 // Clear()
00067 void Type::Clear(void) {
00068   FD_DC("Type::Clear(): not re-implemented in " << typeid(*this).name());
00069 }
00070 
00071 // assign
00072 Type& Type::Assign(const Type& rSource) {
00073   FD_DC("Type(" << this << ")::Assign(" << &rSource << ")");
00074   Clear();
00075   return *this;
00076 }
00077 
00078 // equality
00079 bool Type::Equal(const Type& rOther) const { 
00080   return true;
00081 }   
00082 
00083 // equality
00084 bool Type::operator==(const Type& rOther) const { 
00085   return true;
00086 }
00087 
00088 // equality
00089 bool Type::operator!=(const Type& rOther) const { 
00090   return false;
00091 }
00092 
00093 // assign
00094 Type& Type::operator=(const Type& rSource) {
00095   FD_DC("Type(" << this << ")::AssignementOperator(" << &rSource << ")");
00096   Clear();
00097   return *this;
00098 }
00099 
00100 // assign
00101 Type& Type::DoAssign(const Type& rSource) {
00102   FD_DC("Type(" << this << ")::DoAssign(" << &rSource << ")");
00103   return *this;
00104 }
00105 
00106 // equality
00107 bool Type::DoEqual(const Type& rOther) const {
00108   FD_DC("Type(" << this << ")::DoEqual(" << &rOther << ")");
00109   return true;
00110 }
00111 
00112 // Name(rName)
00113 void Type::Name(const std::string& rName) {
00114 }
00115 
00116 // Name()
00117 const std::string& Type::Name(void) const {
00118   return mName;
00119 }
00120 
00121 // Write(context)
00122 void Type::Write(const Type* pContext) const {
00123   TokenWriter tw(TokenWriter::Stdout);
00124   DoWrite(tw,"",pContext);
00125 }
00126 
00127 // Write(rFileName, label, context, openmode)
00128 void Type::Write(const std::string& rFileName, const std::string& rLabel, 
00129      const Type* pContext, std::ios::openmode openmode) const {
00130   try {
00131     TokenWriter tw(rFileName, openmode);
00132     DoWrite(tw, rLabel, pContext);
00133   }
00134   catch (std::ios::failure&) {
00135     std::stringstream errstr;
00136     errstr << "Exception opening/writing file \"" << rFileName << "\"";
00137     throw Exception("Type::Write", errstr.str(), 2);
00138   }
00139 }
00140 
00141 // Write(rFileName, openmode)
00142 void Type::Write(const std::string& rFileName, std::ios::openmode openmode) const {
00143   Write(rFileName,"",0,openmode);
00144 }
00145 
00146 // Write(tw,label,context)
00147 void Type::Write(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
00148   DoWrite(rTw,rLabel,pContext);
00149 }
00150 
00151 // ToString(label, context)
00152 std::string Type::ToString(const std::string& rLabel, const Type* pContext) const {
00153   TokenWriter tw(TokenWriter::String);
00154   tw.Endl(false);
00155   DoWrite(tw,rLabel,pContext);
00156   return tw.Str();
00157 }
00158 
00159 // ToSText()
00160 std::string Type::ToSText(void) const {
00161   TokenWriter tw(TokenWriter::String);
00162   tw.Endl(true);
00163   DoSWrite(tw);
00164   return tw.Str();
00165 }
00166 
00167 // ToString(label, context)
00168 std::string Type::ToText(const std::string& rLabel, const Type* pContext) const {
00169   TokenWriter tw(TokenWriter::String);
00170   tw.Endl(true);
00171   DoWrite(tw,rLabel,pContext);
00172   return tw.Str();
00173 }
00174 
00175 // DWrite(context)
00176 void Type::DWrite(const Type* pContext) const {
00177   TokenWriter tw(TokenWriter::Stdout);
00178   DoDWrite(tw,"",pContext);
00179 }
00180 
00181 // DWrite(rFileName, label, context, openmode)
00182 void Type::DWrite(const std::string& rFileName, const std::string& rLabel, 
00183       const Type* pContext, std::ios::openmode openmode) const {
00184   try {
00185     TokenWriter tw(rFileName, openmode);
00186     DoDWrite(tw, rLabel, pContext);
00187   }
00188   catch (std::ios::failure&) {
00189     std::stringstream errstr;
00190     errstr << "Exception opening/writing file \"" << rFileName << "\"";
00191     throw Exception("Type::DWrite", errstr.str(), 2);
00192   }
00193 }
00194 
00195 // DWrite(tw,label,context)
00196 void Type::DWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
00197   DoDWrite(rTw,rLabel,pContext);
00198 }
00199 
00200 // SWrite()
00201 void Type::SWrite(void) const {
00202   TokenWriter tw(TokenWriter::Stdout);
00203   DoSWrite(tw);
00204 }
00205 
00206 // SWrite(tw)
00207 void Type::SWrite(TokenWriter& rTw) const {
00208   DoSWrite(rTw);
00209 }
00210 
00211 // Read(rFilename, rLabel,context)
00212 void Type::Read(const std::string& rFilename, const std::string& rLabel, const Type* pContext) {
00213   Clear();
00214   TokenReader tr(rFilename);
00215   DoRead(tr,rLabel,pContext);
00216 }
00217 
00218 // Read(rTr, rLabel, context)
00219 void Type::Read(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
00220   Clear();
00221   DoRead(rTr,rLabel,pContext);
00222 }
00223 
00224 // FromString(rString, rLabel, context)
00225 void Type::FromString(const std::string& rString, const std::string& rLabel, const Type* pContext) {
00226   Clear();
00227   TokenReader tr(TokenReader::String,rString);
00228   DoRead(tr,rLabel,pContext);
00229 }
00230   
00231 //DoWrite(rTr,rLabel,pContext)
00232 void Type::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
00233   (void) rTw; (void) rLabel; (void) pContext;
00234   FD_DC("Type::DoWrite(): not re-implemented in " << typeid(*this).name());
00235 }
00236 
00237 //DoDWrite(rTr,rLabel,pContext)
00238 void Type::DoDWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
00239   FD_DC("Type::DoDWrite(): not re-implemented in " << typeid(*this).name() << ", using DoDWrite instead");
00240   DoWrite(rTw,rLabel,pContext);
00241 }
00242 
00243 //DoSWrite(rTr,rLabel,pContext)
00244 void Type::DoSWrite(TokenWriter& rTw) const {
00245   FD_DC("Type::DoSWrite(): not re-implemented in " << typeid(*this).name());
00246   rTw.WriteComment("");
00247   rTw.WriteComment(" Statistics for " + Name());
00248   rTw.WriteComment("");
00249 }
00250 
00251 //DoRead(rTr,rLabel,pContext)
00252 void Type::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
00253   (void) rLabel; (void) pContext; (void) rTr;
00254   FD_DC("Type::DoRead(): not re-implemented in " << typeid(*this).name());
00255 }
00256 
00257 
00258 
00259 /*
00260 ********************************************************************
00261 ********************************************************************
00262 ********************************************************************
00263 
00264 Implementation of class Documentation
00265 
00266 ********************************************************************
00267 ********************************************************************
00268 ********************************************************************
00269 */
00270 
00271 // construct
00272 Documentation::Documentation(){
00273 }
00274 
00275 // clear all
00276 void Documentation::Clear(void){
00277   FD_DRTI("Documentation::Clear()");
00278   mName="";
00279   mPlugIn="CoreFaudes";
00280   mHtmlDoc="";
00281   mTextDoc="";
00282   mKeywords="";
00283 }
00284 
00285 //  read access members
00286 const std::string& Documentation::Name(void) const{ return mName; }
00287 const std::string& Documentation::PlugIn(void) const{ return mPlugIn; }
00288 const std::string& Documentation::CType(void) const{ return mCType; }
00289 const std::string& Documentation::TextDoc() const{ return mTextDoc; }
00290 const std::string& Documentation::HtmlDoc() const{ return mHtmlDoc; }
00291 const std::string& Documentation::Keywords() const{ return mKeywords; }
00292 
00293 //  write access members
00294 void Documentation::Name(const std::string& name){mName = name; }
00295 void Documentation::PlugIn(const std::string& plugin){mPlugIn = plugin; }
00296 void Documentation::CType(const std::string& name){mCType = name; }
00297 void Documentation::TextDoc(const std::string& textdoc){mTextDoc = textdoc;}
00298 void Documentation::HtmlDoc(const std::string& fname){mHtmlDoc = fname;}
00299 
00300 //  write access keyword
00301 void Documentation::AddKeyword(const std::string& rKeyword){
00302   if(mKeywords.empty()){
00303     mKeywords = rKeyword;
00304   } else{
00305     mKeywords.append(1, mDelim);
00306     mKeywords.append(rKeyword);
00307   }
00308 }
00309 
00310 // regex match keywords (todo)
00311 std::string Documentation::MatchKeyword(const std::string& rPattern) const{
00312   FD_DRTI("Documentation::MatchKeyword(" << rPattern << ")");
00313   // be case insensitive (inefficient)
00314   std::string keys = mKeywords;
00315   std::transform(keys.begin(), keys.end(), keys.begin(), tolower);
00316   std::string match = rPattern;
00317   std::transform(match.begin(), match.end(), match.begin(), tolower);
00318   // find match
00319   std::string res="";
00320   std::size_t posk=keys.find(match);
00321   if(posk==std::string::npos) return res;
00322   // find delimiters 
00323   std::size_t posa=0;
00324   std::size_t posb=keys.length();
00325   while(true) {
00326     posb=keys.find(mDelim,posa);
00327     if(posb==std::string::npos) posb=mKeywords.length();
00328     if(posb>posk) break;
00329     posa=posb+1;
00330   };
00331   // return original case match
00332   FD_DRTI("Documentation::MatchKeyword(" << rPattern << "): " << mKeywords.substr(posa,posb-posa));
00333   return mKeywords.substr(posa,posb-posa);
00334 }
00335 
00336 
00337 // positional keyword
00338 std::string Documentation::KeywordAt(int pos) const{
00339   FD_DRTI("Documentation::KeywordAt(" << pos << ")");
00340   // default result
00341   std::string res="";
00342   // find delimiter
00343   std::size_t posa=0;
00344   std::size_t posb=mKeywords.length();
00345   while(pos>0) {
00346     if(posa>=mKeywords.length()) return res;
00347     posb=mKeywords.find(mDelim,posa);
00348     if(posb==std::string::npos) return res;
00349     posa=posb+1;
00350     pos--;
00351   };
00352   // default result
00353   res=mKeywords.substr(posa);
00354   // find next delimiter
00355   posb=res.find(mDelim);
00356   if(posb==std::string::npos) return res;
00357   res=res.substr(0,posb);
00358   return res;
00359 }
00360 
00361 // keyword
00362 int Documentation::KeywordsSize(void) const{
00363   int cnt=0;
00364   // find delimiter
00365   std::size_t pos=0;
00366   while(pos<mKeywords.length()) {
00367     cnt++;
00368     pos=mKeywords.find(mDelim,pos);
00369     if(pos==std::string::npos) break;
00370     pos++;
00371   };
00372   return cnt;
00373 }
00374 
00375 
00376 // token read
00377 void Documentation::DoRead(TokenReader& rTr,  const std::string& rLabel, const Type* pContext) {
00378   FD_DRTI("Documentation::DoRead(): file " << rTr.FileName());
00379   // ignore label and context
00380   (void) rLabel;
00381   (void) pContext;
00382   Token token;
00383   // my faudes entety (eg type name incl plugin)
00384   std::string ident= rTr.ReadString();
00385   // separate name
00386   size_t pos=ident.find("::");
00387   if(pos!=std::string::npos) mName=ident.substr(pos+2);
00388   else mName=ident;
00389   // separate plugin
00390   if(pos!=std::string::npos) mPlugIn=ident.substr(0,pos);
00391   else mPlugIn = "CoreFaudes";
00392   // corresponding c type
00393   mCType="";
00394   rTr.Peek(token);
00395   if(token.Type()==Token::Option)
00396     mCType = rTr.ReadOption();
00397   // loop other known entries
00398   while(true) {
00399     rTr.Peek(token);
00400     // do the read: text
00401     if(token.Type()==Token::Begin)  
00402     if(token.StringValue()=="TextDoc") {
00403       rTr.ReadBegin("TextDoc");
00404       mTextDoc = rTr.ReadString();
00405       rTr.ReadEnd("TextDoc");
00406       continue;
00407     }
00408     // do the read: html
00409     if(token.Type()==Token::Begin)  
00410     if(token.StringValue()=="HtmlDoc") {
00411       rTr.ReadBegin("HtmlDoc");
00412       mHtmlDoc = rTr.ReadString();
00413       rTr.ReadEnd("HtmlDoc");
00414       continue;
00415     }
00416     // do the read: keys
00417     if(token.Type()==Token::Begin)  
00418     if(token.StringValue()=="Keywords") {
00419       rTr.ReadBegin("Keywords");
00420       while(!rTr.Eos("Keywords")) 
00421         AddKeyword(rTr.ReadString());
00422       rTr.ReadEnd("Keywords");
00423       continue;
00424     }
00425     // unknown -> derived class take over
00426     break;
00427   }
00428 }
00429 
00430 
00431 // token write
00432 void Documentation::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
00433   // ignore label and context
00434   (void) rLabel;
00435   (void) pContext;
00436   // write name
00437   rTw << mPlugIn + "::" + mName ;
00438   // write c type
00439   if(mCType!="") rTw.WriteOption(mCType);
00440   // write text doc
00441   rTw.WriteBegin("TextDoc");
00442   rTw << mTextDoc;
00443   rTw.WriteEnd("TextDoc");
00444   // write html doc
00445   rTw.WriteBegin("HtmlDoc");
00446   rTw << mHtmlDoc;
00447   rTw.WriteEnd("HtmlDoc");
00448   // write keys
00449   rTw.WriteBegin("Keywords");
00450   rTw << mKeywords;
00451   rTw.WriteEnd("Keywords");
00452 }
00453 
00454 
00455 
00456 /*
00457 ********************************************************************
00458 ********************************************************************
00459 ********************************************************************
00460 
00461 Implementation of class TypeDefinition
00462 
00463 ********************************************************************
00464 ********************************************************************
00465 ********************************************************************
00466 */
00467 
00468 
00469 // typedefinition constructor function
00470 TypeDefinition* TypeDefinition::Constructor(Type* pProto, const std::string& rTypeName){
00471   FD_DRTI("TypeDefinition::Construct(" << typeid(pProto).name() << ", " << rTypeName << ")");
00472   TypeDefinition* td = new TypeDefinition();
00473   td->Prototype(pProto);
00474   std::string name=rTypeName;
00475   if(name=="") name=typeid(pProto).name();
00476   td->Name(name);
00477   return(td);
00478 }
00479 
00480 // merge with docu from token io
00481 void TypeDefinition::MergeDocumentationBody(TokenReader& rTr) {
00482   FD_DRTI("TypeDefinition::MergeDocumentationBody(): file " << rTr.FileName() << " for " << mName);
00483   // peek type ident
00484   Token token;
00485   rTr.Peek(token);
00486   // separate name
00487   std::string name = token.StringValue();
00488   size_t pos=name.find("::");
00489   if(pos!=std::string::npos) name=name.substr(pos+2);
00490   // match?
00491   if(mName!=name && mName!="") {
00492     std::stringstream errstr;
00493     errstr << "Documentation mismatch in file \"" << rTr.FileName() << "\" : " << mName << "!=" << name;
00494     throw Exception("TypeDefinition::MergeDocumentationBody", errstr.str(), 48);
00495   };
00496   // call base
00497   Documentation::DoRead(rTr);  
00498 }
00499 
00500 // token io
00501 void TypeDefinition::DoRead(TokenReader& rTr,  const std::string& rLabel, const Type* pContext) {
00502   FD_DRTI("TypeDefinition::DoRead(): file " << rTr.FileName());
00503   // ignore
00504   (void) rLabel;
00505   (void) pContext;
00506   // doit
00507   rTr.ReadBegin("TypeDefinition");
00508   // peek and set name
00509   Token token;
00510   rTr.Peek(token);
00511   // extract name 
00512   std::string mName=token.StringValue();
00513   size_t pos=mName.find("::");
00514   if(pos!=std::string::npos) mName=mName.substr(pos+2);
00515   // do read
00516   MergeDocumentationBody(rTr);
00517   // no extras .. done
00518   rTr.ReadEnd("TypeDefinition");
00519 }
00520 
00521 // token io
00522 void TypeDefinition::DoWrite(TokenWriter& rTw,  const std::string& rLabel, const Type* pContext) const {
00523   // ignore
00524   (void) rLabel;
00525   (void) pContext;
00526   // doit
00527   rTw.WriteBegin("TypeDefinition");
00528   // call base
00529   Documentation::DoWrite(rTw); 
00530   // no extras .. done
00531   rTw.WriteEnd("TypeDefitinion");
00532 }
00533 
00534 // access prototype
00535 const Type* TypeDefinition::Prototype(void) const{
00536   return(mpType);
00537 }
00538 
00539 // set prototype
00540 void TypeDefinition::Prototype(faudes::Type* pType){
00541   if(mpType) delete mpType;
00542   mpType = pType;
00543 }
00544 
00545 // construct new object with faudes type
00546 Type* TypeDefinition::NewObject() const{
00547   FD_DRTI("TypeDefinition::NewObject()");
00548   // bail out 
00549   if(!mpType) return NULL;
00550   // use prototype
00551   return mpType->New();
00552 }
00553 
00554 
00555 // clear (all except prototype)
00556 void TypeDefinition::Clear(){
00557   FD_DRTI("TypeDefinition::Clear()");
00558   // call base
00559   Documentation::Clear();
00560 }
00561 
00562 
00563 
00564 /*
00565 ********************************************************************
00566 ********************************************************************
00567 ********************************************************************
00568 
00569 Implementation of class Integer
00570 
00571 ********************************************************************
00572 ********************************************************************
00573 ********************************************************************
00574 */
00575 
00576 
00577 // public:
00578 Integer::Integer() {
00579   CValue(0);
00580 }
00581 
00582 Integer::Integer(SignedIdx val) {
00583   CValue(val);
00584 }
00585 
00586 Type* Integer::New() const{
00587   return(new Integer());
00588 }
00589 
00590 Type* Integer::Copy() const{
00591   return(new Integer(mCInteger));
00592 }
00593 
00594 void Integer::CValue(SignedIdx val){
00595   mCInteger = val;
00596 }
00597 
00598 SignedIdx Integer::CValue() const{
00599   return(mCInteger);
00600 }
00601 
00602 SignedIdx* Integer::CReference() {
00603   return &mCInteger;
00604 }
00605 
00606 void Integer::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const{
00607   (void) pContext;
00608   std::string label=rLabel;
00609   if(label=="") label="Integer";
00610   FD_DRTI("Integer::DoWrite(): file " << rTw.FileName() << " section " << label);
00611   rTw.WriteBegin(label);
00612   rTw.WriteFloat(mCInteger);
00613   rTw.WriteEnd(label);
00614 }
00615 
00616 void Integer::DoRead(TokenReader& rTr,  const std::string& rLabel, const Type* pContext) {
00617   (void) pContext;
00618   std::string label = rLabel;
00619   if(label == "") label = "Integer";
00620   FD_DRTI("Integer()::DoRead(): file " << rTr.FileName() << "  section " << label);
00621   rTr.SeekBegin(label);
00622   mCInteger = (SignedIdx)rTr.ReadFloat();
00623   rTr.SeekEnd(label);
00624   FD_DRTI("Integer::DoRead(): done");
00625 }
00626 
00627 
00628 // integer sum, uniform rti api
00629 void IntegerSum(const Integer& arg1, const Integer& arg2, Integer& res) {
00630   res=arg1+arg2;
00631 }
00632 
00633 
00634 /*
00635 ********************************************************************
00636 ********************************************************************
00637 ********************************************************************
00638 
00639 Implementation of class String
00640 
00641 ********************************************************************
00642 ********************************************************************
00643 ********************************************************************
00644 */
00645 
00646 
00647 // constructor
00648 String::String() {
00649   CValue("");
00650 }
00651 
00652 // constructor
00653 String::String(std::string val) {
00654   CValue(val);
00655 }
00656 
00657 // factory constructor
00658 Type* String::New() const{
00659   return(new String());
00660 }
00661 
00662 // factory constructor
00663 Type* String::Copy() const{
00664   return(new String(mCString));
00665 }
00666 
00667 // c value
00668 std::string String::CValue() const{
00669   return(mCString);
00670 }
00671 
00672 // c value
00673 void String::CValue(std::string s){
00674   mCString = s;
00675 }
00676 
00677 // c ref
00678 std::string* String::CReference() {
00679   return &mCString;
00680 }
00681 
00682 // token io
00683 void String::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const{
00684   (void)pContext;
00685   std::string label = rLabel;
00686   if(label == "") label = "String";
00687   FD_DRTI("String::DoWrite(): file " << rTw.FileName() << " section " << label);
00688   rTw.WriteBegin(label);
00689   rTw.WriteString(mCString);
00690   rTw.WriteEnd(label);
00691 }
00692 
00693 // token io
00694 void String::DoRead(TokenReader& rTr,  const std::string& rLabel, const Type* pContext) {
00695   (void) pContext;
00696   std::string label = rLabel;
00697   if(label == "") label = "String";
00698   FD_DRTI("String::DoRead(): file " << rTr.FileName() << "  section " << label);
00699   rTr.SeekBegin(label);
00700   mCString = rTr.ReadString();
00701   rTr.SeekEnd(label);
00702   FD_DRTI("String::DoRead(): done");
00703 }
00704 
00705 
00706 /*
00707 ********************************************************************
00708 ********************************************************************
00709 ********************************************************************
00710 
00711 Implementation of class Boolean
00712 
00713 ********************************************************************
00714 ********************************************************************
00715 ********************************************************************
00716 */
00717 
00718 
00719 // constructor
00720 Boolean::Boolean() {
00721   CValue(true);
00722 }
00723 
00724 // constructor
00725 Boolean::Boolean(bool val) {
00726   CValue(val);
00727 }
00728 
00729 // factory constructor
00730 Type* Boolean::New() const{
00731   return(new Boolean());
00732 }
00733 
00734 // factory constructor
00735 Type* Boolean::Copy() const{
00736   return(new Boolean(mCBool));
00737 }
00738 
00739 
00740 // cvaliu
00741 void Boolean::CValue(bool val){
00742   mCBool = val;
00743 }
00744 
00745 // cvalue 
00746 bool Boolean::CValue() const{
00747   return(mCBool);
00748 }
00749 
00750 // c ref
00751 bool* Boolean::CReference() {
00752   return &mCBool;
00753 }
00754 
00755 // token io
00756 void Boolean::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const{
00757   (void)pContext;
00758   std::string label = rLabel;
00759   if(label == "") label = "Boolean";
00760   FD_DRTI("Boolean::DoWrite(): file " << rTw.FileName() << " section " << label);
00761   rTw.WriteBegin(label);
00762   if(mCBool) rTw.WriteString("true");
00763   else rTw.WriteString("false");
00764   rTw.WriteEnd(label);
00765 }
00766 
00767 
00768 // token io
00769 void Boolean::DoRead(TokenReader& rTr,  const std::string& rLabel, const Type* pContext) {
00770   (void) pContext;
00771   std::string label = rLabel;
00772   if(label == "") label = "Boolean";
00773   FD_DRTI("Boolean::DoRead(): file " << rTr.FileName() << "  section " << label);
00774   rTr.SeekBegin(label);
00775   std::string value = rTr.ReadString();
00776   std::transform(value.begin(), value.end(), value.begin(), tolower);
00777   if(value=="true") mCBool=true;
00778   else if(value=="false") mCBool=false;
00779   else {
00780     std::stringstream err;
00781     err << "Expected true or false: " << rTr.FileLine();
00782     throw Exception("Boolean::DoRead()", err.str(), 52);
00783   }
00784   rTr.SeekEnd(label);
00785   FD_DRTI("Boolean::DoRead(): done");
00786 }
00787 
00788 
00789 
00790 } //namspace
00791 

libFAUDES 2.14g --- 2009-12-3 --- c++ source docu by doxygen 1.5.6