Gazebo Math

API Reference

7.4.0
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 <map>
24#include <ostream>
25#include <string>
26#include <utility>
27
28#include <gz/math/config.hh>
29#include <gz/math/Helpers.hh>
30
31namespace gz
32{
33namespace math
34{
35// Inline bracket to help doxygen filtering.
36inline namespace GZ_MATH_VERSION_NAMESPACE {
37namespace 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 // cppcheck-suppress noExplicitConstructor
64 public: Vertex(const std::string &_name,
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
120 public: friend std::ostream &operator<<(std::ostream &_out,
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 template<typename V>
140 Vertex<V> Vertex<V>::NullVertex("__null__", V(), kNullId);
141
145 template<typename V>
148}
149}
150}
151}
152#endif