Add a [] operator to the ParseTree class
This commit is contained in:
parent
e8adf32645
commit
ec2af24be3
@ -13,7 +13,7 @@ using namespace std;
|
||||
|
||||
#include "../lex.hpp"
|
||||
|
||||
#define IS(X) template<typename T, typename std::enable_if<std::is_base_of<X, T>::value>::type* = nullptr>
|
||||
#define IS(X) template<typename T = X, typename std::enable_if<std::is_base_of<X, T>::value>::type* = nullptr>
|
||||
struct ParseComponent {
|
||||
[[nodiscard]] constexpr const type_info& getId() const { return typeid(*this); }
|
||||
virtual ~ParseComponent() = default;
|
||||
@ -88,6 +88,8 @@ public:
|
||||
}
|
||||
return optional<reference_wrapper<T>>();
|
||||
};
|
||||
IS(StandardComponents::NamedIdentifier)
|
||||
inline auto operator[](const string& key) const { return findReferenceByName<T>(key); }
|
||||
inline size_t getCompCount() const { return subComponents.size(); }
|
||||
IS_PARSECOMPONENT inline void add(const T& component) { addComponent<T>(component); };
|
||||
IS_PARSECOMPONENT inline void addAll(const initializer_list<T>& components) { addAllComponents<T>(components); }
|
||||
|
Loading…
Reference in New Issue
Block a user