Leonardus
Loading...
Searching...
No Matches
sod.h
Go to the documentation of this file.
1
17#pragma once
18
19// Inc Library
20#include <string>
21#include <map>
22#include <numeric>
23#include <algorithm>
24#include <memory>
25
26// Inc HAA
27#include "dbc.h"
28#include "helper.h"
29
30// Inc Rich
31#include "so.h"
32
33
34class Context;
35
36
41class SOD : public SOcomposite {
42
48 struct SODMap {
49 std::map<SOp,SOp> stlmap_{};
53 std::for_each( stlmap_.begin(), stlmap_.end(),
54 []( const auto & p_pair ) {
55 delete p_pair.first;
56 delete p_pair.second;
57 } );
58 }
59 };
60
62 std::shared_ptr<SODMap> map_;
63
64
65protected:
66#ifndef DBC_IS_VOID
70 bool invariant() const noexcept override { /* LCOV_EXCL_START */
71 if( map_ == nullptr )
72 return false;
73 return std::none_of( map_->stlmap_.begin(), map_->stlmap_.end(),
74 []( const auto & p ) {
75 return p.first == nullptr or p.second == nullptr;
76 } );
77 } /* LCOV_EXCL_STOP */
78#endif
79
80public:
83 : SOcomposite(),
84 map_(std::make_shared<SODMap>()) {
86 }
87
88
91 explicit SOD( const SOcomposite & p_other )
92 : SOcomposite( p_other ),
93 map_(std::make_shared<SODMap>()) {
95 }
96
97
99 SOD( const SOD & p_other ) : SOcomposite(p_other), map_(p_other.map_) {
101 }
102
103
105 ~SOD() override {
107 }
108
109
110 SOD( SOD&& ) = delete;
111 SOD & operator=( const SOD & ) = delete;
112 SOD & operator=( SOD && ) = delete;
113
114
115public: /* virtual */
116 [[nodiscard]] SOD * dup() const override { return new SOD( *this ); }
117
121 [[nodiscard]] SOD * clone() const override;
122
123
124 std::string opequalequal() const override;
125
126
127 OTCode ot() const override { return OTCode::D; }
128
129
130 std::string type() const override { return "dicttype"; }
131
132
135 bool equal( const SO * p_other ) const override {
136 auto o = dynamic_cast<const SOD*>( p_other);
137 return o ? map_ == o->map_ : false;
138 }
139
140
141 size_t getSize() const override { return map_->stlmap_.size(); }
142
143
144 size_t treeheight( size_t p_myheight ) const override;
145
146
147public: /* other */
149 auto begin() { return map_->stlmap_.begin(); }
150
151
153 auto end() { return map_->stlmap_.end(); }
154
155
164 void insert( SOp p_key, SOp p_value, bool p_forcebegin = false );
165
166
173 SOp find( const SO * p_key ) const;
174
175
181 auto any_pop() {
182 DBC_PRE( getSize() > 0 );
183 DBC_INV_RAII( SOD );
184
185 auto it = begin();
186 auto retval( *it );
187 map_->stlmap_.erase( it );
188 return retval;
189 }
190
191
197 void undef( const SO * p_key );
198};
The context of execution.
Definition context.h:45
Semantic Object Dictionary.
Definition sod.h:41
SOD * dup() const override
Creates a new instance as copy following the red book definition.
Definition sod.h:116
void insert(SOp p_key, SOp p_value, bool p_forcebegin=false)
Insert with the red book definition of equal.
Definition sod.cpp:98
size_t getSize() const override
Returns the size of the SO.
Definition sod.h:141
SOD * clone() const override
Creates a new instance as copy with deep cloning.
Definition sod.cpp:39
size_t treeheight(size_t p_myheight) const override
Tree Height.
Definition sod.cpp:76
std::string opequalequal() const override
String representation for operators '==' and 'pstack'.
Definition sod.cpp:50
OTCode ot() const override
Returns an OTCode.
Definition sod.h:127
void undef(const SO *p_key)
Removes both p_key and its value from the dictionary.
Definition sod.cpp:133
auto begin()
Returns an iterator to the begin of the map of two SOps.
Definition sod.h:149
SOD(const SOcomposite &p_other)
Ctor from parent class object.
Definition sod.h:91
std::string type() const override
Returns a type name.
Definition sod.h:130
SOp find(const SO *p_key) const
Searches for p_key in the dictionary.
Definition sod.cpp:123
SOD()
Ctor.
Definition sod.h:82
bool equal(const SO *p_other) const override
Checks if this SO is equal to another SO.
Definition sod.h:135
bool invariant() const noexcept override
Checks class invariants.
Definition sod.h:70
SOD(const SOD &p_other)
Copy ctor.
Definition sod.h:99
~SOD() override
Dtor.
Definition sod.h:105
std::shared_ptr< SODMap > map_
The shared dictionary.
Definition sod.h:62
auto any_pop()
Returns a pair from the dictionary.
Definition sod.h:181
auto end()
Returns an iterator to the marker at end of the map of two SOps.
Definition sod.h:153
Semantic Object.
Definition so.h:60
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_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
Miscellaneous definitions and functions.
The class SO - semantic object.
OTCode
OTCode - the Object Type Code.
Definition so.h:35
@ o
SOo.
@ D
SOD.
Semantic Object Dictionary - map member class.
Definition sod.h:48
std::map< SOp, SOp > stlmap_
The map.
Definition sod.h:49
~SODMap()
Dtor.
Definition sod.h:52