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