Make the subComponents vector mutable, make some functions const and add private methods to ParseTree to make creation of const objects possible.
This commit is contained in:
parent
28175f2d96
commit
29f0fafe31
@ -12,16 +12,19 @@ class ParseComponent {};
|
|||||||
struct ParseTree: public ParseComponent {
|
struct ParseTree: public ParseComponent {
|
||||||
private:
|
private:
|
||||||
mutable unsigned int compCount = 0;
|
mutable unsigned int compCount = 0;
|
||||||
|
inline void addComp(const auto& comp) const {
|
||||||
|
subComponents.push_back(comp); ++compCount;
|
||||||
|
}; inline void addAllComps(auto& comps) { for (const auto& comp: comps) addComp(comp); }
|
||||||
protected:
|
protected:
|
||||||
vector<ParseComponent> subComponents;
|
mutable vector<ParseComponent> subComponents;
|
||||||
public:
|
public:
|
||||||
unsigned int& getCompCount() { return compCount; }
|
unsigned int& getCompCount() const { return compCount; }
|
||||||
auto& getComponents() { return subComponents; }
|
auto& getComponents() const { return subComponents; }
|
||||||
void add(const ParseComponent& component) { subComponents.push_back(component); ++compCount; };
|
void add(const ParseComponent& component) { addComp(component); };
|
||||||
void addAll(const vector<ParseComponent>& components) { for (const auto& comp: components) add(comp); }
|
void addAll(const vector<ParseComponent>& components) { }
|
||||||
void operator<<(const ParseComponent& component) { this->add(component); }
|
void operator<<(const ParseComponent& component) { this->addComp(component); }
|
||||||
explicit ParseTree(const ParseComponent& element): subComponents() { *this << element; }
|
explicit ParseTree(const ParseComponent& element): subComponents() { addComp(element); }
|
||||||
ParseTree(const initializer_list<ParseComponent>& elements): subComponents() { addAll(elements); }
|
ParseTree(const initializer_list<ParseComponent>& elements): subComponents() { addAllComps(elements); }
|
||||||
ParseTree(): subComponents() {};
|
ParseTree(): subComponents() {};
|
||||||
~ParseTree() = default;
|
~ParseTree() = default;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user