Graph C++ Library
 All Classes Namespaces Files Functions Variables Typedefs Groups Pages
base_vertex.hpp
Go to the documentation of this file.
1 
10 #ifndef BASE_VERTEX_HPP_INCLUDED
11 #define BASE_VERTEX_HPP_INCLUDED
12 
13 // Standard Library
14 #include <list>
15 #include <string>
16 #include <vector>
17 
19 namespace gcl
20 {
21 
29  template <class EdgeAttributesType>
31  {
32  // ============================================================================================
33  // *** Objects related to the vertex.
34  public:
35  typedef typename std::list< EdgeAttributesType >::iterator iterator;
36  private:
37  unsigned int nb_of_types_of_degrees;
38  // ============================================================================================
39  // *** Information about the vertex.
40  private:
41  std::string name;
42  std::vector< std::list< EdgeAttributesType > > neighbours;
43  std::vector< unsigned int > degrees;
44  // ============================================================================================
45  // *** Member functions.
46  public:
48  virtual ~base_vertex() {}
49  std::string get_name();
50  void set_name(std::string _name);
51  unsigned int get_base_vertex_degrees(unsigned int _type);
52  virtual void clear() = 0;
53  protected:
54  void set_nb_of_types_of_degrees(unsigned int _value);
55  void base_vertex_neighbour_insert(unsigned int _type, EdgeAttributesType _info);
56  iterator base_vertex_neighbour_begin(unsigned int _type);
57  iterator base_vertex_neighbour_end(unsigned int _type);
58  void base_vertex_clear();
59  };
60 
61 } // End of namespace gcl.
62 
63 
64 
65 // ================================================================================================
66 // ================================================================================================
67 template <class EdgeAttributesType>
69 {
70  return name;
71 }
72 
73 // ================================================================================================
74 // ================================================================================================
75 template <class EdgeAttributesType>
77 {
78  return degrees[_type];
79 }
80 
81 // ================================================================================================
82 // ================================================================================================
83 template <class EdgeAttributesType>
85 {
86  name = _name;
87 }
88 
89 // ================================================================================================
90 // ================================================================================================
91 template <class EdgeAttributesType>
93 {
94  nb_of_types_of_degrees = _value;
95 }
96 
97 // ================================================================================================
98 // ================================================================================================
99 template <class EdgeAttributesType>
100 void gcl::base_vertex<EdgeAttributesType>::base_vertex_neighbour_insert(unsigned int _type, EdgeAttributesType _info)
101 {
102  // Increases the degree of the vertex.
103  degrees[_type] += 1;
104  // Adds a vertex to the neighbours list.
105  neighbours[_type].push_back(_info);
106 }
107 
108 // ================================================================================================
109 // ================================================================================================
110 template <class EdgeAttributesType>
112 {
113  return neighbours[_type].begin();
114 }
115 
116 // ================================================================================================
117 // ================================================================================================
118 template <class EdgeAttributesType>
120 {
121  return neighbours[_type].end();
122 }
123 
124 // ================================================================================================
125 // ================================================================================================
126 template <class EdgeAttributesType>
128 {
129  // Resets the id of the vertex.
130  name = "00";
131  // Resets the neighbours.
132  neighbours.clear();
133  neighbours.resize(nb_of_types_of_degrees);
134  // Resets the degrees.
135  degrees.clear();
136  degrees.resize(nb_of_types_of_degrees,0);
137 }
138 
139 
140 
141 #endif // BASE_VERTEX_HPP_INCLUDED
void base_vertex_neighbour_insert(unsigned int _type, EdgeAttributesType _info)
Inserts the information of a new neighbour in the neighbours structure.
Definition: base_vertex.hpp:100
std::list< EdgeAttributesType >::iterator iterator
Typedef for iterators used to browse the neighbourhood of the vertex.
Definition: base_vertex.hpp:35
std::string get_name()
Returns the id of the vertex.
Definition: base_vertex.hpp:68
void set_name(std::string _name)
Sets the name of the vertex.
Definition: base_vertex.hpp:84
void set_nb_of_types_of_degrees(unsigned int _value)
Sets the number of types of degrees.
Definition: base_vertex.hpp:92
unsigned int get_base_vertex_degrees(unsigned int _type)
Returns the degree of type _type.
Definition: base_vertex.hpp:76
virtual void clear()=0
Reinitializes the vertex (specific variables).
base_vertex()
Constructor.
Definition: base_vertex.hpp:47
Virtual template base class for vertices in graphs.
Definition: base_vertex.hpp:30
virtual ~base_vertex()
Destructor.
Definition: base_vertex.hpp:48
iterator base_vertex_neighbour_begin(unsigned int _type)
Returns an iterator pointing at the begining of neighbours of type _type.
Definition: base_vertex.hpp:111
void base_vertex_clear()
Reinitializes the variables in the class base_vertex.
Definition: base_vertex.hpp:127
iterator base_vertex_neighbour_end(unsigned int _type)
Returns an iterator pointing at the end of neighbours of type _type.
Definition: base_vertex.hpp:119