tp_attributes.cpp
Go to the documentation of this file.
1 /** @file tp_attributes.cpp Attributes for timed automata */
2 
3 
4 /* Timeplugin for FAU Discrete Event Systems Library (libfaudes)
5 
6  Copyright (C) 2007 Thomas Moor
7  Exclusive copyright is granted to Klaus Schmidt
8 
9 */
10 
11 #include "tp_attributes.h"
12 
13 namespace faudes {
14 
15 
16 /*******************************
17  *
18  * Implementation of AttributeTimedTrans
19  *
20  */
21 
22 // faudes type std
23 FAUDES_TYPE_IMPLEMENTATION(Void,AttributeTimedTrans,AttributeFlags)
24 
25 // Assign my members
26 void AttributeTimedTrans::DoAssign(const AttributeTimedTrans& rSrcAttr) {
27  // call base (incl. virtual clear)
28  AttributeFlags::DoAssign(rSrcAttr);
29  // my additional members
30  mGuard=rSrcAttr.mGuard;
31  mResets=rSrcAttr.mResets;
32 }
33 
34 // Equality
36  // base
37  if(!AttributeFlags::DoEqual(rOther)) return false;
38  // my members
39  if(mGuard!=rOther.mGuard) return false;
40  if(mResets!=rOther.mResets) return false;
41  // pass
42  return true;
43 }
44 
45 
46 //DoWrite(rTw,rLabel,pContext);
47 void AttributeTimedTrans::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
48  if(IsDefault()) return;
49  AttributeFlags::DoWrite(rTw,"",pContext);
50  if(mGuard.Empty() && mResets.Empty()) return;
51  std::string label=rLabel;
52  FD_DC("AttributeTimedTrans(" << this << ")::DoWrite(tr): to section " << label);
53  if(label=="") label="Timing";
54  rTw.WriteBegin(label);
55  if(!mGuard.Empty())
56  mGuard.Write(rTw);
57  if(!mResets.Empty())
58  mResets.Write(rTw);
59  rTw.WriteEnd(label);
60 }
61 
62 
63 //DoRead(rTr,rLabel,pContext)
64 void AttributeTimedTrans::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
65  // call base first
66  AttributeFlags::DoRead(rTr,"",pContext);
67  // find my section
68  std::string label=rLabel;
69  if(label=="") label="Timing";
70  FD_DC("AttributeTimedTrans(" << this << ")::DoRead(tr): from section " << label);
71  // initialise my data
72  mGuard.Clear();
73  mResets.Clear();
74  // test for my data
75  Token token;
76  rTr.Peek(token);
77  if(!token.IsBegin()) return;
78  if(token.StringValue()!=label) return;
79  // test read my data (could throw exceptions now)
80  rTr.ReadBegin(label);
81  while (rTr.Peek(token)) {
82  // 0: looking for "begin" only
83  if (token.Type() != Token::Begin) break;
84  // 1: guard
85  if (token.StringValue() == "Guard") {
86  mGuard.Read(rTr,"Guard");
87  continue;
88  }
89  // 2: resets
90  if (token.StringValue() == "Resets") {
91  mResets.Read(rTr,"Resets");
92  continue;
93  }
94  // 3:
95  std::stringstream errstr;
96  errstr << "invalid transition timing" << rTr.FileLine();
97  throw Exception("AttributeTimedTrans::Read", errstr.str(), 52);
98  }
99  mGuard.Name("Guard");
100  mResets.Name("Resets");
101  rTr.ReadEnd(label);
102 }
103 
104 
105 /*******************************
106  *
107  * Implementation of AttributeTimedState
108  *
109  */
110 
111 // faudes type std
113 
114 // Assign my members
115 void AttributeTimedState::DoAssign(const AttributeTimedState& rSrcAttr) {
116  // call base (incl. virtual clear)
117  AttributeFlags::DoAssign(rSrcAttr);
118  // my additional members
119  mInvariant=rSrcAttr.mInvariant;
120 }
121 
122 // Equality
124  // base
125  if(!AttributeFlags::DoEqual(rOther)) return false;
126  // my members
127  if(mInvariant!=rOther.mInvariant) return false;
128  // pass
129  return true;
130 }
131 
132 
133 //DoWrite(rTw,rLabel,pContext);
134 void AttributeTimedState::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
135  (void) pContext;
136  if(IsDefault()) return;
137  AttributeFlags::DoWrite(rTw,"",pContext);
138  std::string label=rLabel;
139  if(label=="") label="Invariant";
140  FD_DC("AttributeTimedState(" << this << ")::DoWrite(tr): to section " << label);
141  if(!mInvariant.Empty())
142  mInvariant.Write(rTw,label);
143 }
144 
145 
146 //DoRead(rTr,rLabel,pContext)
147 void AttributeTimedState::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
148  // call base first
149  AttributeFlags::DoRead(rTr,"",pContext);
150  // figure my section
151  std::string label=rLabel;
152  if(label=="") label="Invariant";
153  FD_DC("AttributeTimedState(" << this << ")::DoRead(tr): from section " << label);
154  // clear my data
155  mInvariant.Clear();
156  // test my section
157  Token token;
158  rTr.Peek(token);
159  if(!token.IsBegin()) return;
160  if(token.StringValue()!=label) return;
161  // read my section (can throw exceptions now)
162  mInvariant.Read(rTr,label);
163 }
164 
165 
166 /*******************************
167  *
168  * Implementation of AttributeTimedGlobal
169  *
170  */
171 
172 // faudes type std
174 
175 // Assign my members
176 void AttributeTimedGlobal::DoAssign(const AttributeTimedGlobal& rSrcAttr) {
177  // call base (incl. virtual clear)
178  AttributeVoid::DoAssign(rSrcAttr);
179  // my additional members
180  mClocks=rSrcAttr.mClocks;
181  mpClockSymbolTable=rSrcAttr.mpClockSymbolTable;
182 }
183 
184 // Equality
186  // my members
187  if(mClocks!=rOther.mClocks) return false;
188  // pass
189  return true;
190 }
191 
192 //DoWrite(rTw,rLabel,pContext);
193 void AttributeTimedGlobal::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
194  (void) pContext;
195  if(IsDefault()) return;
196  std::string label=rLabel;
197  if(label=="") label="Clocks";
198  FD_DC("AttributeTimedGlobal(" << this << ")::DoWrite(tr): to section " << label);
199  mClocks.Write(rTw,label);
200 }
201 
202 //DoRead(rTr,rLabel,pContext)
203 void AttributeTimedGlobal::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
204  std::string label=rLabel;
205  if(label=="") label="Clocks";
206  FD_DC("AttributeTimedGlobal(" << this << ")::DoRead(tr): from section " << label);
207  (void) pContext;
208  mClocks.Clear();
209  Token token;
210  rTr.Peek(token);
211  if(!token.IsBegin()) return;
212  if(token.StringValue()!=label) return;
213  mClocks.Read(rTr,label);
214 }
215 
216 
217 
218 
219 
220 
221 } // namespace faudes
222 
#define FD_DC(message)
Debug: optional report on container operations.
#define FAUDES_TYPE_IMPLEMENTATION(ftype, ctype, cbase)
faudes type implementation macros, overall
Definition: cfl_types.h:946
Boolean flags Attribute.
bool DoEqual(const AttributeFlags &rOther) const
Test equality of configuration data.
void DoAssign(const AttributeFlags &rSrcAttr)
Assignment method.
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Write to TokenWriter, see Type for public wrappers.
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Reads attribute from TokenReader, see Type for public wrappers.
Globat attribute with clockset.
bool DoEqual(const AttributeTimedGlobal &rOther) const
Test eaulity.
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Writes the attribute to TokenWriter, see AttributeVoid for public wrappers.
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Reads the attribute from TokenReader, see AttributeVoid for public wrappers.
virtual bool IsDefault(void) const
Test for default value (ie empty clockset)
State attribute with invariant.
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Writes the attribute to TokenWriter, see AttributeVoid for public wrappers.
TimeConstraint mInvariant
Invariant
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Reads the attribute from TokenReader, see AttributeVoid for public wrappers.
bool DoEqual(const AttributeTimedState &rOther) const
Test eaulity.
virtual bool IsDefault(void) const
Test for default value (ie empty invariant and default flags)
Transition Attribute with guard and resets.
Definition: tp_attributes.h:28
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Writes the attribute to TokenWriter, see AttributeVoid for public wrappers.
bool DoEqual(const AttributeTimedTrans &rOther) const
Test eaulity.
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Reads the attribute from TokenReader, see AttributeVoid for public wrappers.
TimeConstraint mGuard
Guard
Definition: tp_attributes.h:43
virtual bool IsDefault(void) const
Test for default value (ie empty constraint and default flags)
Definition: tp_attributes.h:43
Minimal Attribute.
void DoAssign(const AttributeVoid &rSrcAttr)
Assign attribute members.
Faudes exception class.
bool Empty(void) const
Checks if TimeConstraint containts no ElemConstraints.
void Read(const std::string &rFileName, const std::string &rLabel="TimeConstraint")
Read from file.
std::string Name(void) const
Return name of Constraint.
void Clear(void)
Clear all.
void Write(void) const
Write to console.
A TokenReader reads sequential tokens from a file or string.
std::string FileLine(void) const
Return "filename:line".
void ReadEnd(const std::string &rLabel)
Close the current section by matching the previous ReadBegin().
void ReadBegin(const std::string &rLabel)
Open a section by specified label.
bool Peek(Token &token)
Peek next token.
A TokenWriter writes sequential tokens to a file, a string or stdout.
void WriteEnd(const std::string &rLabel)
Write end label.
void WriteBegin(const std::string &rLabel)
Write begin label.
Tokens model atomic data for stream IO.
Definition: cfl_token.h:53
const std::string & StringValue(void) const
Get string value of a name token.
Definition: cfl_token.cpp:177
@ Begin
<label> (begin of section)
Definition: cfl_token.h:83
bool IsBegin(void) const
Test token Type.
Definition: cfl_token.cpp:258
TokenType Type(void) const
Get token Type.
Definition: cfl_token.cpp:198
Base class of all libFAUDES objects that participate in the run-time interface.
Definition: cfl_types.h:239
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
Read configuration data from file with label specified.
Definition: cfl_types.cpp:261
void Write(const Type *pContext=0) const
Write configuration data to console.
Definition: cfl_types.cpp:139
bool Empty(void) const
Test whether if the TBaseSet is Empty.
Definition: cfl_baseset.h:1824
virtual void Clear(void)
Clear all set.
Definition: cfl_baseset.h:1902
const std::string & Name(void) const
Return name of TBaseSet.
Definition: cfl_baseset.h:1755
libFAUDES resides within the namespace faudes.
Attributes for timed automata.

libFAUDES 2.32b --- 2024.03.01 --- c++ api documentaion by doxygen