rename all Evoral source from .(hpp|cpp)$ to .(h|cc)
[ardour.git] / libs / ardour / ardour / route_graph.h
1 /*
2  * Copyright (C) 2015-2016 Robin Gareus <robin@gareus.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18
19 #ifndef __ardour_route_graph_h__
20 #define __ardour_route_graph_h__
21
22 #include <map>
23 #include <set>
24
25 namespace ARDOUR {
26
27 typedef boost::shared_ptr<Route> GraphVertex;
28
29 /** A list of edges for a directed graph for routes.
30  *
31  *  It keeps the same data in a few different ways, with add() adding edges
32  *  to all different representations, remove() removing similarly, and the
33  *  lookup method using whichever representation is most efficient for
34  *  that particular lookup.
35  *
36  *  This may be a premature optimisation...
37  */
38 class LIBARDOUR_API GraphEdges
39 {
40 public:
41         typedef std::map<GraphVertex, std::set<GraphVertex> > EdgeMap;
42
43         void add (GraphVertex from, GraphVertex to, bool via_sends_only);
44         bool has (GraphVertex from, GraphVertex to, bool* via_sends_only);
45         bool feeds (GraphVertex from, GraphVertex to);
46         std::set<GraphVertex> from (GraphVertex r) const;
47         void remove (GraphVertex from, GraphVertex to);
48         bool has_none_to (GraphVertex to) const;
49         bool empty () const;
50         void dump () const;
51
52 private:
53         void insert (EdgeMap& e, GraphVertex a, GraphVertex b);
54
55         typedef std::multimap<GraphVertex, std::pair<GraphVertex, bool> > EdgeMapWithSends;
56
57         EdgeMapWithSends::iterator find_in_from_to_with_sends (GraphVertex, GraphVertex);
58         EdgeMapWithSends::iterator find_recursively_in_from_to_with_sends (GraphVertex, GraphVertex);
59
60         /** map of edges with from as `first' and to as `second' */
61         EdgeMap _from_to;
62         /** map of the same edges with to as `first' and from as `second' */
63         EdgeMap _to_from;
64         /** map of edges with via-sends information; first part of the map is
65             the `from' vertex, second is the `to' vertex and a flag which is
66             true if the edge is via a send only.
67         */
68         EdgeMapWithSends _from_to_with_sends;
69 };
70
71 boost::shared_ptr<RouteList> topological_sort (
72         boost::shared_ptr<RouteList>,
73         GraphEdges
74         );
75
76 }
77
78 #endif