Leonardus
so.h
Go to the documentation of this file.
1
17#pragma once
18
19#include <string>
20
21#include "dbc.h"
22#include "counter.h"
23#include "helper.h"
24#include "error.h"
25
26
29enum class OTCode : char {
30 L,
31 B,
32 I,
33 M,
34 N,
35 Nx,
36 O,
37 o,
38 Q,
39 R,
40
41 A,
42 Ax,
43 D,
44 S,
45 K,
46
47 X
48};
49
50
54class SO : public Counter<SO>, protected DbC {
55 bool exec_;
58public:
60 explicit SO( bool p_exec = false ) : exec_(p_exec) {}
61
62
65 virtual ~SO() = default;
66
67
68public: /* accessor */
70 bool getExec() const {
71 return exec_;
72 }
73
74
76 void setExec( bool p_exec ) {
77 exec_ = p_exec;
78 }
79
80
82 virtual size_t getSize() const {
83 return 1;
84 }
85
86
87public: /* virtual */
89 [[nodiscard]] virtual SO * dup() const = 0;
90
91
93 [[nodiscard]] virtual SO * clone() const {
94 return dup();
95 }
96
97
99 virtual std::string opequal() const = 0;
100
101
104 virtual std::string opequalequal() const {
105 return opequal();
106 }
107
108
113 virtual OTCode ot() const = 0;
114
115
119 virtual std::string type() const = 0;
120
121
132 virtual bool equal( const SO * /* unused */ ) const = 0;
133
134
139 virtual bool gt( const SO * /* unused */ ) const {
141 }
142
143
148 virtual bool ge( const SO * /* unused */ ) const {
150 }
151};
152
153
155using SOp = SO *;
156
157
161class SOcomposite : public SO {
162
163public:
165 using SO::SO;
166
167
168public: /* virtual */
169 std::string opequal() const override {
170 return "--nostringval--";
171 }
172
173
185 virtual size_t treeheight( size_t p_myheigth ) const {
186 return p_myheigth;
187 }
188};
Counter base class.
Definition: counter.h:26
Design by contract interface class.
Definition: dbc.h:25
Semantic Object.
Definition: so.h:54
virtual bool equal(const SO *) const =0
Equality.
void setExec(bool p_exec)
Setter for exec_.
Definition: so.h:76
virtual std::string type() const =0
Returns a type name.
virtual SO * dup() const =0
Creates a new instance as copy following the red book definition.
SO(bool p_exec=false)
Ctor.
Definition: so.h:60
virtual ~SO()=default
Virtual dtor.
virtual std::string opequalequal() const
For operators '==' and 'pstack'.
Definition: so.h:104
virtual std::string opequal() const =0
For operators '=', 'cvs' and 'stack'.
virtual bool ge(const SO *) const
Greater or equal.
Definition: so.h:148
virtual OTCode ot() const =0
Returns an OTCode.
virtual bool gt(const SO *) const
Greater than.
Definition: so.h:139
bool getExec() const
Getter for exec_.
Definition: so.h:70
virtual SO * clone() const
Creates a new instance as copy with deep cloning.
Definition: so.h:93
bool exec_
All SOs have executive vs literal attribut.
Definition: so.h:55
virtual size_t getSize() const
Getter for the number of characters or number of objects.
Definition: so.h:82
Composite Semantic Object.
Definition: so.h:161
std::string opequal() const override
For operators '=', 'cvs' and 'stack'.
Definition: so.h:169
virtual size_t treeheight(size_t p_myheigth) const
Tree Height.
Definition: so.h:185
The class Counter.
Helpers for design by contract idioms.
void opErrExit(OpError p_err, const std::string &p_details, const std::source_location p_location)
Operator error message to interpreter cout_ and exit( EC_OPERATOR ).
Definition: error.cpp:28
Error handling.
@ typecheck
PS operator error typecheck.
Definition: error.h:33
Miscellaneous definitions and functions.
OTCode
OTCode - the Object Type Code.
Definition: so.h:29
@ X
any SO
@ S
SOS.
@ M
SOM.
@ A
SOA literal.
@ N
SON literal.
@ B
SOB.
@ Nx
SON executable.
@ K
SOK.
@ Ax
SOA executable.
@ L
SOL.
@ o
SOo.
@ I
SOI.
@ R
SOR.
@ Q
SOQ.
@ O
SOO.
@ D
SOD.