Leonardus
Loading...
Searching...
No Matches
so.h
Go to the documentation of this file.
1
17#pragma once
18
19// Inc Library
20#include <string>
21#include <string_view>
22
23// Inc Pure
24#include "dbc.h"
25#include "helper.h"
26
27// Inc Medium
28#include "counter.h"
29#include "error.h"
30
31
38enum class OTCode : char {
39
40 N = 0,
41 Nx = 1,
42 B,
43 I,
44 L,
45 M,
46 O,
47 o,
48 Q,
49 R,
50
51 F,
52 S,
53
54 // The order of these next 4 entries is used to identify composed semantic objects:
55 A,
56 Ax,
57 D,
58 K,
59
60 X
61
62};
63
64
67class SO : public Counter<SO>, protected DbC {
68
71 bool exec_;
72
73public:
74
76 SO() : exec_(false) {}
77
78
81 explicit SO( bool p_exec ) : exec_(p_exec) {}
82
83
85 SO( const SO & p_other ) : Counter<SO>(), DbC(), exec_(p_other.exec_) {}
86
87
90 virtual ~SO() = default;
91
92
93 SO( SO && ) = delete;
94 SO & operator=( const SO & ) = delete;
95 SO & operator=( SO && ) = delete;
96
97public: /* accessor */
98
100 bool getExec() const {
101 return exec_;
102 }
103
104
106 void setExec( bool p_exec ) {
107 exec_ = p_exec;
108 }
109
110
116 virtual size_t getSize() const {
117 return 1;
118 }
119
120public: /* virtual */
121
124 [[nodiscard]] virtual SO * dup() const = 0;
125
126
132 [[nodiscard]] virtual SO * clone() const {
133 return dup();
134 }
135
136
139 virtual std::string opequal() const = 0;
140
141
147 virtual std::string opequalequal() const {
148 return opequal();
149 }
150
151
156 virtual OTCode ot() const = 0;
157
158
161 virtual std::string_view type() const = 0;
162
163
175 virtual bool equal( const SO * /* unused */ ) const = 0;
176
177
183 virtual bool gt( OpError & p_ec, const SO * /* unused */ ) const {
184 p_ec = typecheck;
185 return false;
186 }
187
188
194 virtual bool ge( OpError & p_ec, const SO * /* unused */ ) const {
195 p_ec = typecheck;
196 return false;
197 }
198
199};
200
201
203using SOp = SO *;
204
205
210class SOshptr : public SO {
211
212protected:
213
217 virtual void * shptr() const = 0;
218
219
220#ifndef DBC_IS_VOID
221
226 bool invariant() const noexcept override { /* LCOV_EXCL_START */
227 return shptr() != nullptr;
228 } /* LCOV_EXCL_STOP */
229#endif
230
231public:
232
233 /* Ctors */
234 using SO::SO;
235
236public: /* virtual */
237
238 std::string opequal() const override {
239 return "--nostringval--";
240 }
241
242
245 bool equal( const SO * p_other ) const override {
246 DBC_PRE( p_other != nullptr );
247
248 if( p_other->ot() != ot() )
249 return false;
250 const auto o = static_cast<const SOshptr *>( p_other );
251 return shptr() == o->shptr();
252 }
253
254};
255
256
261class SOcomposite : public SOshptr {
262
263public:
264
265 /* Ctors */
266 using SOshptr::SOshptr;
267
268public: /* virtual */
269
282 virtual size_t dagheight( size_t p_myheigth ) const = 0;
283
284
290 static bool otcodeIsComposite( OTCode p_code ) {
291 return p_code >= OTCode::A && p_code <= OTCode::K;
292 }
293
294};
Counter base class.
Definition counter.h:30
Design by contract interface class.
Definition dbc.h:30
Semantic Object.
Definition so.h:67
virtual std::string_view type() const =0
Returns a type name.
virtual bool equal(const SO *) const =0
Checks if this SO is equal to another SO.
void setExec(bool p_exec)
Setter for exec_.
Definition so.h:106
virtual SO * dup() const =0
Creates a new instance as copy following the red book definition.
virtual ~SO()=default
Virtual dtor.
virtual std::string opequalequal() const
String representation for operators '==' and 'pstack'.
Definition so.h:147
virtual std::string opequal() const =0
String representation of object for operators '=', 'cvs' and 'stack'.
virtual bool ge(OpError &p_ec, const SO *) const
Greater or equal.
Definition so.h:194
virtual OTCode ot() const =0
Returns an OTCode.
bool getExec() const
Getter for exec_.
Definition so.h:100
SO(bool p_exec)
Ctor.
Definition so.h:81
SO(const SO &p_other)
Copy ctor.
Definition so.h:85
SO()
Ctor.
Definition so.h:76
virtual SO * clone() const
Creates a new instance as copy with deep cloning.
Definition so.h:132
virtual bool gt(OpError &p_ec, const SO *) const
Greater than.
Definition so.h:183
bool exec_
Flag indicating whether the SO is executable (true) or literal (false).
Definition so.h:71
virtual size_t getSize() const
Returns the size of the SO.
Definition so.h:116
Composite Semantic Object.
Definition so.h:261
virtual size_t dagheight(size_t p_myheigth) const =0
DAG Height.
static bool otcodeIsComposite(OTCode p_code)
Checks if an OTCode represents a composite type (A, Ax, D, K).
Definition so.h:290
Semantic Object with shared pointer to data.
Definition so.h:210
virtual void * shptr() const =0
Pointer to the shared object.
bool invariant() const noexcept override
Checks class invariants.
Definition so.h:226
bool equal(const SO *p_other) const override
Checks if this SO is equal to another SO.
Definition so.h:245
std::string opequal() const override
String representation of object for operators '=', 'cvs' and 'stack'.
Definition so.h:238
The class Counter.
Helpers for design by contract idioms.
#define DBC_PRE(XXX)
Assert for preconditions.
Definition dbc.h:104
Error handling.
OpError
Operator error code enum.
Definition error.h:30
@ typecheck
operator error typecheck
Definition error.h:36
Miscellaneous definitions and functions.
OTCode
OTCode - the Object Type Code.
Definition so.h:38
@ X
any SO. Is used by checks to represent any object.
@ S
SOS.
@ M
SOM.
@ A
SOA literal.
@ F
SOF.
@ 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.