MicroModelicaCCompiler  4.5.3
event.hpp
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  This file is part of QSS Solver.
4 
5  QSS Solver is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  QSS Solver is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with QSS Solver. If not, see <http://www.gnu.org/licenses/>.
17 
18  ******************************************************************************/
19 
20 #pragma once
21 
22 #include <ast/ast_types.hpp>
23 #include <util/table.hpp>
24 #include <ir/equation.hpp>
25 #include <ir/statement.hpp>
26 
27 namespace MicroModelica {
28 namespace IR {
29 
30 namespace EVENT {
31 
32 typedef enum {
33  Zero = 0,
34  Positive = 1,
35  Negative = 2
36 } Type;
37 
42 typedef enum {
43  LT,
44  LE,
45  GT,
46  GE
47 } Relation;
48 } // namespace EVENT
49 
50 class Event {
51  public:
52  Event();
53  Event(AST_Expression cond, int id, int offset, Option<Range> range, std::string event_id);
54  ~Event() = default;
55 
56  inline Equation zeroCrossing() { return _zero_crossing; };
59  std::string handler(EVENT::Type type) const;
60  void add(AST_Statement);
61  bool compare(AST_Expression zc);
62  inline bool hasRange() { return _range.is_initialized(); };
63  std::string macro() const;
64  int id() const { return _id; };
73  Expression exp();
74  bool isValid() const { return _zero_crossing.isValid(); };
75  std::string config() const;
76  inline Option<Range> range() const { return _range; };
77  bool compareEventID(std::string event_id);
78 
79  private:
80  AST_Expression getExpression(AST_Expression zc);
81  Equation _zero_crossing;
90  int _id;
91  int _offset;
92  std::string _event_id;
93 };
94 
96 
98 
100 
101 } // namespace IR
102 } // namespace MicroModelica
MicroModelica::IR::EVENT::Relation
Relation
Definition: event.hpp:93
MicroModelica::IR::EVENT::Positive
@ Positive
HND_POSITIVE.
Definition: event.hpp:102
ModelTable< int, Statement >
MicroModelica::IR::Event::macro
std::string macro() const
Definition: event.cpp:154
MicroModelica::IR::Event::_negative_handler_id
int _negative_handler_id
Definition: event.hpp:123
MicroModelica::IR::EVENT::LE
@ LE
ZC_LE.
Definition: event.hpp:95
MicroModelica::IR::Event::_zc_relation
EVENT::Relation _zc_relation
Definition: event.hpp:120
MicroModelica::IR::Event::compareEventID
bool compareEventID(std::string event_id)
Definition: event.cpp:180
MicroModelica::IR::Event::_negative_handler
StatementTable _negative_handler
Definition: event.hpp:117
MicroModelica::IR::Event::negativeHandler
StatementTable negativeHandler()
Definition: event.hpp:92
MicroModelica::IR::Event::~Event
~Event()=default
MicroModelica::IR::Event::Event
Event()
Definition: event.cpp:52
MicroModelica::IR::Event::positiveHandler
StatementTable positiveHandler()
Definition: event.hpp:91
Option
Definition: util_types.hpp:32
MicroModelica::IR::Event::_event_id
std::string _event_id
Definition: event.hpp:126
MicroModelica::IR::zeroCrossingTable
EquationTable zeroCrossingTable(EventTable events)
Helper function to to generate a equation table for zero crossing equations.
Definition: event.cpp:182
MicroModelica::IR::Expression
Definition: expression.hpp:64
MicroModelica::IR::EVENT::Zero
@ Zero
HND_ZERO.
Definition: event.hpp:101
MicroModelica::IR::Equation::isValid
bool isValid() const
Definition: equation.cpp:183
MicroModelica::IR::EVENT::LT
@ LT
ZC_LT.
Definition: event.hpp:94
MicroModelica::IR::Event::_range
Option< Range > _range
Definition: event.hpp:121
MicroModelica::IR::Event::compare
bool compare(AST_Expression zc)
Definition: event.cpp:99
MicroModelica::IR::EVENT::Type
Type
Definition: event.hpp:83
MicroModelica::IR::Event::_positive_handler_id
int _positive_handler_id
Definition: event.hpp:122
equation.hpp
MicroModelica::IR::EVENT::GE
@ GE
ZC_GE.
Definition: event.hpp:97
MicroModelica::IR::Event::_positive_handler
StatementTable _positive_handler
Definition: event.hpp:116
MicroModelica::IR::Event::config
std::string config() const
Definition: event.cpp:162
MicroModelica::IR::Event::exp
Expression exp()
This method returns the range expression of the event.
Definition: event.cpp:156
MicroModelica::IR::Event::_type
EVENT::Type _type
Definition: event.hpp:118
MicroModelica::IR::EVENT::Negative
@ Negative
HND_NEGATIVE.
Definition: event.hpp:103
MicroModelica::IR::Event::handler
std::string handler(EVENT::Type type) const
Definition: event.cpp:125
MicroModelica
Definition: files.cpp:45
MicroModelica::IR::StatementTable
ModelTable< int, Statement > StatementTable
Definition: statement.hpp:98
table.hpp
ast_types.hpp
MicroModelica::IR::EVENT::GT
@ GT
ZC_GT.
Definition: event.hpp:96
MicroModelica::IR::Event::_offset
int _offset
Definition: event.hpp:125
MicroModelica::IR::Event::_zero_crossing
Equation _zero_crossing
Definition: event.hpp:115
MicroModelica::IR::Event::id
int id() const
Definition: event.hpp:98
MicroModelica::IR::Event::isValid
bool isValid() const
Definition: event.hpp:108
MicroModelica::IR::Event::_id
int _id
Definition: event.hpp:124
MicroModelica::IR::Event::hasRange
bool hasRange()
Definition: event.hpp:96
statement.hpp
MicroModelica::IR::Event::add
void add(AST_Statement)
Definition: event.cpp:89
MicroModelica::IR::Event::range
Option< Range > range() const
Definition: event.hpp:110
MicroModelica::IR::Event::getExpression
AST_Expression getExpression(AST_Expression zc)
Definition: event.cpp:117
MicroModelica::IR::Event::zeroCrossing
Equation zeroCrossing()
Definition: event.hpp:90
MicroModelica::IR::Event::_current
EVENT::Type _current
Definition: event.hpp:119
MicroModelica::IR::EventTable
ModelTable< int, Event > EventTable
Definition: event.hpp:129