diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-02-03 22:54:17 +0100 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-02-03 22:54:17 +0100 |
commit | ec6306ad1e746d47ed66af6274fb6710c70933a2 (patch) | |
tree | d00627f99142e62f98894861673a91e14c6eb834 /src/core/parser | |
parent | 7a8a8a31416cfebf785135754035608f4d919bf5 (diff) |
Fixed XML-Importer failing
Diffstat (limited to 'src/core/parser')
-rw-r--r-- | src/core/parser/ParserScope.cpp | 21 | ||||
-rw-r--r-- | src/core/parser/ParserScope.hpp | 33 |
2 files changed, 47 insertions, 7 deletions
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<Node> 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<Node> ParserScopeBase::selectOrThrow(RttiSet types, int maxDepth) +{ + Rooted<Node> res = select(types, maxDepth); + if (res == nullptr) { + std::vector<std::string> 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 @@ -145,6 +145,33 @@ public: /** * 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<Node> 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 <class T> + Rooted<T> select(int maxDepth = -1) + { + return select(RttiSet{&typeOf<T>()}, maxDepth).cast<T>(); + } + + /** + * 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 * node matches. * @@ -154,7 +181,7 @@ public: * function may ascend. A negative value indicates no limitation. * @return the matching node. */ - Rooted<Node> select(RttiSet types, int maxDepth = -1); + Rooted<Node> 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 <class T> - Rooted<T> select(int maxDepth = -1) + Rooted<T> selectOrThrow(int maxDepth = -1) { - return select(RttiSet{&typeOf<T>()}, maxDepth).cast<T>(); + return selectOrThrow(RttiSet{&typeOf<T>()}, maxDepth).cast<T>(); } }; |