Gazebo Math
API Reference
9.0.0~pre1
insert_drive_file
Tutorials
library_books
Classes
toc
Namespaces
insert_drive_file
Files
launch
Gazebo Website
Index
List
Hierarchy
Members: All
Members: Functions
Members: Variables
Members: Typedefs
Members: Enumerations
Members: Enumerator
List
Members
Functions
Typedefs
Variables
Enumerations
Enumerator
src
gz-math
include
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
#include <gz/utils/NeverDestroyed.hh>
31
32
namespace
gz::math
33
{
34
// Inline bracket to help doxygen filtering.
35
inline
namespace
GZ_MATH_VERSION_NAMESPACE {
36
namespace
graph
37
{
40
using
VertexId
= uint64_t;
41
44
using
VertexId_P
=
std::pair<VertexId, VertexId>
;
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
116
public
:
friend
std::ostream
&
operator<<
(
std::ostream
&
_out
,
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>
136
Vertex<V>
&
NullVertex
()
137
{
138
static
gz::utils::NeverDestroyed<Vertex<V>>
v
(
"__null__"
,
V
(),
kNullId
);
139
return
v
.Access();
140
}
141
145
template
<
typename
V>
146
using
VertexRef_M
=
147
std::map<VertexId, std::reference_wrapper<const Vertex<V>
>>;
148
}
// namespace graph
149
}
// namespace GZ_MATH_VERSION_NAMESPACE
150
}
// namespace gz::math
151
#endif
// GZ_MATH_GRAPH_VERTEX_HH_