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 {
|
||||
private:
|
||||
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:
|
||||
vector<ParseComponent> subComponents;
|
||||
mutable vector<ParseComponent> subComponents;
|
||||
public:
|
||||
unsigned int& getCompCount() { return compCount; }
|
||||
auto& getComponents() { return subComponents; }
|
||||
void add(const ParseComponent& component) { subComponents.push_back(component); ++compCount; };
|
||||
void addAll(const vector<ParseComponent>& components) { for (const auto& comp: components) add(comp); }
|
||||
void operator<<(const ParseComponent& component) { this->add(component); }
|
||||
explicit ParseTree(const ParseComponent& element): subComponents() { *this << element; }
|
||||
ParseTree(const initializer_list<ParseComponent>& elements): subComponents() { addAll(elements); }
|
||||
unsigned int& getCompCount() const { return compCount; }
|
||||
auto& getComponents() const { return subComponents; }
|
||||
void add(const ParseComponent& component) { addComp(component); };
|
||||
void addAll(const vector<ParseComponent>& components) { }
|
||||
void operator<<(const ParseComponent& component) { this->addComp(component); }
|
||||
explicit ParseTree(const ParseComponent& element): subComponents() { addComp(element); }
|
||||
ParseTree(const initializer_list<ParseComponent>& elements): subComponents() { addAllComps(elements); }
|
||||
ParseTree(): subComponents() {};
|
||||
~ParseTree() = default;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue