Ignition Math

API Reference

4.0.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: std::string Name() const
96  {
97  return this->name;
98  }
99 
102  public: bool Valid() const
103  {
104  return this->id != kNullId;
105  }
106 
112  public: friend std::ostream &operator<<(std::ostream &_out,
113  const Vertex<V> &_v)
114  {
115  _out << " " << _v.Id() << " [label=\"" << _v.Name()
116  << " (" << _v.Id() << ")\"];" << std::endl;
117  return _out;
118  }
119 
121  private: std::string name = "";
122 
124  private: V data;
125 
127  private: VertexId id = kNullId;
128  };
129 
131  template<typename V>
132  Vertex<V> Vertex<V>::NullVertex("__null__", V(), kNullId);
133 
137  template<typename V>
138  using VertexRef_M =
140 }
141 }
142 }
143 }
144 #endif
V & Data()
Get a mutable reference to the user information.
Definition: Vertex.hh:81
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:102
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:329
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
VertexId Id() const
Get the vertex Id.
Definition: Vertex.hh:88
friend std::ostream & operator<<(std::ostream &_out, const Vertex< V > &_v)
Stream insertion operator. The output uses DOT graph description language.
Definition: Vertex.hh:112
Definition: Angle.hh:39
uint64_t VertexId
Definition: Vertex.hh:41
STL class.
std::string Name() const
Get the vertex name.
Definition: Vertex.hh:95
const V & Data() const
Retrieve the user information.
Definition: Vertex.hh:74