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 DoAssign(rOther);
52}
53
54// Assign my members
56 // call base (incl. virtual clear)
58 // my additional members
63 // my state
64 mSatisfied=false;
68}
69
70
71// Test for equality
73 // call base (incl. virtual clear)
74 if(!AttributeFlags::DoEqual(rAttr)) return false;
75 // test my defining members
76 if(mEventCondition!=rAttr.mEventCondition) return false;
77 if(mStateCondition!=rAttr.mStateCondition) return false;
78 if(!(mEventConditionAttribute==rAttr.mEventConditionAttribute)) return false;
79 if(!(mStateConditionAttribute==rAttr.mStateConditionAttribute)) return false;
80 // pass
81 return true;
82}
83
84
85//DoWrite(rTw);
86void AttributeSimCondition::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
87 (void) rLabel;
88 Token token;
89
90 // report context
91 FD_DC("AttributeSimCondition::DoWrite(rTr," << rLabel <<", " << pContext << "): cast " <<
92 dynamic_cast<const ParallelExecutor*>(pContext));
93
94 // write event condition
95 if(mEventCondition) {
96 rTw.WriteBegin("EventCondition");
97 if(Enabled()) rTw.WriteOption("Enabled");
98 if(!Enabled()) rTw.WriteOption("Disabled");
99 if(Breakpoint()) rTw.WriteOption("Break");
100 mEventConditionAttribute.mStart.Write(rTw,"StartEvents");
101 mEventConditionAttribute.mStop.Write(rTw,"StopEvents");
102 rTw.WriteEnd("EventCondition");
103 }
104
105 // write state condition
106 if(mStateCondition) {
107 rTw.WriteBegin("StateCondition");
108 if(Enabled()) rTw.WriteOption("Enabled");
109 if(!Enabled()) rTw.WriteOption("Disabled");
110 if(Breakpoint()) rTw.WriteOption("Break");
111 if(mStateConditionAttribute.mAllFlag) rTw.WriteOption("Conjunction");
112 if(!mStateConditionAttribute.mAllFlag) rTw.WriteOption("Disjunction");
113 // get context
114 const ParallelExecutor* executor= dynamic_cast<const ParallelExecutor*>(pContext);
116 // test context
117 if(executor)
118 if(executor->Size()!=n) {
119 std::stringstream errstr;
120 errstr << "Invalid ParalleExecutor context (dimension mismatch)";
121 throw Exception("AttributeSimCondition::DoWrite", errstr.str(), 501);
122 }
123 // write the sets
124 for(Idx i=0; i<n; i++) {
126 if(executor) executor->At(i).Generator().WriteStateSet(rTw,set);
127 else set.Write(rTw,"StateSet");
128 }
129 rTw.WriteEnd("StateCondition");
130 }
131}
132
133//DoRead(rTr)
134void AttributeSimCondition::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
135 (void) rLabel;
136 bool err;
137 Token token;
138
139 // report context
140 FD_DC("AttributeSimCondition::DoRead(rTr," << rLabel <<", " << pContext << "): cast " <<
141 dynamic_cast<const ParallelExecutor*>(pContext));
142
143 // clear myself
144 err=false;
145 mEventCondition=false;
146 mStateCondition=false;
147 Enabled(true);
148 Breakpoint(false);
153
154 // switch by toke
155 rTr.Peek(token);
156
157 // read event condition
158 if(token.Type()==Token::Begin && token.StringValue()=="EventCondition") {
159 rTr.ReadBegin("EventCondition");
160 mEventCondition=true;
161 while(!rTr.Eos("EventCondition")) {
162 rTr.Peek(token);
163 if((token.IsOption()) && (token.OptionValue()=="Enabled")) {
164 Enabled(true);
165 rTr.Get(token);
166 continue;
167 }
168 if((token.IsOption()) && (token.OptionValue()=="Disabled")) {
169 Enabled(false);
170 rTr.Get(token);
171 continue;
172 }
173 if((token.IsOption()) && (token.OptionValue()=="Break")) {
174 Breakpoint(true);
175 rTr.Get(token);
176 continue;
177 }
178 if((token.IsBegin()) && (token.StringValue()=="StartEvents")) {
179 mEventConditionAttribute.mStart.Read(rTr,"StartEvents");
180 continue;
181 }
182 if((token.IsBegin()) && (token.StringValue()=="StopEvents")) {
183 mEventConditionAttribute.mStop.Read(rTr,"StopEvents");
184 continue;
185 }
186 // ignore errors
187 rTr.Get(token);
188 }
189 rTr.ReadEnd("EventCondition");
190 }
191
192 // read state condition
193 if(token.Type()==Token::Begin && token.StringValue()=="StateCondition") {
194 rTr.ReadBegin("StateCondition");
195 mStateCondition=true;
196 while(!rTr.Eos("StateCondition")) {
197 rTr.Peek(token);
198 if((token.IsOption()) && (token.OptionValue()=="Enabled")) {
199 Enabled(true);
200 rTr.Get(token);
201 continue;
202 }
203 if((token.IsOption()) && (token.OptionValue()=="Disabled")) {
204 Enabled(false);
205 rTr.Get(token);
206 continue;
207 }
208 if((token.IsOption()) && (token.OptionValue()=="Break")) {
209 Breakpoint(true);
210 rTr.Get(token);
211 continue;
212 }
213 if((token.IsOption()) && (token.OptionValue()=="Conjunction")) {
215 rTr.Get(token);
216 continue;
217 }
218 if((token.IsBegin()) && (token.StringValue()=="StateSet")) {
219 // get context
220 const ParallelExecutor* executor= dynamic_cast<const ParallelExecutor*>(pContext);
222 // test context
223 if(executor)
224 if(executor->Size()<=i) {
225 std::stringstream errstr;
226 errstr << "Invalid ParalleExecutor context (dimension mismatch)";
227 throw Exception("AttributeSimCondition::DoRead", errstr.str(), 501);
228 }
229 // read the set
230 StateSet set;
231 if(executor) executor->At(i).Generator().ReadStateSet(rTr,"StateSet",set);
232 else set.Read(rTr,"StateSet");
233 set.Name("StateSet");
235 continue;
236 }
237 // ignore errors
238 rTr.Get(token);
239 }
240 rTr.ReadEnd("StateCondition");
241 }
242 // report error
243 if(err) {
244 std::stringstream errstr;
245 errstr << "invalid simulation condition" << rTr.FileLine();
246 throw Exception("AttributeSimCondition::Read", errstr.str(), 52);
247 }
248}
249
250// condition state: sample
252 if(on==mSatisfied) return;
253 mSatisfied=on;
254 // newly activated
255 if(mSatisfied) {
257 mActivationTime=now;
258 }
259 // newly deactivated
260 if(!mSatisfied) {
262 }
263}
264
265
266/*
267************************************************
268************************************************
269************************************************
270
271implementation of condition set
272
273************************************************
274************************************************
275************************************************
276*/
277
278// std faudes type (except new)
283
284
285// Default constructor
287 FD_DX("SimConditionSet::SimConditionSet()");
288}
289
290// Copy constructor
292 FD_DX("SimConditionSet::SimConditionSet()");
293}
294
295
296// std faudes new
300 return res;
301}
302
303// get enabled set
305 SimConditionSet result;
306 for(Iterator cit=Begin(); cit != End(); ++cit)
307 if(Enabled(*cit)) result.Insert(*cit,Attribute(*cit));
308 return result;
309}
310
311// condition state: reset alls
313 FD_DX("SimConditionSet::Reset()");
314 for(Iterator cit=Begin(); cit != End(); ++cit) {
316 pattr->Reset();
317 pattr->mSamplesPeriod.Name(SymbolicName(*cit)+" - Period");
318 pattr->mSamplesDuration.Name(SymbolicName(*cit)+" - Duration");
319 }
320 FD_DX("SimConditionSet::Reset(): done");
321}
322
323
324
325} // namespace faudes
326
#define FD_DC(message)
#define FAUDES_TYPE_IMPLEMENTATION(ftype, ctype, cbase)
Definition cfl_types.h:958
#define FAUDES_TYPE_IMPLEMENTATION_EQUAL(ftype, ctype, cbase)
Definition cfl_types.h:916
#define FAUDES_TYPE_IMPLEMENTATION_COPY(ftype, ctype, cbase)
Definition cfl_types.h:903
#define FAUDES_TYPE_IMPLEMENTATION_CAST(ftype, ctype, cbase)
Definition cfl_types.h:905
#define FAUDES_TYPE_IMPLEMENTATION_ASSIGN(ftype, ctype, cbase)
Definition cfl_types.h:908
bool DoEqual(const AttributeFlags &rOther) const
void DoAssign(const AttributeFlags &rSrcAttr)
bool DoEqual(const AttributeSimCondition &rAttr) const
void DoAssign(const 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
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.33k --- 2025.09.16 --- c++ api documentaion by doxygen