graph_properties.cc 2.25 KB
Newer Older
Tiago Peixoto's avatar
Tiago Peixoto committed
1
2
// graph-tool -- a general graph modification and manipulation thingy
//
Tiago Peixoto's avatar
Tiago Peixoto committed
3
// Copyright (C) 2007-2011 Tiago de Paula Peixoto <tiago@skewed.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
17
// along with this program. If not, see <http://www.gnu.org/licenses/>.

18
#include "graph.hh"
Tiago Peixoto's avatar
Tiago Peixoto committed
19
#include "graph_properties.hh"
20
#include "graph_filtering.hh"
21
#include "graph_selectors.hh"
22
#include "graph_util.hh"
Tiago Peixoto's avatar
Tiago Peixoto committed
23

24
25
#include <boost/mpl/for_each.hpp>

26
27
#include <boost/python/extract.hpp>

28
29
30
31
using namespace std;
using namespace boost;
using namespace graph_tool;

32
33
namespace graph_tool
{
34

35
// global property types' names
36
const char* type_names[] =
37
38
    {"bool", "int32_t", "int64_t", "double", "long double",
     "string", "vector<bool>","vector<int32_t>", "vector<int64_t>",
39
40
     "vector<double>", "vector<long double>", "vector<string>",
     "python::object"};
41
42


43
struct shift_vertex_property
44
{
45
46
47
    template <class PropertyMap>
    void operator()(PropertyMap, const GraphInterface::multigraph_t& g,
                    boost::any map, size_t vi, bool& found) const
Tiago Peixoto's avatar
Tiago Peixoto committed
48
    {
49
        try
Tiago Peixoto's avatar
Tiago Peixoto committed
50
        {
51
52
53
            PropertyMap pmap = any_cast<PropertyMap>(map);
            for (size_t i = vi; i < num_vertices(g)-1; ++i)
                pmap[vertex(i,g)] = pmap[vertex(i+1,g)];
54
            found = true;
55
        }
56
        catch (bad_any_cast&) {}
57
    }
58
59
};

60
61
// this function will shift all the properties when a vertex is to be deleted
void GraphInterface::ShiftVertexProperty(boost::any prop, size_t index) const
62
{
63
    bool found = false;
64
    mpl::for_each<writable_vertex_properties>
Tiago Peixoto's avatar
Tiago Peixoto committed
65
        (bind<void>(shift_vertex_property(), _1, ref(_state->_mg),
66
                    prop, index, ref(found)));
67
    if (!found)
68
        throw GraphException("invalid writable property map");
69
}
70

71
} // graph_tool namespace