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 
13 namespace faudes {
14 
15 
16 /*******************************
17  *
18  * Implementation of AttributeLhaTrans
19  *
20  */
21 
22 // faudes type std
23 FAUDES_TYPE_IMPLEMENTATION(Void,AttributeLhaTrans,AttributeFlags)
24 
25 // Assign my members
27  // call base (incl. virtual clear)
28  AttributeFlags::DoAssign(rSrcAttr);
29  // my additional members
30  mGuard=rSrcAttr.mGuard;
31  mReset=rSrcAttr.mReset;
32  return *this;
33 }
34 
35 // Equality
36 bool AttributeLhaTrans::DoEqual(const AttributeLhaTrans& rOther) const {
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);
48 void AttributeLhaTrans::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
49  DoXWrite(rTw,rLabel,pContext);
50 }
51 
52 //DoXWrite(rTw,rLabel,pContext);
53 void 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)
66 void 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 // Assign my members
96  // call base (incl. virtual clear)
97  AttributeFlags::DoAssign(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);
119 void AttributeLhaState::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
120  DoXWrite(rTw,rLabel,pContext);
121 }
122 
123 //DoXWrite(rTw,rLabel,pContext);
124 void 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)
137 void AttributeLhaState::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
138  // call base first
139  AttributeFlags::DoRead(rTr,"",pContext);
140  // clear my data
141  mInvariant.Clear();
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 // Assign my members
178  // call base (incl. virtual clear)
179  AttributeVoid::DoAssign(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);
194 void 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)
204 void 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;
209  mStateSpace.Clear();
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)
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.
virtual void DoXWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Write to TokenWriter, see Type for public wrappers.
void DoAssign(const AttributeFlags &rSrcAttr)
Assignment method.
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Reads attribute from TokenReader, see Type for public wrappers.
Linear hybrid automata globat attribute to specify the overall state space.
Polyhedron mStateSpace
Continuous states.
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Reads the attribute from TokenReader, see AttributeVoid for public wrappers.
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 AttributeLhaGlobal &rOther) const
Test eaulity.
virtual bool IsDefault(void) const
Test for default value (never)
Linear hybrid automata state attribute with invariant, rates and optional initial state constraint.
Polyhedron mInitialConstraint
Initial state constraint
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Writes the attribute to TokenWriter, see AttributeVoid for public wrappers.
Polyhedron mInvariant
Invariant
bool DoEqual(const AttributeLhaState &rOther) const
Test eaulity.
virtual void DoXWrite(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 (never)
Linear hybrid automata transition attribute with guard and resets.
bool DoEqual(const AttributeLhaTrans &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.
LinearRelation mReset
Resets.
virtual void DoXWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Writes the attribute to TokenWriter, see AttributeVoid for public wrappers.
virtual bool IsDefault(void) const
Test for default value.
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Reads the attribute from TokenReader, see AttributeVoid for public wrappers.
Minimal Attribute.
void DoAssign(const AttributeVoid &rSrcAttr)
Assign attribute members.
Faudes exception class.
void Clear(void)
Clear all.
bool Identity(void) const
Test for data format.
Idx Size(void) const
Get size.
void Clear(void)
Clear all.
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.
bool ExistsBegin(const std::string &rLabel)
Search for specified element.
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
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
libFAUDES resides within the namespace faudes.

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