From 8db5ff97ffe34aa42f71b5c8aebfa0878e5fde89 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 4 Jul 2020 16:58:08 +0200 Subject: Add error message support and reporting on all commands. --- src/nodetree.h | 49 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 13 deletions(-) (limited to 'src/nodetree.h') diff --git a/src/nodetree.h b/src/nodetree.h index f2f4600..41f7272 100644 --- a/src/nodetree.h +++ b/src/nodetree.h @@ -29,7 +29,6 @@ #include #include -#include #include "node.h" @@ -54,33 +53,57 @@ public: ~NodeTree(); nodeid_t createId(); - bool hasId(nodeid_t nodeid); + bool hasId(nodeid_t nodeid) const; + //! May throw: + //! - Error::MissingParent if the parent node id does not exist in the tree. + //! - Error::NoSuchId if the ancestorList cannot be made from the supplied id. + //! - Error::IdAlreadyExists if the supplied id already exists in the tree. + //! - Error::NewParentIsSelf if id and parentid are the same. NodeIdList insertAsChild(nodeid_t parentid, nodeid_t id, node_t data, - nodeid_t insertBeforeId) throw (std::exception); - NodeIdList remove(nodeid_t id) throw (std::exception); - NodeIdList move(nodeid_t id, nodeid_t newParentId, - nodeid_t insertBeforeId) throw (std::exception); + nodeid_t insertBeforeId); + + //! May throw: + //! - Error::NoSuchId if node id does not exist. + //! - Error::ProtectedNode if node is protected and cannot be removed. + NodeIdList remove(nodeid_t id); + + //! May throw: + //! - Error::NewParentIsSelf if id and parentid are the same. + //! - Error::NoSuchId if node id does not exist. + //! - Error::MissingParent if new parent node does not exist. + //! - Error::ProtectedNode if node is protected and cannot be (re)moved. + NodeIdList move(nodeid_t id, nodeid_t newParentId, nodeid_t insertBeforeId); + + //! May throw: + //! - Error::NoSuchId if node id does not exist. NodeIdList updateData(nodeid_t id, const std::string &name, - const std::string &value) throw (std::exception); - node_t data(nodeid_t id) throw (std::exception); + const std::string &value); - NodeIdList bfs(nodeid_t id) throw (std::exception); + //! May throw: + //! - Error::NoSuchId if node id does not exist. + node_t data(nodeid_t id); - NodeIdList ancestorList(nodeid_t id) throw (std::exception); + //! May throw: + //! - Error::NoSuchId if node id does not exist. + NodeIdList bfs(nodeid_t id); + + //! May throw: + //! - Error::NoSuchId if node id does not exist. + NodeIdList ancestorList(nodeid_t id); void toStdOut(); std::string toXML(); - void fromXML(const std::string& xml); - nodeid_t nextid; + void fromXML(const std::string& xml); private: friend class XmlParser; Node* createNode(nodeid_t id); void insertChild(Node* parent, Node* child, nodeid_t insertBeforeId); - Node* root; + nodeid_t nextid{10}; + Node* root{nullptr}; std::map id2node; }; -- cgit v1.2.3