File: DefaultColorMap.h

package info (click to toggle)
abyss 2.3.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,284 kB
  • sloc: cpp: 78,182; ansic: 6,512; makefile: 2,252; perl: 672; sh: 509; haskell: 412; python: 4
file content (56 lines) | stat: -rw-r--r-- 1,400 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef DEFAULTCOLORMAP_H
#define DEFAULTCOLORMAP_H

#include "UnorderedMap.h"
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/properties.hpp>

template <typename G>
class DefaultColorMap
{
public:

	typedef typename boost::graph_traits<G>::vertex_descriptor key_type;
	typedef typename boost::graph_traits<G>::vertex_descriptor& reference;
	typedef boost::default_color_type value_type;
	typedef boost::read_write_property_map_tag category;

	typedef unordered_map<key_type, value_type, hash<key_type> >
		map_type;
	map_type map;
};

namespace boost {
template <typename G>
struct property_traits< DefaultColorMap<G> > {
	typedef typename DefaultColorMap<G>::key_type key_type;
	typedef typename DefaultColorMap<G>::reference reference;
	typedef typename DefaultColorMap<G>::value_type value_type;
	typedef typename DefaultColorMap<G>::category category;
};
}

template <typename G>
typename DefaultColorMap<G>::value_type
get(const DefaultColorMap<G>& colorMap, typename DefaultColorMap<G>::key_type key)
{
	typedef typename DefaultColorMap<G>::map_type::const_iterator It;

	It i = colorMap.map.find(key);

	if (i != colorMap.map.end())
		return i->second;

	return boost::white_color;
}

template <typename G>
void
put(DefaultColorMap<G>& colorMap,
	typename DefaultColorMap<G>::key_type key,
	typename DefaultColorMap<G>::value_type value)
{
	colorMap.map[key] = value;
}

#endif