libFAUDES

Sections

Index

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

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