From ca414c19fd8f2658403b189bfccad11ad2db048b Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Wed, 28 Jan 2015 01:06:13 +0100 Subject: Added methods for checking a property for acyclicity (or however this is supposed to be called) --- src/core/model/Node.hpp | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'src/core/model/Node.hpp') diff --git a/src/core/model/Node.hpp b/src/core/model/Node.hpp index 60d22e0..036bcae 100644 --- a/src/core/model/Node.hpp +++ b/src/core/model/Node.hpp @@ -31,8 +31,8 @@ #include #include #include -#include #include +#include #include #include @@ -155,6 +155,7 @@ private: * vector. * * @param p is the list the path should be constructed in. + * @param root is a node at which building the path should be aborted. */ void path(std::vector &p, Handle root) const; @@ -215,6 +216,30 @@ private: std::unordered_set &names, Logger &logger) const; + /** + * Callback function used to access a Node reference stored inside another + * Node. + * + * @param thisRef is the Node of which the reference should be returned. + * @return the value of the reference. + */ + using NodeReferenceCallback = const Node* (const Node* thisRef); + + /** + * Checks whether the a certain property is acyclic. + * + * @param path is a path containing the cycle. If no cycle is found, the + * path will be empty. + * @param visited a set of visited nodes used for cycle detection. + * @param callback is the callback that is used to access the underlying + * property that should be checked for acyclicity. + * @return true if the node is acyclic regarding this property, false if + * a cycle was detected. The cycle is stored in the "path". + */ + bool checkIsAcyclic(std::vector &path, + std::unordered_set &visited, + NodeReferenceCallback callback) const; + protected: /** * Sets the parent node. @@ -364,6 +389,28 @@ protected: */ bool validateName(Logger &logger) const; + /** + * Makes sure the property accessed by the callback is not cyclic. + * + * @param name is the name of the property. The passed name is used to build + * a nice error message. + * @param callback is the callback that is used to access the property. + * @param logger is the logger instance to which an error message containing + * the cycle is logged. + * @return true if the parent reference is acyclic, false otherwise. + */ + bool validateIsAcyclic(const std::string &name, + NodeReferenceCallback callback, Logger &logger) const; + + /** + * Makes sure the "parent" reference is not cyclic. + * + * @param logger is the logger instance to which an error message containing + * the cycle is logged. + * @return true if the parent reference is acyclic, false otherwise. + */ + bool validateParentIsAcyclic(Logger &logger) const; + /** * Helper function that can be used to forward the validation process to * child nodes. -- cgit v1.2.3