diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-18 00:41:56 +0100 |
---|---|---|
committer | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2015-01-18 00:41:56 +0100 |
commit | 5c53ea8fb93f611a90099000fb0ba3b0874f99c5 (patch) | |
tree | 085c7e8d18cec1ad0d27d0729c2a310c546442b3 /src/core/model/Node.cpp | |
parent | d935bf07d15ddd117d07d83bb3818b6abc23cc0b (diff) |
Implemented some helper functions to facilitate implementing doValidate methods. This includes the "validateName" function (which makes sure the Node has a valid identifier), the "continueValidation" function (which descends into the given list of child nodes) and the "continueValidationCheckDuplicates" which descends into the given child list and makes sure the names of the child nodes are unique.
Diffstat (limited to 'src/core/model/Node.cpp')
-rw-r--r-- | src/core/model/Node.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/core/model/Node.cpp b/src/core/model/Node.cpp index 7565ba9..e432aff 100644 --- a/src/core/model/Node.cpp +++ b/src/core/model/Node.cpp @@ -23,6 +23,7 @@ #include <core/common/Logger.hpp> #include <core/common/Rtti.hpp> #include <core/common/TypedRttiBuilder.hpp> +#include <core/common/Utils.hpp> #include "Node.hpp" @@ -353,8 +354,31 @@ std::vector<ResolutionResult> Node::resolve(const std::string &name, return resolve(std::vector<std::string>{name}, type); } +bool Node::checkDuplicate(Handle<Node> elem, + std::unordered_set<std::string> &names, + Logger &logger) const +{ + const std::string &name = elem->getName(); + if (!names.emplace(name).second) { + logger.error(std::string("Element with name \"") + name + + std::string("\" defined multiple times.")); + return false; + } + return true; +} + bool Node::doValidate(Logger &logger) const { return true; } +bool Node::validateName(Logger &logger) const +{ + if (!Utils::isIdentifier(name)) { + logger.error(type().name + std::string(" name \"") + name + + std::string("\" is not a valid identifier")); + return false; + } + return true; +} + void Node::invalidate() { // Only perform the invalidation if necessary |