sp_simconditionset.cpp
Go to the documentation of this file.
1/** @file sp_simconditionset.cpp Set of named simulation conditions */
2
3
4/*
5 Copyright (C) 2008 Thomas Moor
6 Exclusive copyright is granted to Klaus Schmidt
7*/
8
10#include "sp_lpexecutor.h"
11
12namespace faudes {
13
14/*
15************************************************
16************************************************
17************************************************
18
19implementation of attributes
20
21************************************************
22************************************************
23************************************************
24*/
25
26
27
28
29// faudes type std
30FAUDES_TYPE_IMPLEMENTATION(Void,AttributeSimCondition,AttributeFlags)
31
32
33// construct
36 mEventCondition(false),
37 mStateCondition(false)
38{
39 FD_DX("AttributeSimCondition::AttributeSimCondition()");
40 mFlags=mDefSCFlags;
41 Reset();
42}
43
44// construct
47 mEventCondition(false),
48 mStateCondition(false)
49{
50 FD_DX("AttributeSimCondition::AttributeSimCondition(attr)");
51 DoCopy(rOther);
52}
53
54// Copy my members
56 // call base (incl. virtual clear)
57 AttributeFlags::DoCopy(rSrcAttr);
58 // my additional members
63 // my state
64 mSatisfied=false;
68}
69
70// Copy my members
72 // not supported
73 DoCopy(rSrcAttr);
74}
75
76
77// Test for equality
79 // call base (incl. virtual clear)
80 if(!AttributeFlags::DoEqual(rAttr)) return false;
81 // test my defining members
82 if(mEventCondition!=rAttr.mEventCondition) return false;
83 if(mStateCondition!=rAttr.mStateCondition) return false;
84 if(!(mEventConditionAttribute==rAttr.mEventConditionAttribute)) return false;
85 if(!(mStateConditionAttribute==rAttr.mStateConditionAttribute)) return false;
86 // pass
87 return true;
88}
89
90
91//DoWrite(rTw);
92void AttributeSimCondition::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
93 (void) rLabel;
94 Token token;
95
96 // report context
97 FD_DC("AttributeSimCondition::DoWrite(rTr," << rLabel <<", " << pContext << "): cast " <<
98 dynamic_cast<const ParallelExecutor*>(pContext));
99
100 // write event condition
101 if(mEventCondition) {
102 rTw.WriteBegin("EventCondition");
103 if(Enabled()) rTw.WriteOption("Enabled");
104 if(!Enabled()) rTw.WriteOption("Disabled");
105 if(Breakpoint()) rTw.WriteOption("Break");
106 mEventConditionAttribute.mStart.Write(rTw,"StartEvents");
107 mEventConditionAttribute.mStop.Write(rTw,"StopEvents");
108 rTw.WriteEnd("EventCondition");
109 }
110
111 // write state condition
112 if(mStateCondition) {
113 rTw.WriteBegin("StateCondition");
114 if(Enabled()) rTw.WriteOption("Enabled");
115 if(!Enabled()) rTw.WriteOption("Disabled");
116 if(Breakpoint()) rTw.WriteOption("Break");
117 if(mStateConditionAttribute.mAllFlag) rTw.WriteOption("Conjunction");
118 if(!mStateConditionAttribute.mAllFlag) rTw.WriteOption("Disjunction");
119 // get context
120 const ParallelExecutor* executor= dynamic_cast<const ParallelExecutor*>(pContext);
122 // test context
123 if(executor)
124 if(executor->Size()!=n) {
125 std::stringstream errstr;
126 errstr << "Invalid ParalleExecutor context (dimension mismatch)";
127 throw Exception("AttributeSimCondition::DoWrite", errstr.str(), 501);
128 }
129 // write the sets
130 for(Idx i=0; i<n; i++) {
132 if(executor) executor->At(i).Generator().WriteStateSet(rTw,set);
133 else set.Write(rTw,"StateSet");
134 }
135 rTw.WriteEnd("StateCondition");
136 }
137}
138
139//DoRead(rTr)
140void AttributeSimCondition::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
141 (void) rLabel;
142 bool err;
143 Token token;
144
145 // report context
146 FD_DC("AttributeSimCondition::DoRead(rTr," << rLabel <<", " << pContext << "): cast " <<
147 dynamic_cast<const ParallelExecutor*>(pContext));
148
149 // clear myself
150 err=false;
151 mEventCondition=false;
152 mStateCondition=false;
153 Enabled(true);
154 Breakpoint(false);
159
160 // switch by toke
161 rTr.Peek(token);
162
163 // read event condition
164 if(token.Type()==Token::Begin && token.StringValue()=="EventCondition") {
165 rTr.ReadBegin("EventCondition");
166 mEventCondition=true;
167 while(!rTr.Eos("EventCondition")) {
168 rTr.Peek(token);
169 if((token.IsOption()) && (token.OptionValue()=="Enabled")) {
170 Enabled(true);
171 rTr.Get(token);
172 continue;
173 }
174 if((token.IsOption()) && (token.OptionValue()=="Disabled")) {
175 Enabled(false);
176 rTr.Get(token);
177 continue;
178 }
179 if((token.IsOption()) && (token.OptionValue()=="Break")) {
180 Breakpoint(true);
181 rTr.Get(token);
182 continue;
183 }
184 if((token.IsBegin()) && (token.StringValue()=="StartEvents")) {
185 mEventConditionAttribute.mStart.Read(rTr,"StartEvents");
186 continue;
187 }
188 if((token.IsBegin()) && (token.StringValue()=="StopEvents")) {
189 mEventConditionAttribute.mStop.Read(rTr,"StopEvents");
190 continue;
191 }
192 // ignore errors
193 rTr.Get(token);
194 }
195 rTr.ReadEnd("EventCondition");
196 }
197
198 // read state condition
199 if(token.Type()==Token::Begin && token.StringValue()=="StateCondition") {
200 rTr.ReadBegin("StateCondition");
201 mStateCondition=true;
202 while(!rTr.Eos("StateCondition")) {
203 rTr.Peek(token);
204 if((token.IsOption()) && (token.OptionValue()=="Enabled")) {
205 Enabled(true);
206 rTr.Get(token);
207 continue;
208 }
209 if((token.IsOption()) && (token.OptionValue()=="Disabled")) {
210 Enabled(false);
211 rTr.Get(token);
212 continue;
213 }
214 if((token.IsOption()) && (token.OptionValue()=="Break")) {
215 Breakpoint(true);
216 rTr.Get(token);
217 continue;
218 }
219 if((token.IsOption()) && (token.OptionValue()=="Conjunction")) {
221 rTr.Get(token);
222 continue;
223 }
224 if((token.IsBegin()) && (token.StringValue()=="StateSet")) {
225 // get context
226 const ParallelExecutor* executor= dynamic_cast<const ParallelExecutor*>(pContext);
228 // test context
229 if(executor)
230 if(executor->Size()<=i) {
231 std::stringstream errstr;
232 errstr << "Invalid ParalleExecutor context (dimension mismatch)";
233 throw Exception("AttributeSimCondition::DoRead", errstr.str(), 501);
234 }
235 // read the set
236 StateSet set;
237 if(executor) executor->At(i).Generator().ReadStateSet(rTr,"StateSet",set);
238 else set.Read(rTr,"StateSet");
239 set.Name("StateSet");
241 continue;
242 }
243 // ignore errors
244 rTr.Get(token);
245 }
246 rTr.ReadEnd("StateCondition");
247 }
248 // report error
249 if(err) {
250 std::stringstream errstr;
251 errstr << "invalid simulation condition" << rTr.FileLine();
252 throw Exception("AttributeSimCondition::Read", errstr.str(), 52);
253 }
254}
255
256// condition state: sample
258 if(on==mSatisfied) return;
259 mSatisfied=on;
260 // newly activated
261 if(mSatisfied) {
263 mActivationTime=now;
264 }
265 // newly deactivated
266 if(!mSatisfied) {
268 }
269}
270
271
272/*
273************************************************
274************************************************
275************************************************
276
277implementation of condition set
278
279************************************************
280************************************************
281************************************************
282*/
283
284// std faudes type (except new)
290
291
292// Default constructor
294 FD_DX("SimConditionSet::SimConditionSet()");
295}
296
297// Copy constructor
299 FD_DX("SimConditionSet::SimConditionSet()");
300}
301
302
303// std faudes new
307 return res;
308}
309
310// get enabled set
312 SimConditionSet result;
313 for(Iterator cit=Begin(); cit != End(); ++cit)
314 if(Enabled(*cit)) result.Insert(*cit,Attribute(*cit));
315 return result;
316}
317
318// condition state: reset alls
320 FD_DX("SimConditionSet::Reset()");
321 for(Iterator cit=Begin(); cit != End(); ++cit) {
323 pattr->Reset();
324 pattr->mSamplesPeriod.Name(SymbolicName(*cit)+" - Period");
325 pattr->mSamplesDuration.Name(SymbolicName(*cit)+" - Duration");
326 }
327 FD_DX("SimConditionSet::Reset(): done");
328}
329
330
331
332} // namespace faudes
333
#define FD_DC(message)
#define FAUDES_TYPE_IMPLEMENTATION(ftype, ctype, cbase)
Definition cfl_types.h:1017
#define FAUDES_TYPE_IMPLEMENTATION_MOVE(ftype, ctype, cbase)
Definition cfl_types.h:959
#define FAUDES_TYPE_IMPLEMENTATION_EQUAL(ftype, ctype, cbase)
Definition cfl_types.h:967
#define FAUDES_TYPE_IMPLEMENTATION_CAST(ftype, ctype, cbase)
Definition cfl_types.h:948
#define FAUDES_TYPE_IMPLEMENTATION_ASSIGN(ftype, ctype, cbase)
Definition cfl_types.h:951
#define FAUDES_TYPE_IMPLEMENTATION_NEWCOPY(ftype, ctype, cbase)
Definition cfl_types.h:946
bool DoEqual(const AttributeFlags &rOther) const
void DoCopy(const AttributeFlags &rSrcAttr)
bool DoEqual(const AttributeSimCondition &rAttr) const
void DoMove(AttributeSimCondition &rSrcAttr)
SimEventCondition mEventConditionAttribute
SampledDensityFunction mSamplesDuration
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
SimStateCondition mStateConditionAttribute
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
void DoCopy(const AttributeSimCondition &rSrcAttr)
SampledDensityFunction mSamplesPeriod
const std::string & Name(void) const
void Generator(const TimedGenerator &rGen)
const std::string & Name(void) const
void SymbolicName(Idx index, const std::string &rName)
SymbolTable * mpSymbolTable
const Executor & At(int i) const
bool Enabled(Idx cond) const
SimConditionSet EnabledConditions(void)
std::vector< StateSet > mStateSets
virtual bool Insert(const Idx &rIndex)
AttributeSimCondition * Attributep(const Idx &rElem)
const AttributeSimCondition & Attribute(const Idx &rElem) const
std::string FileLine(void) const
bool Eos(const std::string &rLabel)
void ReadEnd(const std::string &rLabel)
void ReadBegin(const std::string &rLabel)
bool Get(Token &token)
bool Peek(Token &token)
void WriteEnd(const std::string &rLabel)
void WriteBegin(const std::string &rLabel)
void WriteOption(const std::string &rOpt)
const std::string & StringValue(void) const
@ Begin
<label> (begin of section)
Definition cfl_token.h:84
bool IsBegin(void) const
const std::string & OptionValue(void) const
bool IsOption(void) const
TokenType Type(void) const
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
virtual Type * New(void) const
Definition cfl_types.cpp:54
void Write(const Type *pContext=0) const
virtual void Clear(void)
Iterator End(void) const
Iterator Begin(void) const
uint32_t Idx
#define FD_DX(message)
Definition sp_executor.h:27

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