From ec6306ad1e746d47ed66af6274fb6710c70933a2 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Tue, 3 Feb 2015 22:54:17 +0100 Subject: Fixed XML-Importer failing --- src/core/parser/ParserScope.cpp | 21 +++++++++++++++++---- src/core/parser/ParserScope.hpp | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 47 insertions(+), 7 deletions(-) (limited to 'src/core/parser') diff --git a/src/core/parser/ParserScope.cpp b/src/core/parser/ParserScope.cpp index 1937697..b97dabd 100644 --- a/src/core/parser/ParserScope.cpp +++ b/src/core/parser/ParserScope.cpp @@ -90,10 +90,23 @@ Rooted ParserScopeBase::select(RttiSet types, int maxDepth) return nodes[i]; } } - throw LoggableException{ - std::string( - "Expected be inside an element of one of the internal types ") + - Utils::join(types, "\", \"", "\"", "\"")}; + return nullptr; +} + +Rooted ParserScopeBase::selectOrThrow(RttiSet types, int maxDepth) +{ + Rooted res = select(types, maxDepth); + if (res == nullptr) { + std::vector typenames; + for (auto type : types) { + typenames.push_back(type->name); + } + throw LoggableException{std::string( + "Expected to be inside an element of one " + "of the internal types ") + + Utils::join(typenames, "\", \"", "\"", "\"")}; + } + return res; } /* Class DeferredResolution */ diff --git a/src/core/parser/ParserScope.hpp b/src/core/parser/ParserScope.hpp index dc1b1bf..7be3c4a 100644 --- a/src/core/parser/ParserScope.hpp +++ b/src/core/parser/ParserScope.hpp @@ -143,6 +143,33 @@ public: */ Rooted getLeaf() const; + /** + * Ascends in the stack starting with the leaf node, returns the first node + * that matches the type given in the RttiSet or nullptr if none matches. + * + * @param types is a set of Rtti types for which should be searched in the + * stack. + * @param maxDepth is the maximum number of stack entries the selection + * function may ascend. A negative value indicates no limitation. + * @return the matching node or nullptr if the node was not found. + */ + Rooted select(RttiSet types, int maxDepth = -1); + + /** + * Ascends in the stack starting with the leaf node, returns the first node + * that matches the given type or nullptr if none matches. + * + * @tparam T is the type that should be searched in the stack. + * @param maxDepth is the maximum number of stack entries the selection + * function may ascend. A negative value indicates no limitation. + * @return the matching node or nullptr if the node was not found. + */ + template + Rooted select(int maxDepth = -1) + { + return select(RttiSet{&typeOf()}, maxDepth).cast(); + } + /** * Ascends in the stack starting with the leaf node, returns the first node * that matches the type given in the RttiSet. Throws an exception if no @@ -154,7 +181,7 @@ public: * function may ascend. A negative value indicates no limitation. * @return the matching node. */ - Rooted select(RttiSet types, int maxDepth = -1); + Rooted selectOrThrow(RttiSet types, int maxDepth = -1); /** * Ascends in the stack starting with the leaf node, returns the first node @@ -166,9 +193,9 @@ public: * @return the matching node. */ template - Rooted select(int maxDepth = -1) + Rooted selectOrThrow(int maxDepth = -1) { - return select(RttiSet{&typeOf()}, maxDepth).cast(); + return selectOrThrow(RttiSet{&typeOf()}, maxDepth).cast(); } }; -- cgit v1.2.3