From bada6666c70977a058755ccf232e7d67b24adeed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Wed, 23 Jul 2014 15:21:29 +0200 Subject: New upstream release --- libcutl/cutl/container/graph.hxx | 217 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 217 insertions(+) create mode 100644 libcutl/cutl/container/graph.hxx (limited to 'libcutl/cutl/container/graph.hxx') diff --git a/libcutl/cutl/container/graph.hxx b/libcutl/cutl/container/graph.hxx new file mode 100644 index 0000000..9c1afe2 --- /dev/null +++ b/libcutl/cutl/container/graph.hxx @@ -0,0 +1,217 @@ +// file : cutl/container/graph.hxx +// copyright : Copyright (c) 2009-2013 Code Synthesis Tools CC +// license : MIT; see accompanying LICENSE file + +#ifndef CUTL_CONTAINER_GRAPH_HXX +#define CUTL_CONTAINER_GRAPH_HXX + +#include + +#include +#include + +#include + +namespace cutl +{ + namespace container + { + struct LIBCUTL_EXPORT no_edge: exception {}; + struct LIBCUTL_EXPORT no_node: exception {}; + + template + class graph + { + public: + typedef N node_base; + typedef E edge_base; + + public: + template + T& + new_node (); + + template + T& + new_node (A0 const&); + + template + T& + new_node (A0 const&, A1 const&); + + template + T& + new_node (A0 const&, A1 const&, A2 const&); + + template + T& + new_node (A0 const&, A1 const&, A2 const&, A3 const&); + + template + T& + new_node (A0 const&, A1 const&, A2 const&, A3 const&, A4 const&); + + template + T& + new_node (A0 const&, A1 const&, A2 const&, A3 const&, A4 const&, + A5 const&); + + template + T& + new_node (A0 const&, A1 const&, A2 const&, A3 const&, A4 const&, + A5 const&, A6 const&); + + template + T& + new_node (A0 const&, A1 const&, A2 const&, A3 const&, A4 const&, + A5 const&, A6 const&, A7 const&); + + template + T& + new_node (A0 const&, A1 const&, A2 const&, A3 const&, A4 const&, + A5 const&, A6 const&, A7 const&, A8 const&); + + template + T& + new_node (A0 const&, A1 const&, A2 const&, A3 const&, A4 const&, + A5 const&, A6 const&, A7 const&, A8 const&, A9 const&); + + // Non-const versions. + // + template + T& + new_node (A0&); + + template + T& + new_node (A0&, A1&); + + template + T& + new_node (A0&, A1&, A2&); + + public: + template + T& + new_edge (L&, R&); + + template + T& + new_edge (L&, R&, A0 const&); + + template + T& + new_edge (L&, R&, A0 const&, A1 const&); + + template + T& + new_edge (L&, R&, A0 const&, A1 const&, A2 const&); + + template + T& + new_edge (L&, R&, A0 const&, A1 const&, A2 const&, A3 const&); + + template + T& + new_edge (L&, R&, A0 const&, A1 const&, A2 const&, A3 const&, + A4 const&); + + template + T& + new_edge (L&, R&, A0 const&, A1 const&, A2 const&, A3 const&, + A4 const&, A5 const&); + + // Functions to reset edge's nodes. + // + public: + template + void + reset_left_node (TE& edge, TN& node) + { + edge.set_left_node (node); + } + + template + void + reset_right_node (TE& edge, TN& node) + { + edge.set_right_node (node); + } + + // Functions to add edges to a node. + // + public: + template + void + add_edge_left (TN& node, TE& edge) + { + node.add_edge_left (edge); + } + + template + void + add_edge_right (TN& node, TE& edge) + { + node.add_edge_right (edge); + } + + // Functions to delete edges and nodes. In order to delete a + // a node without leaving any dangling edges you need to make + // sure that each edge pointing to it is either deleted or reset + // to some other node. + // + public: + template + void + delete_edge (L& left_node, R& right_node, T& edge); + + void + delete_node (node_base& node) + { + if (nodes_.erase (&node) == 0) + throw no_node (); + } + + public: + graph () {} + + private: + graph (graph const&); + + graph& + operator= (graph const&); + + protected: + typedef shared_ptr node_ptr; + typedef shared_ptr edge_ptr; + + typedef std::map nodes; + typedef std::map edges; + + nodes nodes_; + edges edges_; + }; + } +} + +#include + +#endif // CUTL_CONTAINER_GRAPH_HXX -- cgit v1.2.3