From 5c53ea8fb93f611a90099000fb0ba3b0874f99c5 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Sun, 18 Jan 2015 00:41:56 +0100 Subject: 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. --- src/core/model/Node.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/core/model/Node.cpp') 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 #include #include +#include #include "Node.hpp" @@ -353,8 +354,31 @@ std::vector Node::resolve(const std::string &name, return resolve(std::vector{name}, type); } +bool Node::checkDuplicate(Handle elem, + std::unordered_set &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 -- cgit v1.2.3