graph_selectors.cc 1.62 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// graph-tool -- a general graph modification and manipulation thingy
//
// Copyright (C) 2007  Tiago de Paula Peixoto <tiago@forked.de>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// 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
// along with this program. If not, see <http://www.gnu.org/licenses/>.

18
#include <boost/lambda/bind.hpp>
19
20
#include <boost/variant/get.hpp>
#include "graph.hh"
21
22
23
#include "graph_selectors.hh"

using namespace graph_tool;
24
using namespace boost;
25
using namespace boost::lambda;
26
27

// retrieves the appropriate degree selector
28
boost::any graph_tool::degree_selector(GraphInterface::deg_t deg)
29
{
30
    boost::any sel;
31
32
    try
    {
33
        mpl::for_each<selectors>
34
35
36
            (bind<void>(get_degree_selector(), _1,
                        boost::get<GraphInterface::degree_t>(deg),
                        var(sel)));
37
    }
38
    catch (bad_get)
39
    {
40
41
42
43
44
45
        bool found = false;
        mpl::for_each<vertex_scalar_properties>
            (bind<void>(get_scalar_selector(), _1, boost::get<boost::any>(deg),
                        var(sel), var(found)));
        if (!found)
            throw GraphException("invalid degree selector");
46
    }
47
    return sel;
48
}