RTC Toolkit 5.0.0
Loading...
Searching...
No Matches
dataPointPath.hpp
Go to the documentation of this file.
1
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
75public:
81 public:
82 explicit InvalidPathException(const std::string& path);
83 };
84
85 DataPointPath() = default;
86 DataPointPath(const DataPointPath&) = default;
90
91 // This class cannot be inherited, therefore no need for a virtual destructor.
92 ~DataPointPath() = default;
93
100 explicit DataPointPath(const std::string& new_path);
101
108 explicit DataPointPath(std::string&& new_path);
109
116 explicit DataPointPath(const char* const new_path) : DataPointPath(std::string(new_path)) {
117 }
118
122 const std::string& ToString() const noexcept;
123
130 DataPointPath& operator=(const std::string& new_path);
131
138 DataPointPath& operator=(std::string&& new_path);
139
146 operator std::string() const noexcept;
147
148 // Append Operators
158 DataPointPath& operator+=(const DataPointPath& rhs);
159
171 DataPointPath& operator/=(const DataPointPath& rhs);
172
182 friend DataPointPath operator+(DataPointPath lhs, const DataPointPath& rhs);
183
195 friend DataPointPath operator/(DataPointPath lhs, const DataPointPath& rhs);
196
200 friend std::ostream& operator<<(std::ostream& out, const DataPointPath& rhs);
201
202 // Comparison operators for DataPointPath, char * and string
203 friend bool operator==(const DataPointPath& lhs, const char* rhs) noexcept;
204 friend bool operator!=(const DataPointPath& lhs, const char* rhs) noexcept {
205 return !(lhs == rhs);
206 }
207 friend bool operator<(const DataPointPath& lhs, const char* rhs) noexcept;
208 friend bool operator<=(const DataPointPath& lhs, const char* rhs) noexcept;
209 friend bool operator>(const DataPointPath& lhs, const char* rhs) noexcept;
210 friend bool operator>=(const DataPointPath& lhs, const char* rhs) noexcept;
211
212 friend bool operator==(const DataPointPath& lhs, const std::string& rhs) noexcept;
213 friend bool operator!=(const DataPointPath& lhs, const std::string& rhs) noexcept {
214 return !(lhs == rhs);
215 }
216 friend bool operator<(const DataPointPath& lhs, const std::string& rhs) noexcept;
217 friend bool operator<=(const DataPointPath& lhs, const std::string& rhs) noexcept;
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
221 friend bool operator==(const DataPointPath& lhs, const DataPointPath& rhs) noexcept;
222 friend bool operator!=(const DataPointPath& lhs, const DataPointPath& rhs) noexcept {
223 return !(lhs == rhs);
224 }
225 friend bool operator<(const DataPointPath& lhs, const DataPointPath& rhs) noexcept;
226 friend bool operator<=(const DataPointPath& lhs, const DataPointPath& rhs) noexcept;
227 friend bool operator>(const DataPointPath& lhs, const DataPointPath& rhs) noexcept;
228 friend bool operator>=(const DataPointPath& lhs, const DataPointPath& rhs) noexcept;
229
230 // symmetry
231 friend bool operator==(const char* lhs, const DataPointPath& rhs) noexcept {
232 return rhs == lhs;
233 }
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
250 friend bool operator==(const std::string& lhs, const DataPointPath& rhs) noexcept {
251 return rhs == lhs;
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
272 friend std::istream& operator>>(std::istream& input, DataPointPath& path);
284 elt::mal::Uri ToRepositoryURI(const elt::mal::Uri& base_uri) const;
285
295 std::pair<DataPointPath, DataPointPath> Split() const;
296
303 DataPointPath BasePath() const;
304
311 DataPointPath LastComponent() const;
312
320 std::vector<DataPointPath> SplitAll() const;
321
335 static elt::mal::Uri AppendSuffixToUriPath(const std::string& suffix, const elt::mal::Uri& uri);
336
337private:
343 RTCTK_LOCAL static bool ValidPath(const std::string& path);
344
345 std::string m_path;
346
348 RTCTK_LOCAL const static char VALID_CHARACTERS[];
349
351 RTCTK_LOCAL const static std::regex REGEX_VALID_CHARS;
352}; // class DataPointPath
353
354RTCTK_API DataPointPath operator"" _dppath(const char* str, std::size_t len);
355
356// inline implementations
357
358inline bool operator==(const DataPointPath& lhs, const char* rhs) noexcept {
359 return lhs.m_path == rhs;
360}
361
362inline bool operator<(const DataPointPath& lhs, const char* rhs) noexcept {
363 return lhs.m_path < rhs;
364}
365
366inline bool operator<=(const DataPointPath& lhs, const char* rhs) noexcept {
367 return lhs.m_path <= rhs;
368}
369
370inline bool operator>(const DataPointPath& lhs, const char* rhs) noexcept {
371 return lhs.m_path > rhs;
372}
373
374inline bool operator>=(const DataPointPath& lhs, const char* rhs) noexcept {
375 return lhs.m_path >= rhs;
376}
377
378inline bool operator==(const DataPointPath& lhs, const std::string& rhs) noexcept {
379 return lhs.m_path == rhs;
380}
381
382inline bool operator<(const DataPointPath& lhs, const std::string& rhs) noexcept {
383 return lhs.m_path < rhs;
384}
385
386inline bool operator<=(const DataPointPath& lhs, const std::string& rhs) noexcept {
387 return lhs.m_path <= rhs;
388}
389
390inline bool operator>(const DataPointPath& lhs, const std::string& rhs) noexcept {
391 return lhs.m_path > rhs;
392}
393
394inline bool operator>=(const DataPointPath& lhs, const std::string& rhs) noexcept {
395 return lhs.m_path >= rhs;
396}
397
398inline bool operator==(const DataPointPath& lhs, const DataPointPath& rhs) noexcept {
399 return lhs.m_path == rhs.m_path;
400}
401
402inline bool operator<(const DataPointPath& lhs, const DataPointPath& rhs) noexcept {
403 return lhs.m_path < rhs.m_path;
404}
405
406inline bool operator<=(const DataPointPath& lhs, const DataPointPath& rhs) noexcept {
407 return lhs.m_path <= rhs.m_path;
408}
409
410inline bool operator>(const DataPointPath& lhs, const DataPointPath& rhs) noexcept {
411 return lhs.m_path > rhs.m_path;
412}
413
414inline bool operator>=(const DataPointPath& lhs, const DataPointPath& rhs) noexcept {
415 return lhs.m_path >= rhs.m_path;
416}
417
419 lhs += rhs;
420 return lhs;
421}
422
424 lhs /= rhs;
425 return lhs;
426}
427
428inline const std::string& DataPointPath::ToString() const noexcept {
429 return this->m_path;
430}
431
432inline DataPointPath operator"" _dppath(const char* str, std::size_t len) {
433 return DataPointPath(std::string(str));
434}
435
436inline DataPointPath::operator std::string() const noexcept {
437 return m_path;
438}
439
440inline std::ostream& operator<<(std::ostream& out, const DataPointPath& rhs) {
441 out << rhs.m_path;
442 return out;
443}
444
445// The naming convention for the following two helper functions is defined by the nlohmann/json.hpp
446// header library.
447// NOLINTNEXTLINE(readability-identifier-naming)
448RTCTK_API void to_json(JsonPayload& j, const std::vector<DataPointPath>& v);
449
450// NOLINTNEXTLINE(readability-identifier-naming)
451RTCTK_API void from_json(const JsonPayload& j, std::vector<DataPointPath>& v);
452
453} // namespace rtctk::componentFramework
454
458template <>
459struct RTCTK_API fmt::formatter<rtctk::componentFramework::DataPointPath>
460 : fmt::formatter<std::string> {
462 fmt::format_context& ctx) -> fmt::format_context::iterator;
463};
464
465#endif // RTCTK_COMPONENTFRAMEWORK_DATAPOINTPATH_HPP
Exception class used when an invalid character is used in a DataPointPath.
Definition dataPointPath.hpp:80
This class provides a wrapper for a data point path.
Definition dataPointPath.hpp:74
friend bool operator!=(const DataPointPath &lhs, const DataPointPath &rhs) noexcept
Definition dataPointPath.hpp:222
friend bool operator<=(const std::string &lhs, const DataPointPath &rhs) noexcept
Definition dataPointPath.hpp:259
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:243
friend bool operator<(const char *lhs, const DataPointPath &rhs) noexcept
Definition dataPointPath.hpp:237
friend bool operator!=(const std::string &lhs, const DataPointPath &rhs) noexcept
Definition dataPointPath.hpp:253
friend bool operator>=(const std::string &lhs, const DataPointPath &rhs) noexcept
Definition dataPointPath.hpp:265
friend bool operator!=(const char *lhs, const DataPointPath &rhs) noexcept
Definition dataPointPath.hpp:234
friend bool operator!=(const DataPointPath &lhs, const std::string &rhs) noexcept
Definition dataPointPath.hpp:213
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
const std::string & ToString() const noexcept
Get string representing the DataPointPath.
Definition dataPointPath.hpp:428
friend bool operator>(const std::string &lhs, const DataPointPath &rhs) noexcept
Definition dataPointPath.hpp:262
DataPointPath(const char *const new_path)
Create DataPointPath from a null terminated character string.
Definition dataPointPath.hpp:116
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:250
friend bool operator==(const char *lhs, const DataPointPath &rhs) noexcept
Definition dataPointPath.hpp:231
DataPointPath(const DataPointPath &)=default
The RtctkException class is the base class for all Rtctk exceptions.
Definition exceptions.hpp:211
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 ddsSub.hpp:151
Definition commandReplier.cpp:22
DataPointPath operator/(DataPointPath lhs, const DataPointPath &rhs)
Definition dataPointPath.hpp:423
void to_json(JsonPayload &j, const std::vector< DataPointPath > &v)
Definition dataPointPath.cpp:207
bool operator<(const DataPointPath &lhs, const char *rhs) noexcept
Definition dataPointPath.hpp:362
std::istream & operator>>(std::istream &input, DataPointPath &path)
Definition dataPointPath.cpp:193
bool operator>=(const DataPointPath &lhs, const char *rhs) noexcept
Definition dataPointPath.hpp:374
nlohmann::json JsonPayload
Type requirements:
Definition jsonPayload.hpp:25
bool operator<=(const DataPointPath &lhs, const char *rhs) noexcept
Definition dataPointPath.hpp:366
std::ostream & operator<<(std::ostream &out, const DataPointPath &rhs)
Definition dataPointPath.hpp:440
void from_json(const JsonPayload &j, std::vector< DataPointPath > &v)
Definition dataPointPath.cpp:217
elt::mal::future< std::string > InjectReqRepEvent(StateMachineEngine &engine)
Definition malEventInjector.hpp:23
bool operator==(const DataPointPath &lhs, const char *rhs) noexcept
Definition dataPointPath.hpp:358
DataPointPath operator+(DataPointPath lhs, const DataPointPath &rhs)
Definition dataPointPath.hpp:418
bool operator>(const DataPointPath &lhs, const char *rhs) noexcept
Definition dataPointPath.hpp:370
DataPointPath m_path
Definition populateConfig.cpp:165
auto format(const rtctk::componentFramework::DataPointPath &path, fmt::format_context &ctx) -> fmt::format_context::iterator