graph_filtering.hh 22.6 KB
Newer Older
Tiago Peixoto's avatar
Tiago Peixoto committed
1
2
// graph-tool -- a general graph modification and manipulation thingy
//
3
// Copyright (C) 2007-2010 Tiago de Paula Peixoto <tiago@forked.de>
Tiago Peixoto's avatar
Tiago Peixoto committed
4
5
6
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
Tiago Peixoto's avatar
Tiago Peixoto committed
7
// as published by the Free Software Foundation; either version 3
Tiago Peixoto's avatar
Tiago Peixoto committed
8
9
10
11
12
13
14
15
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
16
// along with this program. If not, see <http://www.gnu.org/licenses/>.
Tiago Peixoto's avatar
Tiago Peixoto committed
17
18
19
20
21
22
23
24

#ifndef FILTERING_HH
#define FILTERING_HH

#include <boost/graph/graph_traits.hpp>
#include <boost/graph/filtered_graph.hpp>
#include <boost/graph/reverse_graph.hpp>
#include <boost/mpl/vector.hpp>
25
26
#include <boost/mpl/erase.hpp>
#include <boost/mpl/clear.hpp>
Tiago Peixoto's avatar
Tiago Peixoto committed
27
28
29
30
31
32
#include <boost/mpl/map.hpp>
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/at.hpp>
#include <boost/mpl/or.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/logical.hpp>
33
34
35
36
37
38
39
40
41
42
#include <boost/mpl/inserter.hpp>
#include <boost/mpl/insert_range.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/plus.hpp>
#include <boost/mpl/divides.hpp>
#include <boost/mpl/arithmetic.hpp>
#include <boost/mpl/greater_equal.hpp>
#include <boost/mpl/comparison.hpp>
#include <boost/mpl/transform_view.hpp>
#include <boost/mpl/quote.hpp>
43
#include <boost/mpl/range_c.hpp>
44

45
#include "graph.hh"
Tiago Peixoto's avatar
Tiago Peixoto committed
46
47
#include "graph_adaptor.hh"
#include "graph_selectors.hh"
48
#include "graph_util.hh"
49
#include "graph_wrap.hh"
50
#include "mpl_nested_loop.hh"
51

52
namespace graph_tool
Tiago Peixoto's avatar
   
