Leonardus
context.h
Go to the documentation of this file.
1
17#pragma once
18
19#include <string>
20#include <iostream>
21#include <map>
22#include <cstdint>
23
24#include "dbc.h"
25#include "interpreter.h"
26#include "counter.h"
27#include "helper.h"
28
29#include "sok.h"
30
31
37class Context : public Counter<Context>, protected DbC {
38 std::string snapLeonline_;
42 bool run_ = true;
43 int proclevel_ = 0;
45 int loadlevel_ = 0;
47 int arraynesting_ = 0;
50 AngularUnit angularunit_ = AngularUnit::DEG;
51 size_t realprecision_ = 10;
52 size_t maxloadlevel_ = 1000;
53 uint32_t seed_ = 0;
56public:
57 constexpr static size_t mindictstack_ = 3;
59protected:
60#ifndef DBC_IS_VOID
65 bool invariant() const noexcept override { /* LCOV_EXCL_START */
66 if( proclevel_ < 0 )
67 return false;
68 if( loadlevel_ < 0 )
69 return false;
70 return arraynesting_ >= 0;
71 } /* LCOV_EXCL_STOP */
72#endif
73
74private:
76 static const std::map<const char *, core_t *> systemdictmap_,
79
80public:
85 Context();
86
88 Context( const Context & ) = delete;
89
91 Context( Context && ) = delete;
92
94 Context & operator=( const Context & ) = delete;
95
97 Context & operator=( Context && ) = delete;
98
101 virtual ~Context();
102
103public: /* accessor */
105 SOK & opst() { return os_; }
106
108 SOK & exst() { return es_; }
109
111 SOK & dist() { return ds_; }
112
115 std::ostream & getCout() {
116 return Interpreter::get()->getCout();
117 }
118
120 size_t getProclevel() const { return static_cast<size_t>(proclevel_); }
121
123 size_t getLoadlevel() const { return static_cast<size_t>(loadlevel_); }
124
126 size_t getArraynesting() const { return static_cast<size_t>(arraynesting_); }
127
129 size_t getMaxloadlevel() const { return maxloadlevel_; }
130
132 bool getInterpreterLoop() const { return run_; }
133
135 void stopInterpreterLoop() { run_ = false; }
136
138 void setSnapLeonline( const std::string & p_line ) { snapLeonline_ = p_line; }
139
141 size_t getRealprecision() const { return realprecision_; }
142
144 void setRealprecision( size_t p_prec ) { realprecision_ = p_prec; }
145
147 auto getAngularUnit() const { return angularunit_; }
148
150 void setAngularUnit( AngularUnit p_unit ) { angularunit_ = p_unit; }
151
153 uint32_t getSeed() const { return seed_; }
154
156 void setSeed( uint32_t p_seed ) { seed_ = p_seed; }
157
158
159public: /* other */
163 proclevel_++;
164 }
165
169 proclevel_--;
170 }
171
175 loadlevel_++;
176 }
177
181 loadlevel_--;
182 }
183
188 }
189
194 }
195
197 void status_statistics();
198
200 void property_statistics();
201
203 void stack_statistics();
204};
The context of execution.
Definition: context.h:37
size_t getLoadlevel() const
Getter for load level.
Definition: context.h:123
SOK os_
The operand stack.
Definition: context.h:39
uint32_t getSeed() const
Getter for seed_.
Definition: context.h:153
Context & operator=(const Context &)=delete
Delete copy assignement.
void setRealprecision(size_t p_prec)
Setter for realprecision_.
Definition: context.h:144
void stopInterpreterLoop()
Sets run_ to false.
Definition: context.h:135
Context(Context &&)=delete
Delete the move ctor.
SOK ds_
The dictionary stack.
Definition: context.h:41
void decArraynesting()
Decrements array nesting.
Definition: context.h:191
void status_statistics()
Snapshot of Context state to cout.
Definition: context.cpp:235
uint32_t seed_
Context Property.
Definition: context.h:53
virtual ~Context()
Dtor.
Definition: context.cpp:61
void stack_statistics()
Snapshot of stacks to cout.
Definition: context.cpp:246
bool invariant() const noexcept override
Checks class invariants.
Definition: context.h:65
SOK & opst()
Access to the operand stack.
Definition: context.h:105
void property_statistics()
Snapshot of Context properties to cout.
Definition: context.cpp:223
size_t getMaxloadlevel() const
Getter for maximum load level.
Definition: context.h:129
auto getAngularUnit() const
Getter for angularunit_.
Definition: context.h:147
void incProclevel()
Increments the procedure level.
Definition: context.h:161
bool run_
Control variable for the interpreter loop.
Definition: context.h:42
int loadlevel_
The load level is incemented for ever load_exec() call.
Definition: context.h:45
void incArraynesting()
Increments array nesting.
Definition: context.h:185
void setAngularUnit(AngularUnit p_unit)
Setter for angularunit_.
Definition: context.h:150
Context()
Ctor.
Definition: context.cpp:32
size_t getArraynesting() const
Getter for nesting level.
Definition: context.h:126
AngularUnit angularunit_
Context Property.
Definition: context.h:50
void decLoadlevel()
Decrements load level.
Definition: context.h:179
std::ostream & getCout()
Getter for cout_.
Definition: context.h:115
size_t realprecision_
Context Property.
Definition: context.h:51
static constexpr size_t mindictstack_
Corresponds with the setup in the ctor.
Definition: context.h:57
bool getInterpreterLoop() const
Getter for interpreter loop control variable run_.
Definition: context.h:132
void setSnapLeonline(const std::string &p_line)
Setter for snapLeonline_.
Definition: context.h:138
std::string snapLeonline_
For debugging purposes a copy of the current leon-format line.
Definition: context.h:38
int arraynesting_
The nesting level is incemented for every array within an array for the bind operator.
Definition: context.h:47
void decProclevel()
Decrements the procedure level.
Definition: context.h:167
SOK & exst()
Access to the execution stack.
Definition: context.h:108
void setSeed(uint32_t p_seed)
Setter for seed_.
Definition: context.h:156
SOK & dist()
Access to the dictionary stack.
Definition: context.h:111
size_t maxloadlevel_
Context Property.
Definition: context.h:52
int proclevel_
The process level is incremented for every '{' on input.
Definition: context.h:43
Context & operator=(Context &&)=delete
Delete move assignement.
size_t getProclevel() const
Getter for procedure level.
Definition: context.h:120
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:141
void incLoadlevel()
Increments load level.
Definition: context.h:173
static const std::map< const char *, core_t * > leodictmap_
Maps SON data to SOO data for the leodict.
Definition: context.h:78
SOK es_
The execution stack.
Definition: context.h:40
Counter base class.
Definition: counter.h:26
Design by contract interface class.
Definition: dbc.h:25
static auto get()
Get the singleton pointer.
Definition: interpreter.h:98
Semantic Object stacK.
Definition: sok.h:39
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:70
Miscellaneous definitions and functions.
AngularUnit
Angular Unit for trigonometric functions.
Definition: helper.h:80
The class Interpreter.
The class SOK - semantik object stack.