RTC Toolkit 6.0.0
Loading...
Searching...
No Matches
dataPointPath.hpp
Go to the documentation of this file.
1
11
12#ifndef RTCTK_COMPONENTFRAMEWORK_DATAPOINTPATH_HPP
13#define RTCTK_COMPONENTFRAMEWORK_DATAPOINTPATH_HPP
14
17#include <rtctk/config.hpp>
18
19#include <fmt/format.h>
20#include <mal/utility/Uri.hpp>
21
22#include <algorithm>
23#include <iostream>
24#include <regex>
25#include <stdexcept>
26#include <string>
27#include <string_view>
28#include <type_traits>
29#include <utility>
30#include <vector>
31
33
77public:
83 public:
84 explicit InvalidPathException(const std::string& path);
85 };
86
87 DataPointPath() = default;
88 DataPointPath(const DataPointPath&) = default;
92
93 // This class cannot be inherited, therefore no need for a virtual destructor.
94 ~DataPointPath() = default;
95
102 explicit DataPointPath(const std::string& new_path);
103
110 explicit DataPointPath(std::string&& new_path);
111
118 explicit DataPointPath(const char* const new_path) : DataPointPath(std::string(new_path)) {
119 }
120
124 const std::string& ToString() const noexcept;
125
132 DataPointPath& operator=(const std::string& new_path);
133
140 DataPointPath& operator=(std::string&& new_path);
141
148 operator std::string() const noexcept;
149
150 // Append Operators
160 DataPointPath& operator+=(const DataPointPath& rhs);
161
173 DataPointPath& operator/=(const DataPointPath& rhs);
174
184 friend DataPointPath operator+(DataPointPath lhs, const DataPointPath& rhs);
185
197 friend DataPointPath operator/(DataPointPath lhs, const DataPointPath& rhs);
198
202 friend std::ostream& operator<<(std::ostream& out, const DataPointPath& rhs);
203
204 // Comparison operators for DataPointPath, char * and string
205 friend bool operator==(const DataPointPath& lhs, const char* rhs) noexcept;
206 friend bool operator!=(const DataPointPath& lhs, const char* rhs) noexcept {
207 return !(lhs == rhs);
208 }
209 friend bool operator<(const DataPointPath& lhs, const char* rhs) noexcept;
210 friend bool operator<=(const DataPointPath& lhs, const char* rhs) noexcept;
211 friend bool operator>(const DataPointPath& lhs, const char* rhs) noexcept;
212 friend bool operator>=(const DataPointPath& lhs, const char* rhs) noexcept;
213
214 friend bool operator==(const DataPointPath& lhs, const std::string& rhs) noexcept;
215 friend bool operator!=(const DataPointPath& lhs, const std::string& rhs) noexcept {
216 return !(lhs == rhs);
217 }
218 friend bool operator<(const DataPointPath& lhs, const std::string& rhs) noexcept;
219 friend bool operator<=(const DataPointPath& lhs, const std::string& rhs) noexcept;
220 friend bool operator>(const DataPointPath& lhs, const std::string& rhs) noexcept;
221 friend bool operator>=(const DataPointPath& lhs, const std::string& rhs) noexcept;
222
223 friend bool operator==(const DataPointPath& lhs, const DataPointPath& rhs) noexcept;
224 friend bool operator!=(const DataPointPath& lhs, const DataPointPath& rhs) noexcept {
225 return !(lhs == rhs);
226 }
227 friend bool operator<(const DataPointPath& lhs, const DataPointPath& rhs) noexcept;
228 friend bool operator<=(const DataPointPath& lhs, const DataPointPath& rhs) noexcept;
229 friend bool operator>(const DataPointPath& lhs, const DataPointPath& rhs) noexcept;
230 friend bool operator>=(const DataPointPath& lhs, const DataPointPath& rhs) noexcept;
231
232 // symmetry
233 friend bool operator==(const char* lhs, const DataPointPath& rhs) noexcept {
234 return rhs == lhs;
235 }
236 friend bool operator!=(const char* lhs, const DataPointPath& rhs) noexcept {
237 return !(rhs == lhs);
238 }
239 friend bool operator<(const char* lhs, const DataPointPath& rhs) noexcept {
240 return rhs > lhs;
241 }
242 friend bool operator<=(const char* lhs, const DataPointPath& rhs) noexcept {
243 return rhs >= lhs;
244 }
245 friend bool operator>(const char* lhs, const DataPointPath& rhs) noexcept {
246 return rhs < lhs;
247 }
248 friend bool operator>=(const char* lhs, const DataPointPath& rhs) noexcept {
249 return rhs <= lhs;
250 }
251
252 friend bool operator==(const std::string& lhs, const DataPointPath& rhs) noexcept {
253 return rhs == lhs;
254 }
255 friend bool operator!=(const std::string& lhs, const DataPointPath& rhs) noexcept {
256 return !(rhs == lhs);
257 }
258 friend bool operator<(const std::string& lhs, const DataPointPath& rhs) noexcept {
259 return rhs > lhs;
260 }
261 friend bool operator<=(const std::string& lhs, const DataPointPath& rhs) noexcept {
262 return rhs >= lhs;
263 }
264 friend bool operator>(const std::string& lhs, const DataPointPath& rhs) noexcept {
265 return rhs < lhs;
266 }
267 friend bool operator>=(const std::string& lhs, const DataPointPath& rhs) noexcept {
268 return rhs <= lhs;
269 }
270
274 friend std::istream& operator>>(std::istream& input, DataPointPath& path);
286 elt::mal::Uri ToRepositoryURI(const elt::mal::Uri& base_uri) const;
287
297 std::pair<DataPointPath, DataPointPath> Split() const;
298
305 DataPointPath BasePath() const;
306
313 DataPointPath LastComponent() const;
314
320 bool IsAbsolutePath() const;
321
329 std::vector<DataPointPath> SplitAll() const;
330
344 static elt::mal::Uri AppendSuffixToUriPath(const std::string& suffix, const elt::mal::Uri& uri);
345
346private:
352 RTCTK_LOCAL static bool ValidPath(const std::string& path);
353
354 std::string m_path;
355
357 RTCTK_LOCAL const static std::string VALID_CHARACTERS;
358
360 RTCTK_LOCAL const static std::regex REGEX_VALID_CHARS;
361}; // class DataPointPath
362
363RTCTK_API DataPointPath operator"" _dppath(const char* str, std::size_t len);
364
365// inline implementations
366
367inline bool operator==(const DataPointPath& lhs, const char* rhs) noexcept {
368 return lhs.m_path == rhs;
369}
370
371inline bool operator<(const DataPointPath& lhs, const char* rhs) noexcept {
372 return lhs.m_path < rhs;
373}
374
375inline bool operator<=(const DataPointPath& lhs, const char* rhs) noexcept {
376 return lhs.m_path <= rhs;
377}
378
379inline bool operator>(const DataPointPath& lhs, const char* rhs) noexcept {
380 return lhs.m_path > rhs;
381}
382
383inline bool operator>=(const DataPointPath& lhs, const char* rhs) noexcept {
384 return lhs.m_path >= rhs;
385}
386
387inline bool operator==(const DataPointPath& lhs, const std::string& rhs) noexcept {
388 return lhs.m_path == rhs;
389}
390
391inline bool operator<(const DataPointPath& lhs, const std::string& rhs) noexcept {
392 return lhs.m_path < rhs;
393}
394
395inline bool operator<=(const DataPointPath& lhs, const std::string& rhs) noexcept {
396 return lhs.m_path <= rhs;
397}
398
399inline bool operator>(const DataPointPath& lhs, const std::string& rhs) noexcept {
400 return lhs.m_path > rhs;
401}
402
403inline bool operator>=(const DataPointPath& lhs, const std::string& rhs) noexcept {
404 return lhs.m_path >= rhs;
405}
406
407inline bool operator==(const DataPointPath& lhs, const DataPointPath& rhs) noexcept {
408 return lhs.m_path == rhs.m_path;
409}
410
411inline bool operator<(const DataPointPath& lhs, const DataPointPath& rhs) noexcept {
412 return lhs.m_path < rhs.m_path;
413}
414
415inline bool operator<=(const DataPointPath& lhs, const DataPointPath& rhs) noexcept {
416 return lhs.m_path <= rhs.m_path;
417}
418
419inline bool operator>(const DataPointPath& lhs, const DataPointPath& rhs) noexcept {
420 return lhs.m_path > rhs.m_path;
421}
422
423inline bool operator>=(const DataPointPath& lhs, const DataPointPath& rhs) noexcept {
424 return lhs.m_path >= rhs.m_path;
425}
426
428 lhs += rhs;
429 return lhs;
430}
431
433 lhs /= rhs;
434 return lhs;
435}
436
437inline const std::string& DataPointPath::ToString() const noexcept {
438 return this->m_path;
439}
440
441inline DataPointPath operator"" _dppath(const char* str, std::size_t len) {
442 return DataPointPath(std::string(str));
443}
444
445inline DataPointPath::operator std::string() const noexcept {
446 return m_path;
447}
448
449inline std::ostream& operator<<(std::ostream& out, const DataPointPath& rhs) {
450 out << rhs.m_path;
451 return out;
452}
453
454// The naming convention for the following two helper functions is defined by the nlohmann/json.hpp
455// header library.
456// NOLINTNEXTLINE(readability-identifier-naming)
457RTCTK_API void to_json(JsonPayload& j, const DataPointPath& v);
458
459// NOLINTNEXTLINE(readability-identifier-naming)
461
462} // namespace rtctk::componentFramework
463
464namespace fmt {
465
469template <>
470struct RTCTK_API formatter<rtctk::componentFramework::DataPointPath> : formatter<std::string> {
471 auto format(const rtctk::componentFramework::DataPointPath& path, format_context& ctx) const
472 -> format_context::iterator;
473};
474
475} // namespace fmt
476
477#endif // RTCTK_COMPONENTFRAMEWORK_DATAPOINTPATH_HPP
InvalidPathException(const std::string &path)
Definition dataPointPath.cpp:19
This class provides a wrapper for a data point path.
Definition dataPointPath.hpp:76
friend bool operator!=(const DataPointPath &lhs, const DataPointPath &rhs) noexcept
Definition dataPointPath.hpp:224
friend bool operator<=(const std::string &lhs, const DataPointPath &rhs) noexcept
Definition dataPointPath.hpp:261
friend bool operator>=(const char *lhs, const DataPointPath &rhs) noexcept
Definition dataPointPath.hpp:248
friend bool operator>(const char *lhs, const DataPointPath &rhs) noexcept
Definition dataPointPath.hpp:245
friend bool operator<(const char *lhs, const DataPointPath &rhs) noexcept
Definition dataPointPath.hpp:239
friend bool operator!=(const std::string &lhs, const DataPointPath &rhs) noexcept
Definition dataPointPath.hpp:255
friend bool operator>=(const std::string &lhs, const DataPointPath &rhs) noexcept
Definition dataPointPath.hpp:267
friend bool operator!=(const char *lhs, const DataPointPath &rhs) noexcept
Definition dataPointPath.hpp:236
friend bool operator!=(const DataPointPath &lhs, const std::string &rhs) noexcept
Definition dataPointPath.hpp:215
friend bool operator<=(const char *lhs, const DataPointPath &rhs) noexcept
Definition dataPointPath.hpp:242
friend bool operator<(const std::string &lhs, const DataPointPath &rhs) noexcept
Definition dataPointPath.hpp:258
const std::string & ToString() const noexcept
Get string representing the DataPointPath.
Definition dataPointPath.hpp:437
friend bool operator>(const std::string &lhs, const DataPointPath &rhs) noexcept
Definition dataPointPath.hpp:264
operator std::string() const noexcept
Cast operator to string (implicit).
Definition dataPointPath.hpp:445
DataPointPath(const char *const new_path)
Create DataPointPath from a null terminated character string.
Definition dataPointPath.hpp:118
DataPointPath & operator=(DataPointPath &&)=default
DataPointPath & operator=(const DataPointPath &)=default
DataPointPath(DataPointPath &&)=default
friend bool operator==(const std::string &lhs, const DataPointPath &rhs) noexcept
Definition dataPointPath.hpp:252
friend bool operator==(const char *lhs, const DataPointPath &rhs) noexcept
Definition dataPointPath.hpp:233
DataPointPath(const DataPointPath &)=default
RtctkException() noexcept
Definition exceptions.cpp:112
Project-wide configuration header.
#define RTCTK_LOCAL
Helper to hide a class or function from the public symbol table.
Definition config.hpp:59
#define RTCTK_API
Helper to indicate that a class or function must be exported in the public symbol table.
Definition config.hpp:32
Provides macros and utilities for exception handling.
Defines the JSON payload type JsonPayload.
Definition dataPointPath.hpp:464
Definition commandReplier.cpp:21
DataPointPath operator/(DataPointPath lhs, const DataPointPath &rhs)
Definition dataPointPath.hpp:432
bool operator<=(const DataPointPath &lhs, const char *rhs) noexcept
Definition dataPointPath.hpp:375
bool operator>(const DataPointPath &lhs, const char *rhs) noexcept
Definition dataPointPath.hpp:379
bool operator==(const DataPointPath &lhs, const char *rhs) noexcept
Definition dataPointPath.hpp:367
void to_json(JsonPayload &j, const DataPointPath &v)
Definition dataPointPath.cpp:217
std::istream & operator>>(std::istream &input, DataPointPath &path)
Definition dataPointPath.cpp:203
bool operator>=(const DataPointPath &lhs, const char *rhs) noexcept
Definition dataPointPath.hpp:383
nlohmann::json JsonPayload
Type requirements:
Definition jsonPayload.hpp:24
std::ostream & operator<<(std::ostream &out, const DataPointPath &rhs)
Definition dataPointPath.hpp:449
void from_json(const JsonPayload &j, DataPointPath &v)
Definition dataPointPath.cpp:222
bool operator<(const DataPointPath &lhs, const char *rhs) noexcept
Definition dataPointPath.hpp:371
DataPointPath operator+(DataPointPath lhs, const DataPointPath &rhs)
Definition dataPointPath.hpp:427
Definition commandReplier.cpp:21
Definition ddsSub.hpp:155
auto format(const rtctk::componentFramework::DataPointPath &path, format_context &ctx) const -> format_context::iterator
Definition dataPointPath.cpp:228