Goby3 3.4.0
2026.04.13
Loading...
Searching...
No Matches
identifier.h
Go to the documentation of this file.
1// Copyright 2026:
2// GobySoft, LLC (2013-)
3// Community contributors (see AUTHORS file)
4// File authors:
5// Toby Schneider <toby@gobysoft.org>
6//
7//
8// This file is part of the Goby Underwater Autonomy Project Libraries
9// ("The Goby Libraries").
10//
11// The Goby Libraries are free software: you can redistribute them and/or modify
12// them under the terms of the GNU Lesser General Public License as published by
13// the Free Software Foundation, either version 2.1 of the License, or
14// (at your option) any later version.
15//
16// The Goby Libraries are distributed in the hope that they will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU Lesser General Public License for more details.
20//
21// You should have received a copy of the GNU Lesser General Public License
22// along with Goby. If not, see <http://www.gnu.org/licenses/>.
23
24#ifndef GOBY_MIDDLEWARE_TRANSPORT_IDENTIFIER_H
25#define GOBY_MIDDLEWARE_TRANSPORT_IDENTIFIER_H
26
27#include <algorithm>
28#include <string>
29#include <thread>
30#include <unistd.h> // for getpid
31#include <unordered_map>
32#include <vector>
33
35#include "goby/middleware/marshalling/interface.h" // for Seri...
37
38namespace goby
39{
40namespace middleware
41{
42
44{
45 NO_WILDCARDS, // fully qualified
46 THREAD_WILDCARD, // omit thread
47 PROCESS_THREAD_WILDCARD // omit process and thread
48};
49
51{
52 std::string group;
53 int scheme;
54 std::string type_name;
56 std::size_t thread_id;
57};
58
59// scheme
60inline std::string identifier_part_to_string(int i)
61{
63}
64inline std::string identifier_part_to_string(std::thread::id i)
65{
67}
68
70{
71 public:
72 const static char delimiter;
73 const static char delimiter_substitute;
74 const static char end_delimiter;
75
76 static std::string
77 make_identifier(const std::string& type_name, int scheme, const std::string& group,
78 IdentifierWildcard wildcard, const std::string& process,
79 std::unordered_map<int, std::string>* schemes_buffer = nullptr,
80 std::unordered_map<std::thread::id, std::string>* threads_buffer = nullptr);
81
82 // group, scheme, type, process, thread
83 std::tuple<std::string, int, std::string, int, std::size_t> static parse_identifier(
84 const std::string& identifier);
85
86 protected:
87 template <typename Data, int scheme>
93
94 template <typename Data, int scheme>
101
102 std::string _make_identifier(const std::string& type_name, int scheme, const std::string& group,
103 IdentifierWildcard wildcard)
104 {
105 return make_identifier(type_name, scheme, group, wildcard, process_, &schemes_, &threads_);
106 }
107
108 private:
110 template <typename Key>
111 static const std::string& id_component(const Key& k, std::unordered_map<Key, std::string>& map)
112 {
113 auto it = map.find(k);
114 if (it != map.end())
115 return it->second;
116
117 std::string v = identifier_part_to_string(k) + delimiter_str_;
118 auto it_pair = map.insert(std::make_pair(k, v));
119 return it_pair.first->second;
120 }
121
122 private:
123 static const std::string delimiter_str_;
124 const std::string process_{std::to_string(getpid())};
125 std::unordered_map<int, std::string> schemes_;
126 std::unordered_map<std::thread::id, std::string> threads_;
127};
128
129} // namespace middleware
130} // namespace goby
131
132#endif
Class for grouping publications in the Goby middleware. Analogous to "topics" in ROS,...
Definition group.h:60
static std::string make_identifier(const std::string &type_name, int scheme, const std::string &group, IdentifierWildcard wildcard, const std::string &process, std::unordered_map< int, std::string > *schemes_buffer=nullptr, std::unordered_map< std::thread::id, std::string > *threads_buffer=nullptr)
std::string _make_identifier(const goby::middleware::Group &group, IdentifierWildcard wildcard)
Definition identifier.h:88
static std::tuple< std::string, int, std::string, int, std::size_t > parse_identifier(const std::string &identifier)
std::string _make_identifier(const Data &d, const goby::middleware::Group &group, IdentifierWildcard wildcard)
Definition identifier.h:95
std::string _make_identifier(const std::string &type_name, int scheme, const std::string &group, IdentifierWildcard wildcard)
Definition identifier.h:102
goby::util::logger::GroupSetter group(std::string n)
constexpr int scheme()
Placeholder to provide an interface for the scheme() function family.
Definition cstr.h:65
std::string thread_id(std::thread::id i=std::this_thread::get_id())
Definition common.h:53
std::string identifier_part_to_string(int i)
Definition identifier.h:60
The global namespace for the Goby project.
static std::string to_string(int e)
Convert a known marshalling scheme to a human-readable string or an unknown scheme to the string repr...
Definition interface.h:67
Class for parsing and serializing a given marshalling scheme. Must be specialized for a particular sc...
Definition interface.h:98