Add a component_ptr type definition to ParseComponents.hpp
Signed-off-by: Username404 <w.iron.zombie@gmail.com>
This commit is contained in:
parent
ca4e773fca
commit
1a37e35228
|
@ -25,9 +25,11 @@ struct NamedIdentifier: ParseComponent {
|
||||||
explicit NamedIdentifier(string_view nameText): name(nameText) {}
|
explicit NamedIdentifier(string_view nameText): name(nameText) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef unique_ptr<ParseComponent> component_ptr;
|
||||||
|
|
||||||
#define IS_PARSECOMPONENT IS(ParseComponent)
|
#define IS_PARSECOMPONENT IS(ParseComponent)
|
||||||
class ParseTree: public ParseComponent {
|
class ParseTree: public ParseComponent {
|
||||||
mutable vector<unique_ptr<ParseComponent>> subComponents;
|
mutable vector<component_ptr> subComponents;
|
||||||
using array_type = decltype(subComponents);
|
using array_type = decltype(subComponents);
|
||||||
using iterator = array_type::iterator;
|
using iterator = array_type::iterator;
|
||||||
using constant_iterator = array_type::const_iterator;
|
using constant_iterator = array_type::const_iterator;
|
||||||
|
@ -57,7 +59,7 @@ public:
|
||||||
IS_PARSECOMPONENT
|
IS_PARSECOMPONENT
|
||||||
vector<T*> findById() const {
|
vector<T*> findById() const {
|
||||||
vector<T*> filteredComponents;
|
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)) {
|
if (it->getId() == typeid(T)) {
|
||||||
filteredComponents.push_back(reinterpret_cast<T*>(it.get()));
|
filteredComponents.push_back(reinterpret_cast<T*>(it.get()));
|
||||||
}
|
}
|
||||||
|
@ -74,7 +76,7 @@ public:
|
||||||
}
|
}
|
||||||
return optional<reference_wrapper<T>>();
|
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)
|
IS(NamedIdentifier)
|
||||||
inline auto operator[](const string& key) const { return findReferenceByName<T>(key); }
|
inline auto operator[](const string& key) const { return findReferenceByName<T>(key); }
|
||||||
IS_PARSECOMPONENT inline void add(const T& component) { addComponent<T>(component); }
|
IS_PARSECOMPONENT inline void add(const T& component) { addComponent<T>(component); }
|
||||||
|
|
|
@ -109,7 +109,7 @@ public:
|
||||||
}
|
}
|
||||||
output.str(string());
|
output.str(string());
|
||||||
for (unsigned int i = 0; i < tree.size(); ++i) {
|
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();
|
const type_info& id = component->getId();
|
||||||
try {
|
try {
|
||||||
taskMap.at(id)(tree, i);
|
taskMap.at(id)(tree, i);
|
||||||
|
|
Loading…
Reference in New Issue