From ec2af24be3607eb5595d603cd9d9a4c0210c92c1 Mon Sep 17 00:00:00 2001 From: Username404-59 Date: Wed, 20 Oct 2021 13:16:40 +0200 Subject: [PATCH] Add a [] operator to the ParseTree class --- src/headers/parsing/ParseComponents.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/headers/parsing/ParseComponents.hpp b/src/headers/parsing/ParseComponents.hpp index eb90743..7a57e78 100644 --- a/src/headers/parsing/ParseComponents.hpp +++ b/src/headers/parsing/ParseComponents.hpp @@ -13,7 +13,7 @@ using namespace std; #include "../lex.hpp" -#define IS(X) template::value>::type* = nullptr> +#define IS(X) template::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>(); }; + IS(StandardComponents::NamedIdentifier) + inline auto operator[](const string& key) const { return findReferenceByName(key); } inline size_t getCompCount() const { return subComponents.size(); } IS_PARSECOMPONENT inline void add(const T& component) { addComponent(component); }; IS_PARSECOMPONENT inline void addAll(const initializer_list& components) { addAllComponents(components); }