Leonardus
Loading...
Searching...
No Matches
soa.h
Go to the documentation of this file.
1
17#pragma once
18
19// Inc Library
20#include <string>
21#include <vector>
22#include <algorithm>
23
24// Inc HAA
25#include "dbc.h"
26#include "helper.h"
27
28// Inc Rich
29#include "so.h"
30
31
32class Context;
33
34
40class SOA : public SOcomposite {
41
47 struct SOAArray {
48 std::vector<SOp> stlvec_{};
52 for( auto * ptr : stlvec_ )
53 delete ptr;
54 }
55 };
56
58 std::shared_ptr<SOAArray> vec_;
59
60
61protected:
62#ifndef DBC_IS_VOID
66 bool invariant() const noexcept override { /* LCOV_EXCL_START */
67 if( vec_ == nullptr )
68 return false;
69 return std::none_of( vec_->stlvec_.begin(), vec_->stlvec_.end(),
70 []( const SO * p ) {
71 return p == nullptr;
72 } );
73 } /* LCOV_EXCL_STOP */
74#endif
75
76
77public:
82 explicit SOA( bool p_exec, size_t p_len = 0 );
83
84
86 SOA( const SOA & p_other ) : SOcomposite(p_other), vec_(p_other.vec_) {
88 }
89
90
92 ~SOA() override {
94 }
95
96
97 SOA() = delete;
98 SOA( SOA&& ) = delete;
99 SOA & operator=( const SOA & ) = delete;
100 SOA & operator=( SOA && ) = delete;
101
102
103public: /* accessor */
111 void setSO( size_t p_index, SOp p_sop ) {
112 DBC_PRE( p_index < getSize() );
113 DBC_PRE( p_sop != nullptr );
114
115 delete vec_->stlvec_[p_index];
116 vec_->stlvec_[p_index] = p_sop;
117
118 if( treeheight( 0 ) >= maxtreeheight )
119 inErrExit( semantics, "composite object tree height exceeds maximum" );
120
121 DBC_INV;
122 }
123
124
132 SOp ncat( size_t p_pos ) const {
133 DBC_PRE( p_pos < getSize() );
134
135 return vec_->stlvec_[ p_pos ];
136 }
137
138
139public: /* virtual */
140 [[nodiscard]] SOA * dup() const override { return new SOA( *this ); }
141
142
146 [[nodiscard]] SOA * clone() const override;
147
148
149 std::string opequalequal() const override;
150
151
152 OTCode ot() const override {
153 return getExec() ? OTCode::Ax : OTCode::A;
154 }
155
156
157 std::string type() const override { return "arraytype"; }
158
159
162 bool equal( const SO * p_other ) const override {
163 auto o = dynamic_cast<const SOA*>( p_other );
164 if( !o ) return false;
165 if( getSize() == 0 && o->getSize() == 0 )
166 return true; // Exception: arrays of size zero are always equal.
167 return vec_ == o->vec_;
168 }
169
170
171 size_t getSize() const override { return vec_->stlvec_.size(); }
172
173
174 size_t treeheight( size_t p_myheight ) const override;
175
176
177public: /* other */
179 auto begin() { return vec_->stlvec_.begin(); }
180
181
183 auto end() { return vec_->stlvec_.end(); }
184
185
190 void reduce();
191
192
195 void unfold2exec( Context & k ) const;
196
197
204 DBC_PRE( getSize() > 0 );
206
207 SOp retval = ncat( 0 );
208 vec_->stlvec_.erase( begin() );
209 return retval;
210 }
211
212
215 void bind( Context & k );
216};
The context of execution.
Definition context.h:45
Semantic Object Array.
Definition soa.h:40
size_t treeheight(size_t p_myheight) const override
Tree Height.
Definition soa.cpp:115
SOp front_pop()
Returns a copy of the SOp at position 0 and removes this first position from the array.
Definition soa.h:203
size_t getSize() const override
Returns the size of the SO.
Definition soa.h:171
void unfold2exec(Context &k) const
Unfolds duplicates of the array-content to the execution stack.
Definition soa.cpp:88
std::string type() const override
Returns a type name.
Definition soa.h:157
SOA * clone() const override
Creates a new instance as copy with deep cloning.
Definition soa.cpp:76
void bind(Context &k)
Replaces executable names with operator objects recursively into elements that are SOA.
Definition soa.cpp:51
~SOA() override
Dtor.
Definition soa.h:92
std::shared_ptr< SOAArray > vec_
The shared array.
Definition soa.h:58
void setSO(size_t p_index, SOp p_sop)
Setter for an array object.
Definition soa.h:111
bool equal(const SO *p_other) const override
Checks if this SO is equal to another SO.
Definition soa.h:162
OTCode ot() const override
Returns an OTCode.
Definition soa.h:152
SOp ncat(size_t p_pos) const
Returns a copy of the SOp at the given position.
Definition soa.h:132
bool invariant() const noexcept override
Checks class invariants.
Definition soa.h:66
SOA(const SOA &p_other)
Copy ctor.
Definition soa.h:86
void reduce()
Reduces the array by one SO at the end.
Definition soa.cpp:131
SOA * dup() const override
Creates a new instance as copy following the red book definition.
Definition soa.h:140
auto begin()
Returns an iterator to the first SOp.
Definition soa.h:179
std::string opequalequal() const override
String representation for operators '==' and 'pstack'.
Definition soa.cpp:94
auto end()
Returns an iterator to the marker at end of the vector of SOps.
Definition soa.h:183
Semantic Object.
Definition so.h:60
bool getExec() const
Getter for exec_.
Definition so.h:93
Composite Semantic Object.
Definition so.h:198
Helpers for design by contract idioms.
#define DBC_INV_CTOR(T)
Assert for invariant checks in ctors and dtors.
Definition dbc.h:121
#define DBC_INV
Assert for invariant checks in member functions.
Definition dbc.h:113
#define DBC_PRE(XXX)
Assert for preconditions.
Definition dbc.h:103
#define DBC_INV_RAII(TT)
Defines an instance of the class DbCRAIIassert<>, which calls the invariant()-function at the return ...
Definition dbc.h:93
void inErrExit(InError p_err, const std::string &p_details, const std::source_location p_location)
Write interpreter error message to interpreter out file and exit( EC_INTERPRETER / EC_CMDLINE ).
Definition error.cpp:86
@ semantics
infinite nesting of arrays; infinite loop loading values from dictionary;
Definition error.h:51
Miscellaneous definitions and functions.
constexpr size_t maxtreeheight
The maximum number of nesting levels of composite semantic objects.
Definition helper.h:93
The class SO - semantic object.
OTCode
OTCode - the Object Type Code.
Definition so.h:35
@ A
SOA literal.
@ Ax
SOA executable.
@ o
SOo.
Semantic Object Array - array member class.
Definition soa.h:47
~SOAArray()
Dtor.
Definition soa.h:51
std::vector< SOp > stlvec_
The inner array.
Definition soa.h:48