Gazebo Math

API Reference

6.15.1
gz/math/graph/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 GZ_MATH_GRAPH_VERTEX_HH_
18 #define GZ_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 <gz/math/config.hh>
29 #include <gz/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
VertexId Id() const
Get the vertex Id.
Definition: gz/math/graph/Vertex.hh:88
static const uint64_t MAX_UI64
64bit unsigned integer maximum value
Definition: gz/math/Helpers.hh:339
Definition: gz/math/AdditivelySeparableScalarField3.hh:27
STL class.
A vertex of a graph. It stores user information, an optional name, and keeps an internal unique Id....
Definition: gz/math/graph/Vertex.hh:54
V & Data()
Get a mutable reference to the user information.
Definition: gz/math/graph/Vertex.hh:81
const std::string & Name() const
Get the vertex name.
Definition: gz/math/graph/Vertex.hh:95
static Vertex< V > NullVertex
An invalid vertex.
Definition: gz/math/graph/Vertex.hh:57
const V & Data() const
Retrieve the user information.
Definition: gz/math/graph/Vertex.hh:74
std::map< VertexId, std::reference_wrapper< const Vertex< V > >> VertexRef_M
Definition: gz/math/graph/Vertex.hh:146
Vertex(const std::string &_name, const V &_data=V(), const VertexId _id=kNullId)
Constructor.
Definition: gz/math/graph/Vertex.hh:63
static const VertexId kNullId
Represents an invalid Id.
Definition: gz/math/graph/Vertex.hh:48
bool Valid() const
Whether the vertex is considered valid or not (id==kNullId).
Definition: gz/math/graph/Vertex.hh:109
STL class.
STL class.
T endl(T... args)
friend std::ostream & operator<<(std::ostream &_out, const Vertex< V > &_v)
Stream insertion operator. The output uses DOT graph description language.
Definition: gz/math/graph/Vertex.hh:119
void SetName(const std::string &_name)
Set the vertex name.
Definition: gz/math/graph/Vertex.hh:102
uint64_t VertexId
The unique Id of each vertex.
Definition: gz/math/graph/Vertex.hh:41