Gazebo Math

API Reference

8.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 GZ_MATH_GRAPH_VERTEX_HH_
18#define GZ_MATH_GRAPH_VERTEX_HH_
19
20// uint64_t
21#include <cstdint>
22#include <functional>
23#include <map>
24#include <ostream>
25#include <string>
26#include <utility>
27
28#include <gz/math/config.hh>
29#include <gz/math/Helpers.hh>
30#include <gz/utils/NeverDestroyed.hh>
31
32namespace gz::math
33{
34// Inline bracket to help doxygen filtering.
35inline namespace GZ_MATH_VERSION_NAMESPACE {
36namespace graph
37{
40 using VertexId = uint64_t;
41
45
47 constexpr VertexId kNullId = MAX_UI64;
48
52 template<typename V>
53 class Vertex
54 {
56 // Deprecated in favor of NullVertex().
57 public: static Vertex<V> GZ_DEPRECATED(8) NullVertex;
58
63 // cppcheck-suppress noExplicitConstructor
65 const V &_data = V(),
66 const VertexId _id = kNullId)
67 : name(_name),
68 data(_data),
69 id(_id)
70 {
71 }
72
75 public: const V &Data() const
76 {
77 return this->data;
78 }
79
82 public: V &Data()
83 {
84 return this->data;
85 }
86
89 public: VertexId Id() const
90 {
91 return this->id;
92 }
93
96 public: const std::string &Name() const
97 {
98 return this->name;
99 }
100
103 public: void SetName(const std::string &_name)
104 {
105 this->name = _name;
106 }
107
110 public: bool Valid() const
111 {
112 return this->id != kNullId;
113 }
114
121 const Vertex<V> &_v)
122 {
123 _out << " " << _v.Id() << " [label=\"" << _v.Name()
124 << " (" << _v.Id() << ")\"];" << std::endl;
125 return _out;
126 }
127
129 private: std::string name = "";
130
132 private: V data;
133
135 private: VertexId id = kNullId;
136 };
137
139 // Deprecated in favor of NullVertex().
140 template<typename V>
141 Vertex<V> Vertex<V>::NullVertex("__null__", V(), kNullId);
142
144 template<typename V>
146 {
147 static gz::utils::NeverDestroyed<Vertex<V>> v("__null__", V(), kNullId);
148 return v.Access();
149 }
150
154 template<typename V>
157} // namespace graph
158} // namespace GZ_MATH_VERSION_NAMESPACE
159} // namespace gz::math
160#endif // GZ_MATH_GRAPH_VERTEX_HH_