SIMLIB/C++ 3.09
Loading...
Searching...
No Matches
cond.cc
Go to the documentation of this file.
1/////////////////////////////////////////////////////////////////////////////
2//! \file cond.cc State conditions
3//
4// Copyright (c) 1991-2004 Petr Peringer
5//
6// This library is licensed under GNU Library GPL. See the file COPYING.
7//
8
9//
10// description: continuous system - state conditions
11//
12
13////////////////////////////////////////////////////////////////////////////
14// interface
15//
16
17#include "simlib.h"
18#include "internal.h"
19
20namespace simlib3 {
21
22
23////////////////////////////////////////////////////////////////////////////
24// implementation
25//
26
28
29
30bool SIMLIB_ConditionFlag = false; // condition vector changed
31aCondition *aCondition::First = 0; // condition list
32
33////////////////////////////////////////////////////////////////////////////
34// aCondition implementation
35//
37 Next(First)
38{
39 First = this;
40}
41
43 if (this==First)
44 First = Next;
45 else
46 {
47 aCondition *i;
48 for(i=First; i && i->Next!=this; i=i->Next) { /*empty*/ }
49 if (i) i->Next = Next;
50 }
51}
52
53////////////////////////////////////////////////////////////////////////////
54// aCondition::InitAll -- initialize all conditions
55//
58 for(aCondition *i=First; i; i=i->Next)
59 i->Init();
60}
61
62////////////////////////////////////////////////////////////////////////////
63// aCondition::SetAll
64//
66 for(aCondition *i=First; i; i=i->Next)
67 i->SetNewStatus();
68}
69
70bool aCondition::isAny() { return First!=0; }
71
72////////////////////////////////////////////////////////////////////////////
73// Condition implementation
74//
76 in(i),
77 cc(0),
78 ccl(0)
79{
80}
81
83{
84}
85
86////////////////////////////////////////////////////////////////////////////
87// Condition::Init -- initialize
88//
90{
91 cc = ccl = 0;
92}
93
94////////////////////////////////////////////////////////////////////////////
95// Condition::SetNewStatus -- set new status of condition
96//
98{
99 ccl = cc;
100}
101
102
103////////////////////////////////////////////////////////////////////////////
104/// Condition::operator ()
105//
107 bool x = (in.Value()>=0.0);
108 if(SIMLIB_DynamicFlag) // inside numerical integration step
109 {
110 cc = x; // new condition status
111 if(Change()) { // is change of status?
112 SIMLIB_ConditionFlag = true; // global change flag
113 ContractStep(); // need to step contraction
114 }
115 return false; // test only
116 }
117 return Change(); // do actions if changed
118}
119
120////////////////////////////////////////////////////////////////////////////
121// test or action
122//
124{
125 SIMLIB_ConditionFlag = false;
126 for(aCondition *i=aCondition::First; i ; i=i->Next)
127 if(i->Test()) SIMLIB_ConditionFlag = true;
128}
129
131{
132 for(aCondition *i=aCondition::First; i ; i=i->Next)
133 if(i->Test()) i->Action(); /// Change???? ### !!!!
134}
135
136////////////////////////////////////////////////////////////////////////////
137// SIMLIB_DoConditions -- perform reactions to condition change
138//
140{
141 // precondition: SIMLIB_DynamicFlag = false;
143 {
144 void SampleDelays(); // needs something better ###
145 SampleDelays();
146
147 aCondition::AllActions(); // perform reactions to condition change
148 aCondition::SetAll(); // register new status
149 SIMLIB_ResetStatus = true; // ??? always reset integration method ???
150 }
151}
152
153#if 0
154////////////////////////////////////////////////////////////////////////////
155/// get name of object
156const char *Condition::Name() const {
157 if(HasName()) return _name;
158 else return SIMLIB_create_tmp_name("Condition{%p}", this);
159}
160
161////////////////////////////////////////////////////////////////////////////
162/// get name of object
163const char *ConditionUp::Name() const {
164 if(HasName()) return _name;
165 else return SIMLIB_create_tmp_name("ConditionUp{%p}", this);
166}
167
168////////////////////////////////////////////////////////////////////////////
169/// get name of object
170const char *ConditionDown::Name() const {
171 if(HasName()) return _name;
172 else return SIMLIB_create_tmp_name("ConditionDown{%p}", this);
173}
174#endif
175
176} // namespace
177
Condition(Input i)
Definition: cond.cc:75
virtual void SetNewStatus() override
update
Definition: cond.cc:97
virtual bool Test() override
Condition::operator ()
Definition: cond.cc:106
unsigned char ccl
old state
Definition: simlib.h:1509
unsigned char cc
state
Definition: simlib.h:1508
virtual void Init() override
initialize
Definition: cond.cc:89
continuous block connection (transparent reference) wrapper for pointer to objects of aContiBlock der...
Definition: simlib.h:895
double Value() const
get target block value
Definition: simlib.h:931
bool HasName() const
Definition: simlib.h:321
virtual std::string Name() const
get object name
Definition: object.cc:134
abstract base class for all state-condition blocks State event in combined model is executed at the t...
Definition: simlib.h:1484
aCondition * Next
Definition: simlib.h:1486
static void InitAll()
Definition: cond.cc:56
static aCondition * First
Definition: simlib.h:1485
static void TestAll()
Definition: cond.cc:123
static bool isAny()
Definition: cond.cc:70
static void AllActions()
Definition: cond.cc:130
static void SetAll()
Definition: cond.cc:65
Internal header file for SIMLIB/C++.
Implementation of class CalendarList interface is static - using global functions in SQS namespace.
Definition: algloop.cc:32
bool SIMLIB_DynamicFlag
in dynamic section
Definition: intg.cc:56
bool SIMLIB_ConditionFlag
Definition: cond.cc:30
SIMLIB_IMPLEMENTATION
Definition: algloop.cc:34
void SampleDelays()
Definition: run.cc:92
std::string SIMLIB_create_tmp_name(const char *fmt,...)
printf-like function to create temporary name (the length of temporary names is limited) used only ...
Definition: name.cc:80
bool SIMLIB_ResetStatus
flag set if there is a need for integration method restart
Definition: intg.cc:86
void SIMLIB_DoConditions()
Definition: cond.cc:139
void ContractStep()
contract step of integration
Definition: intg.cc:64
Main SIMLIB/C++ interface.