Add a component_ptr type definition to ParseComponents.hpp

Signed-off-by: Username404 <w.iron.zombie@gmail.com>
This commit is contained in:
Username404 2022-02-06 19:40:34 +01:00
parent ca4e773fca
commit 1a37e35228
Signed by: Username404-59
GPG Key ID: 7AB361FBB257A5D1
2 changed files with 6 additions and 4 deletions

View File

@ -25,9 +25,11 @@ struct NamedIdentifier: ParseComponent {
explicit NamedIdentifier(string_view nameText): name(nameText) {}
};
typedef unique_ptr<ParseComponent> component_ptr;
#define IS_PARSECOMPONENT IS(ParseComponent)
class ParseTree: public ParseComponent {
mutable vector<unique_ptr<ParseComponent>> subComponents;
mutable vector<component_ptr> subComponents;
using array_type = decltype(subComponents);
using iterator = array_type::iterator;
using constant_iterator = array_type::const_iterator;
@ -57,7 +59,7 @@ public:
IS_PARSECOMPONENT
vector<T*> findById() const {
vector<T*> filteredComponents;
for_each(cbegin(), cend(), [&filteredComponents](const unique_ptr<ParseComponent>& it) {
for_each(cbegin(), cend(), [&filteredComponents](const component_ptr& it) {
if (it->getId() == typeid(T)) {
filteredComponents.push_back(reinterpret_cast<T*>(it.get()));
}
@ -74,7 +76,7 @@ public:
}
return optional<reference_wrapper<T>>();
};
inline decltype(*subComponents.data()) operator[](const unsigned int& index) const { return subComponents[index]; }
inline component_ptr& operator[](const unsigned int& index) const { return subComponents[index]; }
IS(NamedIdentifier)
inline auto operator[](const string& key) const { return findReferenceByName<T>(key); }
IS_PARSECOMPONENT inline void add(const T& component) { addComponent<T>(component); }

View File

@ -109,7 +109,7 @@ public:
}
output.str(string());
for (unsigned int i = 0; i < tree.size(); ++i) {
const unique_ptr<ParseComponent>& component = tree[i];
const component_ptr& component = tree[i];
const type_info& id = component->getId();
try {
taskMap.at(id)(tree, i);