Ignition Math

API Reference

6.8.0
Vertex.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef IGNITION_MATH_GRAPH_VERTEX_HH_
18 #define IGNITION_MATH_GRAPH_VERTEX_HH_
19 
20 // uint64_t
21 #include <cstdint>
22 #include <functional>
23 #include <iostream>
24 #include <map>
25 #include <string>
26 #include <utility>
27 
28 #include <ignition/math/config.hh>
29 #include <ignition/math/Helpers.hh>
30 
31 namespace ignition
32 {
33 namespace math
34 {
35 // Inline bracket to help doxygen filtering.
36 inline namespace IGNITION_MATH_VERSION_NAMESPACE {
37 namespace graph
38 {
41  using VertexId = uint64_t;
42 
46 
48  static const VertexId kNullId = MAX_UI64;
49 
53  template<typename V>
54  class Vertex
55  {
57  public: static Vertex<V> NullVertex;
58 
63  public: Vertex(const std::string &_name,
64  const V &_data = V(),
65  const VertexId _id = kNullId)
66  : name(_name),
67  data(_data),
68  id(_id)
69  {
70  }
71 
74  public: const V &Data() const
75  {
76  return this->data;
77  }
78 
81  public: V &Data()
82  {
83  return this->data;
84  }
85 
88  public: VertexId Id() const
89  {
90  return this->id;
91  }
92 
95  public: const std::string &Name() const
96  {
97  return this->name;
98  }
99 
102  public: void SetName(const std::string &_name)
103  {
104  this->name = _name;
105  }
106 
109  public: bool Valid() const
110  {
111  return this->id != kNullId;
112  }
113 
119  public: friend std::ostream &operator<<(std::ostream &_out,
120  const Vertex<V> &_v)
121  {
122  _out << " " << _v.Id() << " [label=\"" << _v.Name()
123  << " (" << _v.Id() << ")\"];" << std::endl;
124  return _out;
125  }
126 
128  private: std::string name = "";
129 
131  private: V data;
132 
134  private: VertexId id = kNullId;
135  };
136 
138  template<typename V>
139  Vertex<V> Vertex<V>::NullVertex("__null__", V(), kNullId);
140 
144  template<typename V>
145  using VertexRef_M =
147 }
148 }
149 }
150 }
151 #endif
V & Data()
Get a mutable reference to the user information.
Definition: Vertex.hh:81
const std::string & Name() const
Get the vertex name.
Definition: Vertex.hh:95
Vertex(const std::string &_name, const V &_data=V(), const VertexId _id=kNullId)
Constructor.
Definition: Vertex.hh:63
bool Valid() const
Whether the vertex is considered valid or not (id==kNullId).
Definition: Vertex.hh:109
A vertex of a graph. It stores user information, an optional name, and keeps an internal unique Id...
Definition: Vertex.hh:54
T endl(T... args)
static const uint64_t MAX_UI64
64bit unsigned integer maximum value
Definition: Helpers.hh:339
STL class.
STL class.
static const VertexId kNullId
Represents an invalid Id.
Definition: Vertex.hh:48
static Vertex< V > NullVertex
An invalid vertex.
Definition: Vertex.hh:57
void SetName(const std::string &_name)
Set the vertex name.
Definition: Vertex.hh:102
VertexId Id() const
Get the vertex Id.
Definition: Vertex.hh:88
uint64_t VertexId
The unique Id of each vertex.
Definition: Vertex.hh:41
friend std::ostream & operator<<(std::ostream &_out, const Vertex< V > &_v)
Stream insertion operator. The output uses DOT graph description language.
Definition: Vertex.hh:119
Definition: Angle.hh:42
STL class.
const V & Data() const
Retrieve the user information.
Definition: Vertex.hh:74