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
13namespace faudes {
14
15
16/*******************************
17 *
18 * Implementation of AttributeTimedTrans
19 *
20 */
21
22// faudes type std
23FAUDES_TYPE_IMPLEMENTATION(Void,AttributeTimedTrans,AttributeFlags)
24
25// Copy my members
26void AttributeTimedTrans::DoCopy(const AttributeTimedTrans& rSrcAttr) {
27 // call base (incl. virtual clear)
28 AttributeFlags::DoCopy(rSrcAttr);
29 // my additional members
30 mGuard=rSrcAttr.mGuard;
31 mResets=rSrcAttr.mResets;
32}
33
34// Copy my members
36 // we dont support mive
37 DoCopy(rSrcAttr);
38}
39
40// Equality
42 // base
43 if(!AttributeFlags::DoEqual(rOther)) return false;
44 // my members
45 if(mGuard!=rOther.mGuard) return false;
46 if(mResets!=rOther.mResets) return false;
47 // pass
48 return true;
49}
50
51
52//DoWrite(rTw,rLabel,pContext);
53void AttributeTimedTrans::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
54 if(IsDefault()) return;
55 AttributeFlags::DoWrite(rTw,"",pContext);
56 if(mGuard.Empty() && mResets.Empty()) return;
57 std::string label=rLabel;
58 FD_DC("AttributeTimedTrans(" << this << ")::DoWrite(tr): to section " << label);
59 if(label=="") label="Timing";
60 rTw.WriteBegin(label);
61 if(!mGuard.Empty())
62 mGuard.Write(rTw);
63 if(!mResets.Empty())
64 mResets.Write(rTw);
65 rTw.WriteEnd(label);
66}
67
68
69//DoRead(rTr,rLabel,pContext)
70void AttributeTimedTrans::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
71 // call base first
72 AttributeFlags::DoRead(rTr,"",pContext);
73 // find my section
74 std::string label=rLabel;
75 if(label=="") label="Timing";
76 FD_DC("AttributeTimedTrans(" << this << ")::DoRead(tr): from section " << label);
77 // initialise my data
78 mGuard.Clear();
79 mResets.Clear();
80 // test for my data
81 Token token;
82 rTr.Peek(token);
83 if(!token.IsBegin()) return;
84 if(token.StringValue()!=label) return;
85 // test read my data (could throw exceptions now)
86 rTr.ReadBegin(label);
87 while (rTr.Peek(token)) {
88 // 0: looking for "begin" only
89 if (token.Type() != Token::Begin) break;
90 // 1: guard
91 if (token.StringValue() == "Guard") {
92 mGuard.Read(rTr,"Guard");
93 continue;
94 }
95 // 2: resets
96 if (token.StringValue() == "Resets") {
97 mResets.Read(rTr,"Resets");
98 continue;
99 }
100 // 3:
101 std::stringstream errstr;
102 errstr << "invalid transition timing" << rTr.FileLine();
103 throw Exception("AttributeTimedTrans::Read", errstr.str(), 52);
104 }
105 mGuard.Name("Guard");
106 mResets.Name("Resets");
107 rTr.ReadEnd(label);
108}
109
110
111/*******************************
112 *
113 * Implementation of AttributeTimedState
114 *
115 */
116
117// faudes type std
119
120// Copy my members
121void AttributeTimedState::DoCopy(const AttributeTimedState& rSrcAttr) {
122 // call base (incl. virtual clear)
123 AttributeFlags::DoCopy(rSrcAttr);
124 // my additional members
125 mInvariant=rSrcAttr.mInvariant;
126}
127
128// Copy my members
130 // we dont support move
131 DoCopy(rSrcAttr);
132}
133
134// Equality
136 // base
137 if(!AttributeFlags::DoEqual(rOther)) return false;
138 // my members
139 if(mInvariant!=rOther.mInvariant) return false;
140 // pass
141 return true;
142}
143
144
145//DoWrite(rTw,rLabel,pContext);
146void AttributeTimedState::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
147 (void) pContext;
148 if(IsDefault()) return;
149 AttributeFlags::DoWrite(rTw,"",pContext);
150 std::string label=rLabel;
151 if(label=="") label="Invariant";
152 FD_DC("AttributeTimedState(" << this << ")::DoWrite(tr): to section " << label);
153 if(!mInvariant.Empty())
154 mInvariant.Write(rTw,label);
155}
156
157
158//DoRead(rTr,rLabel,pContext)
159void AttributeTimedState::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
160 // call base first
161 AttributeFlags::DoRead(rTr,"",pContext);
162 // figure my section
163 std::string label=rLabel;
164 if(label=="") label="Invariant";
165 FD_DC("AttributeTimedState(" << this << ")::DoRead(tr): from section " << label);
166 // clear my data
168 // test my section
169 Token token;
170 rTr.Peek(token);
171 if(!token.IsBegin()) return;
172 if(token.StringValue()!=label) return;
173 // read my section (can throw exceptions now)
174 mInvariant.Read(rTr,label);
175}
176
177
178/*******************************
179 *
180 * Implementation of AttributeTimedGlobal
181 *
182 */
183
184// faudes type std
186
187// Copy my members
188void AttributeTimedGlobal::DoCopy(const AttributeTimedGlobal& rSrcAttr) {
189 // call base (incl. virtual clear)
190 AttributeVoid::DoCopy(rSrcAttr);
191 // my additional members
192 mClocks=rSrcAttr.mClocks;
193 mpClockSymbolTable=rSrcAttr.mpClockSymbolTable;
194}
195
196// Copy my members
198 // call base (incl. virtual clear)
199 AttributeVoid::DoCopy(rSrcAttr);
200 // my additional members
201 mClocks.Move(rSrcAttr.mClocks);
203}
204
205// Equality
207 // my members
208 if(mClocks!=rOther.mClocks) return false;
209 // pass
210 return true;
211}
212
213//DoWrite(rTw,rLabel,pContext);
214void AttributeTimedGlobal::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
215 (void) pContext;
216 if(IsDefault()) return;
217 std::string label=rLabel;
218 if(label=="") label="Clocks";
219 FD_DC("AttributeTimedGlobal(" << this << ")::DoWrite(tr): to section " << label);
220 mClocks.Write(rTw,label);
221}
222
223//DoRead(rTr,rLabel,pContext)
224void AttributeTimedGlobal::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
225 std::string label=rLabel;
226 if(label=="") label="Clocks";
227 FD_DC("AttributeTimedGlobal(" << this << ")::DoRead(tr): from section " << label);
228 (void) pContext;
229 mClocks.Clear();
230 Token token;
231 rTr.Peek(token);
232 if(!token.IsBegin()) return;
233 if(token.StringValue()!=label) return;
234 mClocks.Read(rTr,label);
235}
236
237
238
239
240
241
242} // namespace faudes
243
#define FD_DC(message)
#define FAUDES_TYPE_IMPLEMENTATION(ftype, ctype, cbase)
Definition cfl_types.h:1017
void DoCopy(const AttrType &rSrc)
Definition cfl_types.h:1167
bool DoEqual(const AttributeFlags &rOther) const
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
void DoCopy(const AttributeFlags &rSrcAttr)
bool DoEqual(const AttributeTimedGlobal &rOther) const
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
virtual bool IsDefault(void) const
void DoMove(AttributeTimedGlobal &rSrcAttr)
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
void DoCopy(const AttributeTimedState &rSrcAttr)
void DoMove(AttributeTimedState &rSrcAttr)
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
bool DoEqual(const AttributeTimedState &rOther) const
virtual bool IsDefault(void) const
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
bool DoEqual(const AttributeTimedTrans &rOther) const
void DoCopy(const AttributeTimedTrans &rSrcAttr)
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
void DoMove(AttributeTimedTrans &rSrcAttr)
virtual bool IsDefault(void) const
const std::string & Name(void) const
void Read(const std::string &rFileName, const std::string &rLabel="TimeConstraint")
std::string Name(void) const
std::string FileLine(void) const
void ReadEnd(const std::string &rLabel)
void ReadBegin(const std::string &rLabel)
bool Peek(Token &token)
void WriteEnd(const std::string &rLabel)
void WriteBegin(const std::string &rLabel)
const std::string & StringValue(void) const
@ Begin
<label> (begin of section)
Definition cfl_token.h:84
bool IsBegin(void) const
TokenType Type(void) const
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
void Write(const Type *pContext=0) const
virtual Type & Move(Type &rSrc)
Definition cfl_types.cpp:89
bool Empty(void) const
virtual void Clear(void)

libFAUDES 2.34d --- 2026.03.11 --- c++ api documentaion by doxygen