Tiago Peixoto committed
53
{
54

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using namespace boost;

// Graph filtering
// ---------------
//
// We want to generate versions of a template algorithm for every possible type
// of graph views. The types of graph views are the following:
//
//    - The original directed multigraph
//
//    - Filtered graphs, based on MaskFilter below. This amounts to a
//      filtered_graph for every combination of filtered and unfiltered vertex
//      or edge, i.e., 3.
//
//    - A reversed view of each directed graph (original + filtered)
//
//    - An undirected view of each directed (unreversed) graph (original +
//      filtered)
//
// The total number of graph views is then: 3 * 4 = 12
//
// The specific specialization can be called at run time (and generated at
// compile time) with the run_action() function, which takes as arguments the
// GraphInterface worked on, and the template functor to be specialized, which
// must take as first argument a pointer to a graph type, which itself must be a
// template parameter. Additionally, the function can be called optionally with
// up to 4 extra arguments, which must be MPL sequence instances corresponding
// to the type range of the extra arguments which must be passed to the template
// functor. The run_action() will not run the algorithm itself, but will instead
// return a functor (graph_action) which must be called either with no
// arguments, or with parameters of type boost::any which hold internally the
// type and values of the extra parameters to be passed to the action functor,
// and which will define the specialization to be chosen.
//
// Example:
//
// struct my_algorithm
// {
//     template <class Graph, class ValueType>
94
//     void operator()(Graph& g, ValueType val) const
95
96
97
98
99
100
101
//     {
//         ... do something ...
//     }
// };
//
// ...
//
102
// GraphInterface g;
103
104
// typedef mpl::vector<int, double, string> value_types;
// double foo = 42.0;
105
// run_action(g, my_algorithm(), value_types)(boost::any(foo));
106
107
108
109
//
// The above line will run my_algorithm::operator() with Graph being the
// appropriate graph view type and ValueType being 'double' and val = 42.0.

110
111
112
113
// Whenever no implementation is called, the following exception is thrown
class ActionNotFound: public GraphException
{
public:
114
115
116
117
118
119
120
121
    ActionNotFound(const boost::any& graph_view, const type_info& action,
                   const vector<const type_info*>& args);
    virtual const char * what () const throw ();
    virtual ~ActionNotFound() throw () {}
private:
    boost::any _graph_view;
    const type_info& _action;
    vector<const type_info*> _args;
122
};
123
124

namespace detail
125
{
126
127
128
129
130
131

// Implementation
// --------------
//
// The class MaskFilter below is the main filter predicate for the filtered
// graph view, based on descriptor property maps.  It filters out edges or
132
133
// vertices which are masked according to a property map with bool (actually
// uint8_t) value type.
134
135
136

template <class DescriptorProperty>
class MaskFilter
137
{
138
139
140
141
142
public:
    typedef typename property_traits<DescriptorProperty>::value_type value_t;
    MaskFilter(){}
    MaskFilter(DescriptorProperty filtered_property, bool invert)
        : _filtered_property(filtered_property), _invert(invert) {}
143

144
145
146
147
    template <class Descriptor>
    inline bool operator() (Descriptor d) const
    {
        // ignore if masked
Tiago Peixoto's avatar
   
Tiago Peixoto committed
148

149
        return get(_filtered_property, d) ^ _invert;
150

151
152
153
154
155
        // TODO: This is a critical section. It will be called for every vertex
        //       or edge in the graph, every time they're iterated
        //       through. Therefore, it must be guaranteed this is as optimized
        //       as possible.
    }
156

157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
private:
    DescriptorProperty _filtered_property;
    bool _invert;
};


// Metaprogramming
// ---------------
//
// We need to generate a type sequence with all the filtered graph views, which
// will be called all_graph_views.

// metafunction class to get the correct filter predicate
template <class Property>
struct get_predicate
Tiago Peixoto's avatar
Tiago Peixoto committed
172
{
173
174
    typedef MaskFilter<Property> type;
};
Tiago Peixoto's avatar
Tiago Peixoto committed
175

176
177
template <>
struct get_predicate<keep_all>
Tiago Peixoto's avatar
Tiago Peixoto committed
178
{
179
    typedef keep_all type;
Tiago Peixoto's avatar
Tiago Peixoto committed
180
181
};

182
183
// metafunction to get the filtered graph type
struct graph_filter
Tiago Peixoto's avatar
Tiago Peixoto committed
184
{
185
186
187
    template <class Graph, class EdgeProperty, class VertexProperty>
    struct apply
    {
188

189
190
191
192
193
        typedef typename get_predicate<EdgeProperty>::type edge_predicate;
        typedef typename get_predicate<VertexProperty>::type vertex_predicate;

        typedef filtered_graph<Graph,
                               edge_predicate,
Tiago Peixoto's avatar
Tiago Peixoto committed
194
                               vertex_predicate> filtered_graph_t;
195
196
197
198
199
200
201
202

        // If both predicates are keep_all, then return the original graph
        // type. Otherwise return the filtered_graph type.
        typedef typename mpl::if_<
            typename mpl::and_<
                is_same<edge_predicate,
                        keep_all>,
                is_same<vertex_predicate,
203
                        keep_all>
204
205
                >::type,
            Graph,
Tiago Peixoto's avatar
Tiago Peixoto committed
206
            filtered_graph_t>::type type;
207
    };
Tiago Peixoto's avatar
Tiago Peixoto committed
208
209
};

210
211
// metafunction to get the undirected graph type
struct graph_undirect
Tiago Peixoto's avatar
Tiago Peixoto committed
212
213
{
    template <class Graph>
214
    struct apply
Tiago Peixoto's avatar
Tiago Peixoto committed
215
    {
216
217
        typedef UndirectedAdaptor<Graph> type;
    };
Tiago Peixoto's avatar
Tiago Peixoto committed
218
219
};

220
221
// metafunction to get the reversed graph type
struct graph_reverse
Tiago Peixoto's avatar
Tiago Peixoto committed
222
{
223
    template <class Graph>
224
225
226
227
    struct apply
    {
        typedef reverse_graph<Graph> type;
    };
Tiago Peixoto's avatar
Tiago Peixoto committed
228
229
};

230
231
232
233
234
235
236
237
238
239
// this wraps an unary metafunction class Bind into a unary metafunction,
// i.e., it is an identity operation. I'm not sure why it's necessary, but
// using pure unary bind expressions below didn't work for me, and this
// fixed it.
template <class Bind>
struct bind_wrap1
{
    template <class T1> struct apply
    { typedef typename Bind::template apply<T1>::type type; };
};
240

241
242
243
// metafunction which returns a mpl::vector containing all the pair combinations
// of two given type sequences
struct get_all_pairs
Tiago Peixoto's avatar
Tiago Peixoto committed
244
{
245
    struct make_pair
Tiago Peixoto's avatar
Tiago Peixoto committed
246
    {
247
248
249
250
251
252
        template <class T1, class T2>
        struct apply
        {
            typedef mpl::pair<T1,T2> type;
        };
    };
253

254
255
    template <class TR1, class TR2>
    struct apply
256
    {
257
        struct get_second_types
258
        {
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
            template <class T1>
            struct apply
            {
                typedef typename mpl::transform<
                    TR2,
                    bind_wrap1<
                        mpl::bind2<make_pair, T1, mpl::_1>
                    > >::type type;
            };
        };

        typedef typename mpl::transform<
            TR1,
            get_second_types,
            mpl::back_inserter<mpl::vector<> >
            >::type pair_combinations; // nested sequence (vector of vectors) of
                                       // pair combinations

        // joins two sequences
        struct join
        {
            template <class Seq1, class Seq2>
            struct apply
            {
                typedef typename boost::mpl::copy<
                    Seq2,
                    boost::mpl::back_inserter<Seq1>
                    >::type type;
            };
        };

        // flattens a nested sequence
        template<class Sequence>
        struct flatten
        {
            typedef typename boost::mpl::fold<
                Sequence,
                typename boost::mpl::clear<Sequence>::type,
                join
                >::type type;
        };

        // the complete list of combinations
        typedef typename flatten<pair_combinations>::type type;
    };
};

// metafunction class to get the correct property map type
template <class Scalar, class IndexMap>
struct get_property_map_type
{
310
311
    typedef typename property_map_type::apply<Scalar, IndexMap>
        ::type::unchecked_t type;
312
313
314
315
316
317
318
};

template <class IndexMap>
struct get_property_map_type<keep_all, IndexMap>
{
    typedef keep_all type;
};
319

320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
// this metafunction returns a filtered graph type, given the scalar types to be
// used in the property maps
struct get_graph_filtered
{
    template <class TypePair>
    struct apply
    {
        typedef typename TypePair::first edge_scalar;
        typedef typename TypePair::second vertex_scalar;

        // if the 'scalar' is the index map itself, use simply that, otherwise
        // get the specific property map
        typedef typename mpl::if_<
            is_same<edge_scalar,
                    GraphInterface::edge_index_map_t>,
            GraphInterface::edge_index_map_t,
            typename get_property_map_type<
                edge_scalar,
                GraphInterface::edge_index_map_t>::type
            >::type edge_property_map;

        typedef typename mpl::if_<
            is_same<vertex_scalar,
                    GraphInterface::vertex_index_map_t>,
            GraphInterface::vertex_index_map_t,
            typename get_property_map_type<
                vertex_scalar,
                GraphInterface::vertex_index_map_t>::type
            >::type vertex_property_map;

        typedef typename graph_filter::apply<GraphInterface::multigraph_t,
                                             edge_property_map,
                                             vertex_property_map>::type type;
353
    };
354
};
355

356
357
358
// this metafunction returns all the possible graph views
struct get_all_graph_views
{
359
    template <class TypePairs,
360
361
362
363
364
365
              class AlwaysDirected = mpl::bool_<false>,
              class NeverDirected = mpl::bool_<false>,
              class AlwaysReversed = mpl::bool_<false>,
              class NeverReversed = mpl::bool_<false>,
              class NeverFiltered = mpl::bool_<false> >
    struct apply
366
    {
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
        // filtered graphs
        struct filtered_graphs:
            mpl::if_
            <NeverFiltered,
             mpl::vector<GraphInterface::multigraph_t>,
             typename mpl::transform<TypePairs,
                                     get_graph_filtered>::type>::type {};

        // filtered + reversed graphs
        struct reversed_graphs:
            mpl::if_<AlwaysReversed,
                     typename mpl::transform<filtered_graphs,
                                             graph_reverse>::type,
                     typename mpl::if_<
                         NeverReversed,
                         filtered_graphs,
                         typename mpl::transform<
                             filtered_graphs,
                             graph_reverse,
                             mpl::back_inserter<filtered_graphs>
                             >::type
                         >::type
                >::type {};

        // undirected + filtereed + reversed graphs
        struct undirected_graphs:
            mpl::if_<AlwaysDirected,
394
                     reversed_graphs,
395
396
397
398
399
400
401
402
403
404
405
406
407
                     typename mpl::if_<
                         NeverDirected,
                         typename mpl::transform<filtered_graphs,
                                                 graph_undirect>::type,
                         typename mpl::transform<
                             filtered_graphs,
                             graph_undirect,
                             mpl::back_inserter<reversed_graphs>
                             >::type
                         >::type
                     >::type {};
        typedef undirected_graphs type;
    };
Tiago Peixoto's avatar
Tiago Peixoto committed
408
409
};

410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
// useful metafunction to split sequences in half
struct split
{
    template <class Sequence>
    struct get_element
    {
        template <class Index>
        struct apply
        {
            typedef typename mpl::at<Sequence,Index>::type type;
        };
    };

    template <class Sequence>
    struct apply
    {
        typedef typename mpl::size<Sequence>::type size;
        typedef typename mpl::divides<size, mpl::int_<2> >::type half_size;
        typedef typename mpl::transform<mpl::range_c<int, 0, half_size::value>,
                                        get_element<Sequence>,
                                        mpl::back_inserter<mpl::vector<> > >
            ::type first_part;
        typedef typename mpl::transform<mpl::range_c<int, half_size::value,
                                                     size::value>,
                                        get_element<Sequence>,
                                        mpl::back_inserter<mpl::vector<> > >
            ::type second_part;
        typedef typename mpl::pair<first_part,second_part> type;
    };
};



443
444
// all scalar types plus edge and vertex index property (we actually only use
// bool)
445

446
447
#ifndef NO_GRAPH_FILTERING
struct edge_scalars:
448
    mpl::vector<keep_all, uint8_t> {};
449
struct vertex_scalars:
450
    mpl::vector<keep_all, uint8_t> {};
451
452
453
454
455
456
#else
struct edge_scalars:
    mpl::vector<keep_all> {};
struct vertex_scalars:
    mpl::vector<keep_all> {};
#endif
457

458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
// all scalar pairs
struct scalar_pairs: get_all_pairs::apply<edge_scalars,vertex_scalars>::type {};

// finally, this type should hold all the possible graph views
struct all_graph_views:
    get_all_graph_views::apply<scalar_pairs>::type {};

// restricted graph views
struct always_directed:
    get_all_graph_views::apply<scalar_pairs,mpl::bool_<true> >::type {};

struct never_directed:
    get_all_graph_views::apply<scalar_pairs,mpl::bool_<false>,
                               mpl::bool_<true> >::type {};

struct always_reversed:
    get_all_graph_views::apply<scalar_pairs,mpl::bool_<true>,
                               mpl::bool_<false>,mpl::bool_<true> >::type {};

struct never_reversed:
478
    get_all_graph_views::apply<scalar_pairs,mpl::bool_<false>,
479
480
                               mpl::bool_<false>,mpl::bool_<false>,
                               mpl::bool_<true> >::type {};
481
482
483
484
485
486

struct always_directed_never_reversed:
    get_all_graph_views::apply<scalar_pairs,mpl::bool_<true>,
                               mpl::bool_<false>,mpl::bool_<false>,
                               mpl::bool_<true> >::type {};

487
488
489
490
491
492
493
494
495
496
497
498
struct never_filtered:
    get_all_graph_views::apply<scalar_pairs,mpl::bool_<false>,
                               mpl::bool_<false>,mpl::bool_<false>,
                               mpl::bool_<false>,mpl::bool_<true> >::type {};

// sanity check
typedef mpl::size<all_graph_views>::type n_views;
#ifndef NO_GRAPH_FILTERING
BOOST_MPL_ASSERT_RELATION(n_views::value, == , mpl::int_<12>::value);
#else
BOOST_MPL_ASSERT_RELATION(n_views::value, == , mpl::int_<3>::value);
#endif
Tiago Peixoto's avatar
Tiago Peixoto committed
499

500
501
// run_action() implementation
// ===========================
502
503
504

// wrap action to be called, to deal with property maps, i.e., return version
// with no bounds checking.
505
template <class Action, class Wrap>
506
507
struct action_wrap
{
508
509
    action_wrap(Action a, GraphInterface& g, size_t max_v, size_t max_e)
        : _a(a), _g(g), _max_v(max_v), _max_e(max_e) {}
510
511

    template <class Type>
512
    typename checked_vector_property_map
513
        <Type,GraphInterface::vertex_index_map_t>::unchecked_t
514
    uncheck(checked_vector_property_map
515
516
517
518
519
520
            <Type,GraphInterface::vertex_index_map_t> a) const
    {
        return a.get_unchecked(_max_v);
    }

    template <class Type>
521
    typename checked_vector_property_map
522
        <Type,GraphInterface::edge_index_map_t>::unchecked_t
523
    uncheck(checked_vector_property_map
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
            <Type,GraphInterface::edge_index_map_t> a) const
    {
        return a.get_unchecked(_max_e);
    }

    template <class Type>
    scalarS<typename Type::unchecked_t>
    uncheck(scalarS<Type> a) const
    {
        return scalarS<typename Type::unchecked_t>(uncheck(a._pmap));
    }

    //no op
    template <class Type>
    Type uncheck(Type a) const { return a; }

540
541
542
543
544
545
546
547
548
549
550
551
    template <class Graph>
    GraphWrap<Graph> wrap(Graph* g, mpl::true_) const
    {
        return graph_wrap(*g, _g);
    }

    template <class Graph>
    Graph& wrap(Graph* g, mpl::false_) const
    {
        return *g;
    }

552
    void operator()() const {};
553
    template <class T1> void operator()(const T1& a1) const { _a(wrap(a1, Wrap())); }
554
555
    template <class T1, class T2>
    void operator()(const T1& a1, const T2& a2) const
556
    { _a(wrap(a1,Wrap()), uncheck(a2)); }
557
558
    template <class T1, class T2, class T3>
    void operator()(const T1& a1, const T2& a2, const T3& a3) const
559
    { _a(wrap(a1,Wrap()), uncheck(a2), uncheck(a3));}
560
561
562
    template <class T1, class T2, class T3, class T4>
    void operator()(const T1& a1, const T2& a2, const T3& a3, const T4& a4)
        const
563
    { _a(wrap(a1,Wrap()), uncheck(a2), uncheck(a3), uncheck(a4)); }
564
565
566
    template <class T1, class T2, class T3, class T4, class T5>
    void operator()(const T1& a1, const T2& a2, const T3& a3, const T4& a4,
                    const T5& a5) const
567
    { _a(wrap(a1,Wrap()), uncheck(a2), uncheck(a3), uncheck(a4), uncheck(a5)); }
568
569

    Action _a;
570
    reference_wrapper<GraphInterface> _g;
571
572
573
    size_t _max_v, _max_e;
};

574
575
// this functor encapsulates another functor Action, which takes a pointer to a
// graph view as first argument
576
577
template <class Action, class GraphViews, class Wrap, class TR1, class TR2,
          class TR3, class TR4 >
578
struct graph_action
Tiago Peixoto's avatar
Tiago Peixoto committed
579
{
580
581
582
    struct graph_view_pointers:
        mpl::transform<GraphViews, mpl::quote1<add_pointer> >::type {};

583
584
    graph_action(GraphInterface& g, Action a)
        : _g(g), _a(a, g, num_vertices(g._mg), g._max_edge_index + 1) {}
Tiago Peixoto's avatar
Tiago Peixoto committed
585

586
    void operator()() const
Tiago Peixoto's avatar
Tiago Peixoto committed
587
    {
588
589
590
591
592
        bool found = false;
        boost::any gview = _g.GetGraphView();
        boost::mpl::for_each<graph_view_pointers>
            (boost::mpl::select_types(_a, found, gview));
        if (!found)
593
        {
594
595
            throw ActionNotFound(gview, typeid(Action),
                                 vector<const type_info*>());
596
        }
Tiago Peixoto's avatar
Tiago Peixoto committed
597
598
    }

599
    void operator()(boost::any a1) const
600
    {
601
602
603
604
605
        bool found = false;
        boost::any gview = _g.GetGraphView();
        boost::mpl::nested_for_each<graph_view_pointers,TR1>()
            (boost::mpl::select_types(_a, found, gview, a1));
        if (!found)
606
        {
607
608
            vector<const type_info*> args;
            args.push_back(&a1.type());
609
            throw ActionNotFound(gview, typeid(Action), args);
610
        }
Tiago Peixoto's avatar
Tiago Peixoto committed
611
612
    }

613
614
615
616
617
618
619
620
    void operator()(boost::any a1, boost::any a2) const
    {
        bool found = false;
        boost::any gview = _g.GetGraphView();
        boost::mpl::nested_for_each<graph_view_pointers,TR1,TR2>()
            (boost::mpl::select_types(_a, found, gview, a1, a2));
        if (!found)
        {
621
622
623
            vector<const type_info*> args;
            args.push_back(&a1.type());
            args.push_back(&a2.type());
624
625
626
            throw ActionNotFound(gview, typeid(Action), args);
        }
    }
Tiago Peixoto's avatar
Tiago Peixoto committed
627

628
    void operator()(boost::any a1, boost::any a2, boost::any a3) const
Tiago Peixoto's avatar
Tiago Peixoto committed
629
    {
630
631
632
633
634
635
        bool found = false;
        boost::any gview = _g.GetGraphView();
        boost::mpl::nested_for_each<graph_view_pointers,TR1,TR2,TR3>()
            (boost::mpl::select_types(_a, found, gview, a1, a2, a3));
        if (!found)
        {
636
637
638
639
            vector<const type_info*> args;
            args.push_back(&a1.type());
            args.push_back(&a2.type());
            args.push_back(&a3.type());
640
641
            throw ActionNotFound(gview, typeid(Action), args);
        }
Tiago Peixoto's avatar
Tiago Peixoto committed
642
643
    }

644
645
    void operator()(boost::any a1, boost::any a2, boost::any a3,
                    boost::any a4) const
646
    {
647
648
649
650
651
        bool found = false;
        boost::any gview = _g.GetGraphView();
        boost::mpl::nested_for_each<graph_view_pointers,TR1,TR2,TR3,TR4>()
            (boost::mpl::select_types(_a, found, gview, a1, a2, a3,a4));
        if (!found)
652
        {
653
654
655
656
657
            vector<const type_info*> args;
            args.push_back(&a1.type());
            args.push_back(&a2.type());
            args.push_back(&a3.type());
            args.push_back(&a4.type());
658
            throw ActionNotFound(gview, typeid(Action), args);
659
        }
Tiago Peixoto's avatar
Tiago Peixoto committed
660
661
    }

662
    const GraphInterface &_g;
663
    action_wrap<Action, Wrap> _a;
Tiago Peixoto's avatar
Tiago Peixoto committed
664
};
665
} // details namespace
Tiago Peixoto's avatar
Tiago Peixoto committed
666

667

668
// all definitions of run_action with different arity
669
template <class GraphViews = detail::all_graph_views, class Wrap = mpl::false_>
670
struct run_action
Tiago Peixoto's avatar
Tiago Peixoto committed
671
{
672
    template <class Action>
673
674
    detail::graph_action<Action,GraphViews,Wrap>
    operator()(GraphInterface &g, Action a)
675
    {
676
        return detail::graph_action<Action,GraphViews,Wrap>(g, a);
677
    }
678
679

    template <class Action, class TR1>
680
681
    detail::graph_action<Action,GraphViews,Wrap,TR1>
    operator()(GraphInterface &g, Action a, TR1)
682
    {
683
        return detail::graph_action<Action,GraphViews,Wrap,TR1>(g, a);
684
    }
Tiago Peixoto's avatar
Tiago Peixoto committed
685

686
    template <class Action, class TR1, class TR2>
687
688
    detail::graph_action<Action,GraphViews,Wrap,TR1,TR2>
    operator()(GraphInterface &g, Action a, TR1, TR2)
689
    {
690
        return detail::graph_action<Action,GraphViews,Wrap,TR1,TR2>(g, a);
691
    }
692

693
    template <class Action, class TR1, class TR2, class TR3>
694
695
    detail::graph_action<Action,GraphViews,Wrap,TR1,TR2,TR3>
    operator()(GraphInterface &g, Action a, TR1, TR2, TR3)
696
    {
697
        return detail::graph_action<Action,GraphViews,Wrap,TR1,TR2,TR3>(g, a);
698
    }
699

700
    template <class Action, class TR1, class TR2, class TR3, class TR4>
701
702
    detail::graph_action<Action,GraphViews,Wrap,TR1,TR2,TR3,TR4>
    operator()(GraphInterface &g, Action a, TR1, TR2, TR3, TR4)
703
    {
704
        return detail::graph_action<Action,GraphViews,Wrap,TR1,TR2,TR3,TR4>(g, a);
705
706
    }
};
707

708
709
710
// returns true if graph filtering was enabled at compile time
bool graph_filtering_enabled();

711
} //graph_tool namespace
712

Tiago Peixoto's avatar
   
Tiago Peixoto committed
713
#endif // FILTERING_HH