graph_properties.cc 2.18 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  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
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_selectors.hh"
21
#include "graph_util.hh"
Tiago Peixoto's avatar
Tiago Peixoto committed
22

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

25
26
27
28
using namespace std;
using namespace boost;
using namespace graph_tool;

29
30
namespace graph_tool
{
31

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


40
struct shift_vertex_property
41
{
42
43
44
    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
45
    {
46
        try
Tiago Peixoto's avatar
Tiago Peixoto committed
47
        {
48
49
50
            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)];
51
            found = true;
52
        }
53
        catch (bad_any_cast&) {}
54
    }
55
56
};

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


69
} // graph_tool namespace