Leonardus
Loading...
Searching...
No Matches
context.h
Go to the documentation of this file.
1
17#pragma once
18
19// Inc Library
20#include <string>
21#include <iostream>
22#include <map>
23#include <cstdint>
24
25// Inc HAA
26#include "dbc.h"
27#include "helper.h"
28
29// Inc Medium
30#include "counter.h"
31
32// Inc Rich
33#include "interpreter.h"
34#include "sok.h"
35
36
42class Context : public Counter<Context>, protected DbC {
43 std::string snapLeonline_;
47 bool run_ = true;
48 int proclevel_ = 0;
50 int loadlevel_ = 0;
52 int arraynesting_ = 0;
55 AngularUnit angularunit_ = AngularUnit::DEG;
56 size_t realprecision_ = 10;
57 size_t maxloadlevel_ = 1000;
58 uint32_t seed_ = 0;
61public:
62 constexpr static size_t mindictstack_ = 3;
64protected:
65#ifndef DBC_IS_VOID
70 bool invariant() const noexcept override { /* LCOV_EXCL_START */
71 if( proclevel_ < 0 )
72 return false;
73 if( loadlevel_ < 0 )
74 return false;
75 return arraynesting_ >= 0;
76 } /* LCOV_EXCL_STOP */
77#endif
78
79private:
81 static const std::map<const char *, core_t *> systemdictmap_,
84
85public:
90 Context();
91
93 Context( const Context & ) = delete;
94
96 Context( Context && ) = delete;
97
99 Context & operator=( const Context & ) = delete;
100
102 Context & operator=( Context && ) = delete;
103
106 virtual ~Context();
107
108public: /* accessor */
110 SOK & opst() { return os_; }
111
113 SOK & exst() { return es_; }
114
116 SOK & dist() { return ds_; }
117
120 std::ostream & getCout() {
121 return Interpreter::get()->getCout();
122 }
123
125 size_t getProclevel() const { return static_cast<size_t>(proclevel_); }
126
128 size_t getLoadlevel() const { return static_cast<size_t>(loadlevel_); }
129
131 size_t getArraynesting() const { return static_cast<size_t>(arraynesting_); }
132
134 size_t getMaxloadlevel() const { return maxloadlevel_; }
135
137 bool getInterpreterLoop() const { return run_; }
138
140 void stopInterpreterLoop() { run_ = false; }
141
143 void setSnapLeonline( const std::string & p_line ) { snapLeonline_ = p_line; }
144
146 size_t getRealprecision() const { return realprecision_; }
147
149 void setRealprecision( size_t p_prec ) { realprecision_ = p_prec; }
150
152 auto getAngularUnit() const { return angularunit_; }
153
155 void setAngularUnit( AngularUnit p_unit ) { angularunit_ = p_unit; }
156
158 uint32_t getSeed() const { return seed_; }
159
161 void setSeed( uint32_t p_seed ) { seed_ = p_seed; }
162
163
164public: /* other */
168 proclevel_++;
169 }
170
174 proclevel_--;
175 }
176
180 loadlevel_++;
181 }
182
186 loadlevel_--;
187 }
188
194
200
202 void status_statistics();
205 void property_statistics();
206
208 void stack_statistics();
209};
The context of execution.
Definition context.h:42
size_t getLoadlevel() const
Getter for load level.
Definition context.h:128
SOK os_
The operand stack.
Definition context.h:44
uint32_t getSeed() const
Getter for seed_.
Definition context.h:158
Context & operator=(const Context &)=delete
Delete copy assignement.
void setRealprecision(size_t p_prec)
Setter for realprecision_.
Definition context.h:149
void stopInterpreterLoop()
Sets run_ to false.
Definition context.h:140
Context(Context &&)=delete
Delete the move ctor.
SOK ds_
The dictionary stack.
Definition context.h:46
void decArraynesting()
Decrements array nesting.
Definition context.h:196
void status_statistics()
Snapshot of Context state to cout.
Definition context.cpp:240
uint32_t seed_
Context Property.
Definition context.h:58
virtual ~Context()
Dtor.
Definition context.cpp:64
void stack_statistics()
Snapshot of stacks to cout.
Definition context.cpp:251
bool invariant() const noexcept override
Checks class invariants.
Definition context.h:70
SOK & opst()
Access to the operand stack.
Definition context.h:110
void property_statistics()
Snapshot of Context properties to cout.
Definition context.cpp:228
size_t getMaxloadlevel() const
Getter for maximum load level.
Definition context.h:134
auto getAngularUnit() const
Getter for angularunit_.
Definition context.h:152
void incProclevel()
Increments the procedure level.
Definition context.h:166
bool run_
Control variable for the interpreter loop.
Definition context.h:47
int loadlevel_
The load level is incemented for ever load_exec() call.
Definition context.h:50
void incArraynesting()
Increments array nesting.
Definition context.h:190
void setAngularUnit(AngularUnit p_unit)
Setter for angularunit_.
Definition context.h:155
Context()
Ctor.
Definition context.cpp:35
size_t getArraynesting() const
Getter for nesting level.
Definition context.h:131
AngularUnit angularunit_
Context Property.
Definition context.h:55
void decLoadlevel()
Decrements load level.
Definition context.h:184
std::ostream & getCout()
Getter for cout_.
Definition context.h:120
size_t realprecision_
Context Property.
Definition context.h:56
static constexpr size_t mindictstack_
Corresponds with the setup in the ctor.
Definition context.h:62
bool getInterpreterLoop() const
Getter for interpreter loop control variable run_.
Definition context.h:137
void setSnapLeonline(const std::string &p_line)
Setter for snapLeonline_.
Definition context.h:143
std::string snapLeonline_
For debugging purposes a copy of the current leon-format line.
Definition context.h:43
int arraynesting_
The nesting level is incemented for every array within an array for the bind operator.
Definition context.h:52
void decProclevel()
Decrements the procedure level.
Definition context.h:172
SOK & exst()
Access to the execution stack.
Definition context.h:113
void setSeed(uint32_t p_seed)
Setter for seed_.
Definition context.h:161
SOK & dist()
Access to the dictionary stack.
Definition context.h:116
size_t maxloadlevel_
Context Property.
Definition context.h:57
int proclevel_
The process level is incremented for every '{' on input.
Definition context.h:48
Context & operator=(Context &&)=delete
Delete move assignement.
size_t getProclevel() const
Getter for procedure level.
Definition context.h:125
static const std::map< const char *, core_t * > systemdictmap_
Maps SON data to SOO data for the systemdict.
Definition context.h:76
Context(const Context &)=delete
Delete the copy ctor.
size_t getRealprecision() const
Getter for realprecision_.
Definition context.h:146
void incLoadlevel()
Increments load level.
Definition context.h:178
static const std::map< const char *, core_t * > leodictmap_
Maps SON data to SOO data for the leodict.
Definition context.h:203
SOK es_
The execution stack.
Definition context.h:45
Counter base class.
Definition counter.h:27
Design by contract interface class.
Definition dbc.h:26
static auto get()
Get the singleton pointer.
Definition interpreter.h:101
Semantic Object stacK.
Definition sok.h:44
The class Counter.
Helpers for design by contract idioms.
#define DBC_INV_RAII(TT)
Defines an instance of the class DbCRAIIassert<>, which calls the invariant()-function at the return ...
Definition dbc.h:71
Miscellaneous definitions and functions.
AngularUnit
Angular Unit for trigonometric functions.
Definition helper.h:81
The class Interpreter.
The class SOK - semantik object stack.