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