hyb_attributes.cpp
Go to the documentation of this file.
1/** @file hyb_attributes.cpp Attributes of linear hybrid automata */
2
3/*
4 Hybrid systems plug-in for FAU Discrete Event Systems Library
5
6 Copyright (C) 2010 Thomas Moor
7
8*/
9
10
11#include "hyb_attributes.h"
12
13namespace faudes {
14
15
16/*******************************
17 *
18 * Implementation of AttributeLhaTrans
19 *
20 */
21
22// faudes type std
23FAUDES_TYPE_IMPLEMENTATION(Void,AttributeLhaTrans,AttributeFlags)
24
25// Copy my members
27 // call base (incl. virtual clear)
28 AttributeFlags::DoCopy(rSrcAttr);
29 // my additional members
30 mGuard=rSrcAttr.mGuard;
31 mReset=rSrcAttr.mReset;
32 return *this;
33}
34
35// Equality
37 // base
38 if(!AttributeFlags::DoEqual(rOther)) return false;
39 // my members
40 if(mGuard!=rOther.mGuard) return false;
41 if(mReset!=rOther.mReset) return false;
42 // pass
43 return true;
44}
45
46
47//DoWrite(rTw,rLabel,pContext);
48void AttributeLhaTrans::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
49 DoXWrite(rTw,rLabel,pContext);
50}
51
52//DoXWrite(rTw,rLabel,pContext);
53void AttributeLhaTrans::DoXWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
54 if(IsDefault()) return;
55 AttributeFlags::DoXWrite(rTw,"",pContext);
56 if(mGuard.Size()==0 && mReset.Identity()) return;
57 if(rLabel!="") rTw.WriteBegin(rLabel);
58 if(mGuard.Size()!=0)
59 mGuard.Write(rTw,"Guard");
60 if(!mReset.Identity())
61 mReset.Write(rTw,"Reset");
62 if(rLabel!="") rTw.WriteEnd(rLabel);
63}
64
65//DoRead(rTr,rLabel,pContext)
66void AttributeLhaTrans::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
67 // call base first
68 AttributeFlags::DoRead(rTr,"",pContext);
69 // initialise my data
70 mGuard.Clear();
71 mReset.Clear();
72 // if section specified, read begin label
73 if(rLabel!="") rTr.ReadBegin(rLabel);
74 // search my data
75 if(rTr.ExistsBegin("Guard"))
76 mGuard.Read(rTr,"Guard");
77 // search my data
78 if(rTr.ExistsBegin("Reset"))
79 mReset.Read(rTr,"Reset");
80 // if section specified, read end label
81 if(rLabel!="") rTr.ReadEnd(rLabel);
82}
83
84
85/*******************************
86 *
87 * Implementation of AttributeLhaState
88 *
89 */
90
91// faudes type std
93
94// Copy my members
96 // call base (incl. virtual clear)
97 AttributeFlags::DoCopy(rSrcAttr);
98 // my additional members
99 mInvariant=rSrcAttr.mInvariant;
100 mInitialConstraint=rSrcAttr.mInitialConstraint;
101 mRate= rSrcAttr.mRate;
102 return *this;
103}
104
105// Equality
107 // base
108 if(!AttributeFlags::DoEqual(rOther)) return false;
109 // my members
110 if(mInvariant!=rOther.mInvariant) return false;
111 if(mInitialConstraint!=rOther.mInitialConstraint) return false;
112 if(mRate!=rOther.mRate) return false;
113 // pass
114 return true;
115}
116
117
118//DoWrite(rTw,rLabel,pContext);
119void AttributeLhaState::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
120 DoXWrite(rTw,rLabel,pContext);
121}
122
123//DoXWrite(rTw,rLabel,pContext);
124void AttributeLhaState::DoXWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
125 if(IsDefault()) return;
126 AttributeFlags::DoXWrite(rTw,"",pContext);
127 if(rLabel!="") rTw.WriteBegin(rLabel);
128 if(mInvariant.Size()!=0)
129 mInvariant.Write(rTw,"Invariant");
130 if(mInitialConstraint.Size()!=0)
131 mInitialConstraint.Write(rTw,"InitialConstraint");
132 mRate.Write(rTw,"Rate");
133 if(rLabel!="") rTw.WriteEnd(rLabel);
134}
135
136//DoRead(rTr,rLabel,pContext)
137void AttributeLhaState::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
138 // call base first
139 AttributeFlags::DoRead(rTr,"",pContext);
140 // clear my data
143 mRate.Clear();
144 // if section specified, read begin label
145 if(rLabel!="") rTr.ReadBegin(rLabel);
146 // search my data
147 if(rTr.ExistsBegin("Invariant")) {
148 mInvariant.Read(rTr,"Invariant");
149 }
150 // search my data
151 if(rTr.ExistsBegin("InitialConstraint")) {
152 mInitialConstraint.Read(rTr,"InitialConstraint");
153 }
154 // search my data
155 if(rTr.ExistsBegin("Rate")) {
156 mRate.Read(rTr,"Rate");
157 } else {
158 std::stringstream errstr;
159 errstr << "invalid lha state [missing rate]" << rTr.FileLine();
160 throw Exception("AttributeLhaState::Read", errstr.str(), 52);
161 }
162 // if section specified, read end label
163 if(rLabel!="") rTr.ReadEnd(rLabel);
164}
165
166
167/*******************************
168 *
169 * Implementation of AttributeLhaGlobal
170 *
171 */
172
173// faudes type std
175
176// Copy my members
178 // call base (incl. virtual clear)
179 AttributeVoid::DoCopy(rSrcAttr);
180 // my additional members
181 mStateSpace=rSrcAttr.mStateSpace;
182 return *this;
183}
184
185// Equality
187 // my members
188 if(mStateSpace!=rOther.mStateSpace) return false;
189 // pass
190 return true;
191}
192
193//DoWrite(rTw,rLabel,pContext);
194void AttributeLhaGlobal::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
195 (void) pContext;
196 if(IsDefault()) return;
197 std::string label=rLabel;
198 if(label=="") label="LhaStateSpace";
199 FD_DC("AttributeLhaGlobal(" << this << ")::DoWrite(tr): to section " << label);
200 mStateSpace.Write(rTw,label);
201}
202
203//DoRead(rTr,rLabel,pContext)
204void AttributeLhaGlobal::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
205 std::string label=rLabel;
206 if(label=="") label="LhaStateSpace";
207 FD_DC("AttributeLhaGlobal(" << this << ")::DoRead(tr): from section " << label);
208 (void) pContext;
210 Token token;
211 rTr.Peek(token);
212 if(token.Type()!=Token::Begin) return;
213 if(token.StringValue()!=label) return;
214 mStateSpace.Read(rTr,label);
215}
216
217
218
219
220
221
222} // namespace faudes
223
#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 DoXWrite(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)
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
bool DoEqual(const AttributeLhaGlobal &rOther) const
virtual bool IsDefault(void) const
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
bool DoEqual(const AttributeLhaState &rOther) const
virtual void DoXWrite(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
bool DoEqual(const AttributeLhaTrans &rOther) const
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
virtual void DoXWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
virtual bool IsDefault(void) const
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
bool Identity(void) const
Idx Size(void) const
std::string FileLine(void) const
void ReadEnd(const std::string &rLabel)
void ReadBegin(const std::string &rLabel)
bool Peek(Token &token)
bool ExistsBegin(const std::string &rLabel)
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
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

libFAUDES 2.34e --- 2026.03.16 --- c++ api documentaion by doxygen