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// Assign my members
26void AttributeTimedTrans::DoAssign(const AttributeTimedTrans& rSrcAttr) {
27 // call base (incl. virtual clear)
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);
47void 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)
64void 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
115void 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);
134void 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)
147void 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
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
176void 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);
193void 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)
203void 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)
#define FAUDES_TYPE_IMPLEMENTATION(ftype, ctype, cbase)
Definition cfl_types.h:958
void DoAssign(const AttrType &rSrc)
Definition cfl_types.h:1094
bool DoEqual(const AttributeFlags &rOther) const
void DoAssign(const AttributeFlags &rSrcAttr)
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)
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
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)
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
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
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
bool Empty(void) const
virtual void Clear(void)

libFAUDES 2.33k --- 2025.09.16 --- c++ api documentaion by doxygen