tp_attributes.cpp

Go to the documentation of this file.
00001 
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 //DoWrite(rTw,rLabel,pContext);
00023 void AttributeTimedTrans::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
00024   if(IsDefault()) return;
00025   AttributeFlags::DoWrite(rTw,"",pContext);
00026   if(mGuard.Empty() && mResets.Empty()) return; 
00027   std::string label=rLabel;
00028   FD_DC("AttributeTimedTrans(" << this << ")::DoWrite(tr): to section " << label);
00029   if(label=="") label="Timing";
00030   rTw.WriteBegin(label);
00031   if(!mGuard.Empty()) 
00032      mGuard.Write(rTw);
00033   if(!mResets.Empty()) 
00034     mResets.Write(rTw);
00035   rTw.WriteEnd(label);
00036 }
00037 
00038 
00039 //DoRead(rTr,rLabel,pContext)
00040 void AttributeTimedTrans::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
00041   // call base first
00042   AttributeFlags::DoRead(rTr,"",pContext);
00043   // find my section
00044   std::string label=rLabel;
00045   if(label=="") label="Timing";
00046   FD_DC("AttributeTimedTrans(" << this << ")::DoRead(tr): from section " << label);
00047   // initialise my data
00048   mGuard.Clear();
00049   mResets.Clear();
00050   // test for  my data
00051   Token token;
00052   rTr.Peek(token);
00053   if(token.Type()!=Token::Begin)  return;
00054   if(token.StringValue()!=label) return;
00055   // test read  my data (could throw exceptions now)
00056   rTr.ReadBegin(label);
00057   while (rTr.Peek(token)) {
00058     // 0: looking for "begin" only
00059     if (token.Type() != Token::Begin) break;
00060     // 1: guard
00061     if (token.StringValue() == "Guard") {
00062        mGuard.Read(rTr,"Guard");
00063        continue;
00064     }
00065     // 2: resets
00066     if (token.StringValue() == "Resets") {
00067        mResets.Read(rTr,"Resets");
00068        continue;
00069     }
00070     // 3:
00071     std::stringstream errstr;
00072     errstr << "invalid transition timing" << rTr.FileLine();
00073     throw Exception("AttributeTimedTrans::Read", errstr.str(), 52);
00074   }
00075   mGuard.Name("Guard");
00076   mResets.Name("Resets");
00077   rTr.ReadEnd(label);
00078 }
00079 
00080 
00081 /*******************************
00082  * 
00083  * Implementation of AttributeTimedState
00084  *
00085  */
00086 
00087 //DoWrite(rTw,rLabel,pContext);
00088 void AttributeTimedState::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
00089   (void) pContext;
00090   if(IsDefault()) return;
00091   AttributeFlags::DoWrite(rTw,"",pContext);
00092   std::string label=rLabel;
00093   if(label=="") label="Invariant";
00094   FD_DC("AttributeTimedState(" << this << ")::DoWrite(tr): to section " << label);
00095   if(!mInvariant.Empty())
00096     mInvariant.Write(rTw,label);
00097 }
00098 
00099 
00100 //DoRead(rTr,rLabel,pContext)
00101 void AttributeTimedState::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
00102   // call base first
00103   AttributeFlags::DoRead(rTr,"",pContext);
00104   // figure my section
00105   std::string label=rLabel;
00106   if(label=="") label="Invariant";
00107   FD_DC("AttributeTimedState(" << this << ")::DoRead(tr): from section " << label);
00108   // clear my data
00109   mInvariant.Clear();
00110   // test my section
00111   Token token;
00112   rTr.Peek(token);
00113   if(token.Type()!=Token::Begin)  return;
00114   if(token.StringValue()!=label) return;
00115   // read my section (can throw exceptions now)
00116   mInvariant.Read(rTr,label);
00117 }
00118 
00119 
00120 /*******************************
00121  * 
00122  * Implementation of AttributeTimedGlobal
00123  *
00124  */
00125 
00126 //DoWrite(rTw,rLabel,pContext);
00127 void AttributeTimedGlobal::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
00128   (void) pContext;
00129   if(IsDefault()) return;
00130   std::string label=rLabel;
00131   if(label=="") label="Clocks";
00132   FD_DC("AttributeTimedGlobal(" << this << ")::DoWrite(tr): to section " << label);
00133   mClocks.Write(rTw,label);
00134 }
00135 
00136 //DoRead(rTr,rLabel,pContext)
00137 void AttributeTimedGlobal::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
00138   std::string label=rLabel;
00139   if(label=="") label="Clocks";
00140   FD_DC("AttributeTimedGlobal(" << this << ")::DoRead(tr): from section " << label);
00141   (void) pContext;
00142   mClocks.Clear();
00143   Token token;
00144   rTr.Peek(token);
00145   if(token.Type()!=Token::Begin)  return;
00146   if(token.StringValue()!=label) return;
00147   mClocks.Read(rTr,label);
00148 }
00149 
00150 
00151 
00152 
00153 
00154 
00155 } // namespace faudes
00156 

Generated on Mon Nov 10 08:13:15 2008 for libFAUDES 2.11v by  doxygen 1.4.4