ParseComponents.hpp: Add a parent reference wrapper to ParseTree
Signed-off-by: Username404-59 <w.iron.zombie@gmail.com>
This commit is contained in:
parent
76cc701dd7
commit
a3e2427017
|
@ -42,6 +42,7 @@ class ParseTree: public virtual ParseComponent {
|
|||
using array_type = decltype(subComponents);
|
||||
using iterator = array_type::iterator;
|
||||
using constant_iterator = array_type::const_iterator;
|
||||
mutable optional<reference_wrapper<const ParseTree>> parent;
|
||||
protected:
|
||||
IS_PARSECOMPONENT
|
||||
void addComponent(const T& component) const {
|
||||
|
@ -51,6 +52,9 @@ protected:
|
|||
static_assert(is_move_constructible_v<T>, "T is not copy-constructible or move-constructible");
|
||||
subComponents.emplace_back(new T(move(const_cast<T&>(component))));
|
||||
}
|
||||
if constexpr(is_base_of_v<ParseTree, T>) {
|
||||
reinterpret_cast<const ParseTree&>(*subComponents.back()).parent = cref(*this);
|
||||
}
|
||||
};
|
||||
IS_PARSECOMPONENT
|
||||
void addAllComponents(
|
||||
|
@ -68,6 +72,9 @@ public:
|
|||
inline iterator end() noexcept { return subComponents.end(); }
|
||||
inline constant_iterator end() const noexcept { return cend(); }
|
||||
inline constant_iterator cend() const noexcept { return subComponents.cend(); }
|
||||
|
||||
const decltype(parent)& getParent() const { return parent; }
|
||||
|
||||
IS_PARSECOMPONENT
|
||||
vector<T*> findById() const {
|
||||
vector<T*> filteredComponents;
|
||||
|
|
Loading…
Reference in New Issue