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 <vector>
24#include <memory>
25#include <algorithm>
26
27// Inc HAA
28#include "dbc.h"
29#include "helper.h"
30
31// Inc Rich
32#include "so.h"
33
34
35class Context;
36
37
41class SOD : public SOcomposite {
45 struct SODMap {
46 std::map<SOp,SOp> stlmap_;
50 std::for_each( stlmap_.begin(), stlmap_.end(),
51 []( const auto & p_pair ) {
52 delete p_pair.first;
53 delete p_pair.second;
54 } );
55 }
56 };
57
58 std::shared_ptr<SODMap> map_;
61protected:
62#ifndef DBC_IS_VOID
66 bool invariant() const noexcept override { /* LCOV_EXCL_START */
67 if( map_ == nullptr )
68 return false;
69 return std::none_of( map_->stlmap_.begin(), map_->stlmap_.end(),
70 []( const auto & p ) {
71 return p.first == nullptr or p.second == nullptr;
72 } );
73 } /* LCOV_EXCL_STOP */
74#endif
75
76public:
78 SOD() : map_(std::make_shared<SODMap>()) {
80 }
81
82public: /* virtual */
83 [[nodiscard]] SOD * dup() const override { return new SOD( *this ); }
84
88 [[nodiscard]] SOD * clone() const override;
89
90 std::string opequalequal() const override;
91
92 OTCode ot() const override { return OTCode::D; }
93
94 std::string type() const override { return "dicttype"; }
95
96 bool equal( const SO * p_other ) const override {
97 auto o = dynamic_cast<const SOD*>( p_other);
98 return o ? map_ == o->map_ : false;
99 }
100
101 size_t getSize() const override { return map_->stlmap_.size(); }
102
103 size_t treeheight( size_t p_myheight ) const override;
104
105public: /* other */
107 auto begin() { return map_->stlmap_.begin(); }
108
109
111 auto end() { return map_->stlmap_.end(); }
112
113
121 void insert( SOp p_key, SOp p_value, bool p_forcebegin = false );
122
123
128 SOp find( const SO * p_key ) const;
129
130
133 auto any_pop() {
134 DBC_PRE( getSize() > 0 );
135 DBC_INV_RAII( SOD );
136
137 auto it = begin();
138 auto retval( *it );
139 map_->stlmap_.erase( it );
140 return retval;
141 }
142
143
147 void undef( const SO * p_key );
148};
The context of execution.
Definition context.h:42
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:83
void insert(SOp p_key, SOp p_value, bool p_forcebegin=false)
Insert with the red book definition of equal.
Definition sod.cpp:92
size_t getSize() const override
Getter for the number of characters or number of objects.
Definition sod.h:101
SOD * clone() const override
Creates a new instance as copy with deep cloning.
Definition sod.cpp:37
size_t treeheight(size_t p_myheight) const override
Tree Height.
Definition sod.cpp:70
std::string opequalequal() const override
For operators '==' and 'pstack'.
Definition sod.cpp:49
OTCode ot() const override
Returns an OTCode.
Definition sod.h:92
void undef(const SO *p_key)
Removes both p_key and its value from the dictionary.
Definition sod.cpp:127
auto begin()
Returns an iterator to the begin of the map of two SOps.
Definition sod.h:107
std::string type() const override
Returns a type name.
Definition sod.h:94
SOp find(const SO *p_key) const
Searches for p_key in the dictionary.
Definition sod.cpp:117
SOD()
Ctor.
Definition sod.h:78
bool equal(const SO *p_other) const override
Equality.
Definition sod.h:96
bool invariant() const noexcept override
Checks class invariants.
Definition sod.h:66
std::shared_ptr< SODMap > map_
The shared dictionary.
Definition sod.h:58
auto any_pop()
Returns a pair from the dictionary.
Definition sod.h:133
auto end()
Returns an iterator to the marker at end of the map of two SOps.
Definition sod.h:111
Semantic Object.
Definition so.h:58
Composite Semantic Object.
Definition so.h:165
Helpers for design by contract idioms.
#define DBC_INV_CTOR(T)
Assert for invariant checks in ctors and dtors.
Definition dbc.h:89
#define DBC_PRE(XXX)
Assert for preconditions.
Definition dbc.h:78
#define DBC_INV_RAII(TT)
Defines an instance of the class DbCRAIIassert<>, which calls the invariant()-function at the return ...
Definition dbc.h:71
Miscellaneous definitions and functions.
The class SO - semantic object.
OTCode
OTCode - the Object Type Code.
Definition so.h:33
@ o
SOo.
@ D
SOD.
Semantic Object Dictionary - map member class.
Definition sod.h:45
std::map< SOp, SOp > stlmap_
The map.
Definition sod.h:46
~SODMap()
Dtor.
Definition sod.h:49