Gazebo Math

API Reference

9.0.0~pre1
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 {
59 // cppcheck-suppress noExplicitConstructor
60 public: Vertex(const std::string &_name,
61 const V &_data = V(),
62 const VertexId _id = kNullId)
63 : name(_name),
64 data(_data),
65 id(_id)
66 {
67 }
68
71 public: const V &Data() const
72 {
73 return this->data;
74 }
75
78 public: V &Data()
79 {
80 return this->data;
81 }
82
85 public: VertexId Id() const
86 {
87 return this->id;
88 }
89
92 public: const std::string &Name() const
93 {
94 return this->name;
95 }
96
99 public: void SetName(const std::string &_name)
100 {
101 this->name = _name;
102 }
103
106 public: bool Valid() const
107 {
108 return this->id != kNullId;
109 }
110
117 const Vertex<V> &_v)
118 {
119 _out << " " << _v.Id() << " [label=\"" << _v.Name()
120 << " (" << _v.Id() << ")\"];" << std::endl;
121 return _out;
122 }
123
125 private: std::string name = "";
126
128 private: V data;
129
131 private: VertexId id = kNullId;
132 };
133
135 template<typename V>
137 {
138 static gz::utils::NeverDestroyed<Vertex<V>> v("__null__", V(), kNullId);
139 return v.Access();
140 }
141
145 template<typename V>
148} // namespace graph
149} // namespace GZ_MATH_VERSION_NAMESPACE
150} // namespace gz::math
151#endif // GZ_MATH_GRAPH_VERTEX_HH_