Loading...
Searching...
No Matches
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 IGNITION_MATH_GRAPH_VERTEX_HH_
18#define IGNITION_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 <ignition/math/config.hh>
30
31namespace ignition
32{
33namespace math
34{
35inline namespace IGNITION_MATH_VERSION_NAMESPACE
36{
37namespace graph
38{
41 using VertexId = uint64_t;
42
45 using VertexId_P = std::pair<VertexId, VertexId>;
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: std::string Name() const
96 {
97 return this->name;
98 }
99
102 public: bool Valid() const
103 {
104 return this->id != kNullId;
105 }
106
112 public: friend std::ostream &operator<<(std::ostream &_out,
113 const Vertex<V> &_v)
114 {
115 _out << " " << _v.Id() << " [label=\"" << _v.Name()
116 << " (" << _v.Id() << ")\"];" << std::endl;
117 return _out;
118 }
119
121 private: std::string name = "";
122
124 private: V data;
125
127 private: VertexId id = kNullId;
128 };
129
131 template<typename V>
132 Vertex<V> Vertex<V>::NullVertex("__null__", V(), kNullId);
133
137 template<typename V>
139 std::map<VertexId, std::reference_wrapper<const Vertex<V>>>;
140}
141}
142}
143}
144#endif
A vertex of a graph.
Definition Vertex.hh:55
friend std::ostream & operator<<(std::ostream &_out, const Vertex< V > &_v)
Stream insertion operator.
Definition Vertex.hh:112
std::string Name() const
Get the vertex name.
Definition Vertex.hh:95
V & Data()
Get a mutable reference to the user information.
Definition Vertex.hh:81
static Vertex< V > NullVertex
An invalid vertex.
Definition Vertex.hh:57
Vertex(const std::string &_name, const V &_data=V(), const VertexId _id=kNullId)
Constructor.
Definition Vertex.hh:63
const V & Data() const
Retrieve the user information.
Definition Vertex.hh:74
bool Valid() const
Whether the vertex is considered valid or not (id==kNullId).
Definition Vertex.hh:102
VertexId Id() const
Get the vertex Id.
Definition Vertex.hh:88
std::pair< VertexId, VertexId > VertexId_P
Definition Vertex.hh:45
static const VertexId kNullId
Represents an invalid Id.
Definition Vertex.hh:48
std::map< VertexId, std::reference_wrapper< const Vertex< V > > > VertexRef_M
Definition Vertex.hh:138
static const uint64_t MAX_UI64
64bit unsigned integer maximum value
Definition Helpers.hh:328
Definition Angle.hh:40