Gazebo Transport

API Reference

15.0.0~pre1
TopicUtils.hh
Go to the documentation of this file.
1/*
2 * Copyright (C) 2014 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
18#ifndef GZ_TRANSPORT_TOPICUTILS_HH_
19#define GZ_TRANSPORT_TOPICUTILS_HH_
20
21#include <cstdint>
22#include <string>
23#include <optional>
24#include <vector>
25
26#include "gz/transport/config.hh"
27#include "gz/transport/Export.hh"
28
29namespace gz::transport
30{
31 // Inline bracket to help doxygen filtering.
32 inline namespace GZ_TRANSPORT_VERSION_NAMESPACE {
33 //
36 class GZ_TRANSPORT_VISIBLE TopicUtils
37 {
44 public: static bool IsValidNamespace(const std::string &_ns);
45
53 public: static bool IsValidPartition(const std::string &_partition);
54
64 public: static bool IsValidTopic(const std::string &_topic);
65
102 public: static bool FullyQualifiedName(const std::string &_partition,
103 const std::string &_ns,
104 const std::string &_topic,
105 std::string &_name);
106
127 public: static bool DecomposeFullyQualifiedTopic(
128 const std::string &_fullyQualifiedName,
129 std::string &_partition,
130 std::string &_namespaceAndTopic);
131
164 const std::string &_token,
165 std::string &_prefix,
166 std::string &_partition,
167 std::string &_namespaceAndTopic,
168 std::string &_pUUID,
169 std::string &_nUUID,
170 std::string &_entityType,
171 std::string &_remainingToken);
172
207 public: static bool DecomposeLivelinessToken(
208 const std::string &_token,
209 std::string &_prefix,
210 std::string &_partition,
211 std::string &_namespaceAndTopic,
212 std::string &_pUUID,
213 std::string &_nUUID,
214 std::string &_entityType,
215 std::string &_typeName);
216
252 public: static bool DecomposeLivelinessToken(
253 const std::string &_token,
254 std::string &_prefix,
255 std::string &_partition,
256 std::string &_namespaceAndTopic,
257 std::string &_pUUID,
258 std::string &_nUUID,
259 std::string &_entityType,
260 std::string &_reqType,
261 std::string &_repType);
262
277 const std::string &_fullyQualifiedTopic,
278 const std::string &_pUuid,
279 const std::string &_nUuid,
280 const std::string &_entityType);
281
297 const std::string &_fullyQualifiedTopic,
298 const std::string &_pUuid,
299 const std::string &_nUuid,
300 const std::string &_entityType,
301 const std::string &_typeName);
302
319 const std::string &_fullyQualifiedTopic,
320 const std::string &_pUuid,
321 const std::string &_nUuid,
322 const std::string &_entityType,
323 const std::string &_reqTypeName,
324 const std::string &_repTypeName);
325
332 public: static std::string AsValidTopic(const std::string &_topic);
333
337 public: static std::string MangleName(const std::string &_input);
338
342 public: static std::string DemangleName(const std::string &_input);
343
348 public: static bool MangleType(const std::vector<std::string> &_input,
349 std::string &_output);
350
355 public: static bool DemangleType(const std::string &_input,
356 std::vector<std::string> &_output);
357
361 public: static const uint16_t kMaxNameLength = 65535;
362
364 public: static const char kTokenSeparator[];
365
367 public: static const char kTypeSeparator[];
368
370 public: static const char kTokenPrefix[];
371
373 public: static const char kSlashReplacement;
374 };
375
376
379 {
385 public: FullyQualifiedTopic(const std::string &_partition,
386 const std::string &_ns,
387 const std::string &_topic)
388 : partition(_partition), ns(_ns), topic(_topic)
389 {
390 this->fullTopic.emplace();
391 if (!TopicUtils::FullyQualifiedName(_partition, _ns, _topic,
392 *this->fullTopic))
393 {
394 this->fullTopic.reset();
395 }
396 }
399 const std::string &Partition() const
400 {
401 return this->partition;
402 }
405 const std::string &Namespace() const
406 {
407 return this->ns;
408 }
411 const std::string &Topic() const
412 {
413 return this->topic;
414 }
417 std::optional<std::string> FullTopic() const
418 {
419 return this->fullTopic;
420 }
421
423 private: const std::string partition;
424
426 private: const std::string ns;
427
429 private: const std::string topic;
430
433 private: std::optional<std::string> fullTopic;
434 };
435 }
436}
437
438#endif