tp_attributes.cpp

Go to the documentation of this file.
00001 /** @file tp_attributes.cpp  Attributes for timed automata */
00002 
00003 
00004 /* Timeplugin for FAU Discrete Event Systems Library (libfaudes)
00005 
00006    Copyright (C) 2007  Thomas Moor
00007    Exclusive copyright is granted to Klaus Schmidt
00008 
00009 */
00010 
00011 #include "tp_attributes.h"
00012 
00013 namespace faudes {
00014 
00015 
00016 /*******************************
00017  * 
00018  * Implementation of AttributeTimedTrans
00019  *
00020  */
00021 
00022 // faudes type std
00023 FAUDES_TYPE_IMPLEMENTATION(Void,AttributeTimedTrans,AttributeFlags)
00024 
00025 // Assign my members
00026 void AttributeTimedTrans::DoAssign(const AttributeTimedTrans& rSrcAttr) { 
00027   // call base (incl. virtual clear)
00028   AttributeFlags::DoAssign(rSrcAttr);
00029   // my additional members
00030   mGuard=rSrcAttr.mGuard;
00031   mResets=rSrcAttr.mResets;
00032 }
00033 
00034 // Equality
00035 bool AttributeTimedTrans::DoEqual(const AttributeTimedTrans& rOther) const {
00036   // base
00037   if(!AttributeFlags::DoEqual(rOther)) return false;
00038   // my members
00039   if(mGuard!=rOther.mGuard) return false;
00040   if(mResets!=rOther.mResets) return false;
00041   // pass
00042   return true;
00043 }
00044 
00045 
00046 //DoWrite(rTw,rLabel,pContext);
00047 void AttributeTimedTrans::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
00048   if(IsDefault()) return;
00049   AttributeFlags::DoWrite(rTw,"",pContext);
00050   if(mGuard.Empty() && mResets.Empty()) return; 
00051   std::string label=rLabel;
00052   FD_DC("AttributeTimedTrans(" << this << ")::DoWrite(tr): to section " << label);
00053   if(label=="") label="Timing";
00054   rTw.WriteBegin(label);
00055   if(!mGuard.Empty()) 
00056      mGuard.Write(rTw);
00057   if(!mResets.Empty()) 
00058     mResets.Write(rTw);
00059   rTw.WriteEnd(label);
00060 }
00061 
00062 
00063 //DoRead(rTr,rLabel,pContext)
00064 void AttributeTimedTrans::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
00065   // call base first
00066   AttributeFlags::DoRead(rTr,"",pContext);
00067   // find my section
00068   std::string label=rLabel;
00069   if(label=="") label="Timing";
00070   FD_DC("AttributeTimedTrans(" << this << ")::DoRead(tr): from section " << label);
00071   // initialise my data
00072   mGuard.Clear();
00073   mResets.Clear();
00074   // test for  my data
00075   Token token;
00076   rTr.Peek(token);
00077   if(!token.IsBegin()) return;
00078   if(token.StringValue()!=label) return;
00079   // test read  my data (could throw exceptions now)
00080   rTr.ReadBegin(label);
00081   while (rTr.Peek(token)) {
00082     // 0: looking for "begin" only
00083     if (token.Type() != Token::Begin) break;
00084     // 1: guard
00085     if (token.StringValue() == "Guard") {
00086        mGuard.Read(rTr,"Guard");
00087        continue;
00088     }
00089     // 2: resets
00090     if (token.StringValue() == "Resets") {
00091        mResets.Read(rTr,"Resets");
00092        continue;
00093     }
00094     // 3:
00095     std::stringstream errstr;
00096     errstr << "invalid transition timing" << rTr.FileLine();
00097     throw Exception("AttributeTimedTrans::Read", errstr.str(), 52);
00098   }
00099   mGuard.Name("Guard");
00100   mResets.Name("Resets");
00101   rTr.ReadEnd(label);
00102 }
00103 
00104 
00105 /*******************************
00106  * 
00107  * Implementation of AttributeTimedState
00108  *
00109  */
00110 
00111 // faudes type std
00112 FAUDES_TYPE_IMPLEMENTATION(Void,AttributeTimedState,AttributeFlags)
00113 
00114 // Assign my members
00115 void AttributeTimedState::DoAssign(const AttributeTimedState& rSrcAttr) { 
00116   // call base (incl. virtual clear)
00117   AttributeFlags::DoAssign(rSrcAttr);
00118   // my additional members
00119   mInvariant=rSrcAttr.mInvariant;
00120 }
00121 
00122 // Equality
00123 bool AttributeTimedState::DoEqual(const AttributeTimedState& rOther) const {
00124   // base
00125   if(!AttributeFlags::DoEqual(rOther)) return false;
00126   // my members
00127   if(mInvariant!=rOther.mInvariant) return false;
00128   // pass
00129   return true;
00130 }
00131 
00132 
00133 //DoWrite(rTw,rLabel,pContext);
00134 void AttributeTimedState::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
00135   (void) pContext;
00136   if(IsDefault()) return;
00137   AttributeFlags::DoWrite(rTw,"",pContext);
00138   std::string label=rLabel;
00139   if(label=="") label="Invariant";
00140   FD_DC("AttributeTimedState(" << this << ")::DoWrite(tr): to section " << label);
00141   if(!mInvariant.Empty())
00142     mInvariant.Write(rTw,label);
00143 }
00144 
00145 
00146 //DoRead(rTr,rLabel,pContext)
00147 void AttributeTimedState::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
00148   // call base first
00149   AttributeFlags::DoRead(rTr,"",pContext);
00150   // figure my section
00151   std::string label=rLabel;
00152   if(label=="") label="Invariant";
00153   FD_DC("AttributeTimedState(" << this << ")::DoRead(tr): from section " << label);
00154   // clear my data
00155   mInvariant.Clear();
00156   // test my section
00157   Token token;
00158   rTr.Peek(token);
00159   if(!token.IsBegin())  return;
00160   if(token.StringValue()!=label) return;
00161   // read my section (can throw exceptions now)
00162   mInvariant.Read(rTr,label);
00163 }
00164 
00165 
00166 /*******************************
00167  * 
00168  * Implementation of AttributeTimedGlobal
00169  *
00170  */
00171 
00172 // faudes type std
00173 FAUDES_TYPE_IMPLEMENTATION(Void,AttributeTimedGlobal,AttributeVoid)
00174 
00175 // Assign my members
00176 void AttributeTimedGlobal::DoAssign(const AttributeTimedGlobal& rSrcAttr) { 
00177   // call base (incl. virtual clear)
00178   AttributeVoid::DoAssign(rSrcAttr);
00179   // my additional members
00180   mClocks=rSrcAttr.mClocks;
00181   mpClockSymbolTable=rSrcAttr.mpClockSymbolTable;
00182 }
00183 
00184 // Equality
00185 bool AttributeTimedGlobal::DoEqual(const AttributeTimedGlobal& rOther) const {
00186   // my members
00187   if(mClocks!=rOther.mClocks) return false;
00188   // pass
00189   return true;
00190 }
00191 
00192 //DoWrite(rTw,rLabel,pContext);
00193 void AttributeTimedGlobal::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
00194   (void) pContext;
00195   if(IsDefault()) return;
00196   std::string label=rLabel;
00197   if(label=="") label="Clocks";
00198   FD_DC("AttributeTimedGlobal(" << this << ")::DoWrite(tr): to section " << label);
00199   mClocks.Write(rTw,label);
00200 }
00201 
00202 //DoRead(rTr,rLabel,pContext)
00203 void AttributeTimedGlobal::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
00204   std::string label=rLabel;
00205   if(label=="") label="Clocks";
00206   FD_DC("AttributeTimedGlobal(" << this << ")::DoRead(tr): from section " << label);
00207   (void) pContext;
00208   mClocks.Clear();
00209   Token token;
00210   rTr.Peek(token);
00211   if(!token.IsBegin())  return;
00212   if(token.StringValue()!=label) return;
00213   mClocks.Read(rTr,label);
00214 }
00215 
00216 
00217 
00218 
00219 
00220 
00221 } // namespace faudes
00222 

libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen