RTC Toolkit  2.0.0
dataPointPath.hpp
Go to the documentation of this file.
1 
12 #ifndef RTCTK_COMPONENTFRAMEWORK_DATAPOINTPATH_HPP
13 #define RTCTK_COMPONENTFRAMEWORK_DATAPOINTPATH_HPP
14 
15 #include <algorithm>
16 #include <iostream>
17 #include <regex>
18 #include <stdexcept>
19 #include <string>
20 #include <string_view>
21 #include <type_traits>
22 
23 #include <mal/utility/Uri.hpp>
24 
26 
27 namespace rtctk::componentFramework {
28 
66 public:
70  class InvalidPathException : public elt::error::CiiBaseException {
71  public:
72  using elt::error::CiiBaseException::CiiBaseException;
73  explicit InvalidPathException(const std::string& path);
74  };
75 
76  DataPointPath() = default;
77  DataPointPath(const DataPointPath&) = default;
81  virtual ~DataPointPath() = default;
82 
89  explicit DataPointPath(const std::string& new_path);
90 
97  explicit DataPointPath(std::string&& new_path);
98 
105  explicit DataPointPath(const char* const new_path) : DataPointPath(std::string(new_path)) {
106  }
107 
111  const std::string& ToString() const noexcept;
112 
119  DataPointPath& operator=(const std::string& new_path);
120 
127  DataPointPath& operator=(std::string&& new_path);
128 
135  operator std::string() const noexcept;
136 
137  // Append Operators
146  DataPointPath& operator+=(const DataPointPath& rhs);
158  DataPointPath& operator/=(const DataPointPath& rhs);
159 
168  friend DataPointPath operator+(DataPointPath lhs, const DataPointPath& rhs);
169 
180  friend DataPointPath operator/(DataPointPath lhs, const DataPointPath& rhs);
181 
185  friend std::ostream& operator<<(std::ostream& out, const DataPointPath& rhs);
186 
187  // Comparison operators for DataPointPath, char * and string
188  friend bool operator==(const DataPointPath& lhs, const char* rhs) noexcept;
189  friend bool operator!=(const DataPointPath& lhs, const char* rhs) noexcept {
190  return !(lhs == rhs);
191  }
192  friend bool operator<(const DataPointPath& lhs, const char* rhs) noexcept;
193  friend bool operator<=(const DataPointPath& lhs, const char* rhs) noexcept;
194  friend bool operator>(const DataPointPath& lhs, const char* rhs) noexcept;
195  friend bool operator>=(const DataPointPath& lhs, const char* rhs) noexcept;
196 
197  friend bool operator==(const DataPointPath& lhs, const std::string& rhs) noexcept;
198  friend bool operator!=(const DataPointPath& lhs, const std::string& rhs) noexcept {
199  return !(lhs == rhs);
200  }
201  friend bool operator<(const DataPointPath& lhs, const std::string& rhs) noexcept;
202  friend bool operator<=(const DataPointPath& lhs, const std::string& rhs) noexcept;
203  friend bool operator>(const DataPointPath& lhs, const std::string& rhs) noexcept;
204  friend bool operator>=(const DataPointPath& lhs, const std::string& rhs) noexcept;
205 
206  friend bool operator==(const DataPointPath& lhs, const DataPointPath& rhs) noexcept;
207  friend bool operator!=(const DataPointPath& lhs, const DataPointPath& rhs) noexcept {
208  return !(lhs == rhs);
209  }
210  friend bool operator<(const DataPointPath& lhs, const DataPointPath& rhs) noexcept;
211  friend bool operator<=(const DataPointPath& lhs, const DataPointPath& rhs) noexcept;
212  friend bool operator>(const DataPointPath& lhs, const DataPointPath& rhs) noexcept;
213  friend bool operator>=(const DataPointPath& lhs, const DataPointPath& rhs) noexcept;
214 
215  // symmetry
216  friend bool operator==(const char* lhs, const DataPointPath& rhs) noexcept {
217  return rhs == lhs;
218  }
219  friend bool operator!=(const char* lhs, const DataPointPath& rhs) noexcept {
220  return !(rhs == lhs);
221  }
222  friend bool operator<(const char* lhs, const DataPointPath& rhs) noexcept {
223  return rhs > lhs;
224  }
225  friend bool operator<=(const char* lhs, const DataPointPath& rhs) noexcept {
226  return rhs >= lhs;
227  }
228  friend bool operator>(const char* lhs, const DataPointPath& rhs) noexcept {
229  return rhs < lhs;
230  }
231  friend bool operator>=(const char* lhs, const DataPointPath& rhs) noexcept {
232  return rhs <= lhs;
233  }
234 
235  friend bool operator==(const std::string& lhs, const DataPointPath& rhs) noexcept {
236  return rhs == lhs;
237  }
238  friend bool operator!=(const std::string& lhs, const DataPointPath& rhs) noexcept {
239  return !(rhs == lhs);
240  }
241  friend bool operator<(const std::string& lhs, const DataPointPath& rhs) noexcept {
242  return rhs > lhs;
243  }
244  friend bool operator<=(const std::string& lhs, const DataPointPath& rhs) noexcept {
245  return rhs >= lhs;
246  }
247  friend bool operator>(const std::string& lhs, const DataPointPath& rhs) noexcept {
248  return rhs < lhs;
249  }
250  friend bool operator>=(const std::string& lhs, const DataPointPath& rhs) noexcept {
251  return rhs <= lhs;
252  }
253 
257  friend std::istream& operator>>(std::istream& input, DataPointPath& path);
268  elt::mal::Uri ToRepositoryURI(const elt::mal::Uri& base_uri) const;
269 
283  static elt::mal::Uri AppendSuffixToUriPath(const std::string& suffix, const elt::mal::Uri& uri);
284 
285 private:
291  static bool ValidPath(const std::string& path);
292 
293  std::string path;
294 
296  const static char VALID_CHARACTERS[];
297 
299  const static std::regex REGEX_VALID_CHARS;
300 }; // class DataPointPath
301 
302 DataPointPath operator"" _dppath(const char* str, std::size_t len);
303 
304 // inline implementations
305 
306 inline bool operator==(const DataPointPath& lhs, const char* rhs) noexcept {
307  return lhs.path == rhs;
308 }
309 
310 inline bool operator<(const DataPointPath& lhs, const char* rhs) noexcept {
311  return lhs.path < rhs;
312 }
313 
314 inline bool operator<=(const DataPointPath& lhs, const char* rhs) noexcept {
315  return lhs.path <= rhs;
316 }
317 
318 inline bool operator>(const DataPointPath& lhs, const char* rhs) noexcept {
319  return lhs.path > rhs;
320 }
321 
322 inline bool operator>=(const DataPointPath& lhs, const char* rhs) noexcept {
323  return lhs.path >= rhs;
324 }
325 
326 inline bool operator==(const DataPointPath& lhs, const std::string& rhs) noexcept {
327  return lhs.path == rhs;
328 }
329 
330 inline bool operator<(const DataPointPath& lhs, const std::string& rhs) noexcept {
331  return lhs.path < rhs;
332 }
333 
334 inline bool operator<=(const DataPointPath& lhs, const std::string& rhs) noexcept {
335  return lhs.path <= rhs;
336 }
337 
338 inline bool operator>(const DataPointPath& lhs, const std::string& rhs) noexcept {
339  return lhs.path > rhs;
340 }
341 
342 inline bool operator>=(const DataPointPath& lhs, const std::string& rhs) noexcept {
343  return lhs.path >= rhs;
344 }
345 
346 inline bool operator==(const DataPointPath& lhs, const DataPointPath& rhs) noexcept {
347  return lhs.path == rhs.path;
348 }
349 
350 inline bool operator<(const DataPointPath& lhs, const DataPointPath& rhs) noexcept {
351  return lhs.path < rhs.path;
352 }
353 
354 inline bool operator<=(const DataPointPath& lhs, const DataPointPath& rhs) noexcept {
355  return lhs.path <= rhs.path;
356 }
357 
358 inline bool operator>(const DataPointPath& lhs, const DataPointPath& rhs) noexcept {
359  return lhs.path > rhs.path;
360 }
361 
362 inline bool operator>=(const DataPointPath& lhs, const DataPointPath& rhs) noexcept {
363  return lhs.path >= rhs.path;
364 }
365 
367  lhs += rhs;
368  if (not DataPointPath::ValidPath(lhs)) {
369  CII_THROW(DataPointPath::InvalidPathException, lhs);
370  }
371  return lhs;
372 }
373 
375  lhs /= rhs;
376  return lhs;
377 }
378 
379 inline const std::string& DataPointPath::ToString() const noexcept {
380  return this->path;
381 }
382 
384  this->path += rhs.path;
385  if (not DataPointPath::ValidPath(*this)) {
386  CII_THROW(DataPointPath::InvalidPathException, *this);
387  }
388  return *this;
389 }
390 
392  std::string::value_type this_path_back = this->path.empty() ? '0' : this->path.back();
393  std::string::value_type rhs_path_front = rhs.path.empty() ? '0' : rhs.path.front();
394  if (this_path_back != '/' and rhs_path_front != '/') {
395  // If we do not end or start with a slash then add one.
396  this->path += "/" + rhs.path;
397  } else if (this_path_back == '/' and rhs_path_front == '/') {
398  // If we end and start with a slash then ignore one of them.
399  this->path.append(rhs.path, 1);
400  } else {
401  this->path += rhs.path;
402  }
403  return *this;
404 }
405 
406 inline DataPointPath operator"" _dppath(const char* str, std::size_t len) {
407  return DataPointPath(std::string(str));
408 }
409 
410 inline DataPointPath::operator std::string() const noexcept {
411  return path;
412 }
413 
414 inline std::ostream& operator<<(std::ostream& out, const DataPointPath& rhs) {
415  out << rhs.path;
416  return out;
417 }
418 
419 } // namespace rtctk::componentFramework
420 
421 #endif // RTCTK_COMPONENTFRAMEWORK_DATAPOINTPATH_HPP
exceptions.hpp
Provides macros and utilities for exception handling.
rtctk::componentFramework::DataPointPath::operator>=
friend bool operator>=(const char *lhs, const DataPointPath &rhs) noexcept
Definition: dataPointPath.hpp:231
rtctk::componentFramework::DataPointPath::DataPointPath
DataPointPath(DataPointPath &&)=default
rtctk::componentFramework::operator/
DataPointPath operator/(DataPointPath lhs, const DataPointPath &rhs)
Definition: dataPointPath.hpp:374
rtctk::componentFramework::DataPointPath::operator>
friend bool operator>(const char *lhs, const DataPointPath &rhs) noexcept
Definition: dataPointPath.hpp:228
rtctk::componentFramework::DataPointPath::operator>
friend bool operator>(const DataPointPath &lhs, const char *rhs) noexcept
Definition: dataPointPath.hpp:318
rtctk::componentFramework::DataPointPath::operator>>
friend std::istream & operator>>(std::istream &input, DataPointPath &path)
Read into DataPointPath from istream.
Definition: dataPointPath.cpp:92
rtctk::componentFramework::DataPointPath::operator=
DataPointPath & operator=(DataPointPath &&)=default
rtctk::componentFramework
Definition: commandReplier.cpp:20
rtctk::componentFramework::DataPointPath::operator>
friend bool operator>(const std::string &lhs, const DataPointPath &rhs) noexcept
Definition: dataPointPath.hpp:247
rtctk::componentFramework::DataPointPath::operator==
friend bool operator==(const char *lhs, const DataPointPath &rhs) noexcept
Definition: dataPointPath.hpp:216
rtctk::componentFramework::operator<=
bool operator<=(const DataPointPath &lhs, const char *rhs) noexcept
Definition: dataPointPath.hpp:314
rtctk::componentFramework::operator<<
std::ostream & operator<<(std::ostream &os, AlertServiceIf::AlertStatus const &status)
Definition: alertServiceIf.cpp:59
rtctk::componentFramework::DataPointPath::ToString
const std::string & ToString() const noexcept
Get string representing the DataPointPath.
Definition: dataPointPath.hpp:379
rtctk::componentFramework::DataPointPath::~DataPointPath
virtual ~DataPointPath()=default
rtctk::componentFramework::DataPointPath::AppendSuffixToUriPath
static elt::mal::Uri AppendSuffixToUriPath(const std::string &suffix, const elt::mal::Uri &uri)
Appends a suffix string to the path of a URI.
Definition: dataPointPath.cpp:70
rtctk::componentFramework::DataPointPath::DataPointPath
DataPointPath()=default
rtctk::componentFramework::DataPointPath::operator=
DataPointPath & operator=(const DataPointPath &)=default
rtctk::componentFramework::DataPointPath::operator!=
friend bool operator!=(const DataPointPath &lhs, const std::string &rhs) noexcept
Definition: dataPointPath.hpp:198
rtctk::componentFramework::DataPointPath::DataPointPath
DataPointPath(const DataPointPath &)=default
rtctk::componentFramework::operator>
bool operator>(const DataPointPath &lhs, const char *rhs) noexcept
Definition: dataPointPath.hpp:318
rtctk::componentFramework::DataPointPath::operator<
friend bool operator<(const char *lhs, const DataPointPath &rhs) noexcept
Definition: dataPointPath.hpp:222
rtctk::componentFramework::DataPointPath::operator==
friend bool operator==(const DataPointPath &lhs, const char *rhs) noexcept
Definition: dataPointPath.hpp:306
rtctk::componentFramework::DataPointPath::operator==
friend bool operator==(const std::string &lhs, const DataPointPath &rhs) noexcept
Definition: dataPointPath.hpp:235
rtctk::componentFramework::DataPointPath::InvalidPathException::InvalidPathException
InvalidPathException(const std::string &path)
Definition: dataPointPath.cpp:17
rtctk::componentFramework::DataPointPath::operator<
friend bool operator<(const DataPointPath &lhs, const char *rhs) noexcept
Definition: dataPointPath.hpp:310
rtctk::componentFramework::DataPointPath::operator+=
DataPointPath & operator+=(const DataPointPath &rhs)
Append another DataPointPath to this DataPointPath without adding a path seperator,...
Definition: dataPointPath.hpp:383
rtctk::componentFramework::DataPointPath::operator!=
friend bool operator!=(const char *lhs, const DataPointPath &rhs) noexcept
Definition: dataPointPath.hpp:219
rtctk::componentFramework::DataPointPath::InvalidPathException
Exception class used when an invalid character is used in a DataPointPath.
Definition: dataPointPath.hpp:70
rtctk::componentFramework::DataPointPath::operator<=
friend bool operator<=(const char *lhs, const DataPointPath &rhs) noexcept
Definition: dataPointPath.hpp:225
rtctk::componentFramework::DataPointPath::operator>=
friend bool operator>=(const DataPointPath &lhs, const char *rhs) noexcept
Definition: dataPointPath.hpp:322
std
Definition: mudpiProcessingError.hpp:119
rtctk::componentFramework::DataPointPath::operator!=
friend bool operator!=(const std::string &lhs, const DataPointPath &rhs) noexcept
Definition: dataPointPath.hpp:238
rtctk::componentFramework::DataPointPath::DataPointPath
DataPointPath(const char *const new_path)
Create DataPointPath from a null terminated character string.
Definition: dataPointPath.hpp:105
rtctk::componentFramework::DataPointPath::operator>=
friend bool operator>=(const std::string &lhs, const DataPointPath &rhs) noexcept
Definition: dataPointPath.hpp:250
rtctk::componentFramework::DataPointPath::operator<
friend bool operator<(const std::string &lhs, const DataPointPath &rhs) noexcept
Definition: dataPointPath.hpp:241
rtctk::componentFramework::DataPointPath::operator!=
friend bool operator!=(const DataPointPath &lhs, const DataPointPath &rhs) noexcept
Definition: dataPointPath.hpp:207
rtctk::componentFramework::DataPointPath
This class provides a wrapper for a data point path.
Definition: dataPointPath.hpp:65
rtctk::componentFramework::DataPointPath::operator/=
DataPointPath & operator/=(const DataPointPath &rhs)
Append another DataPointPath to this DataPointPath with a path seperator (/) in between if needed.
Definition: dataPointPath.hpp:391
rtctk::componentFramework::operator==
bool operator==(const DataPointPath &lhs, const char *rhs) noexcept
Definition: dataPointPath.hpp:306
rtctk::componentFramework::operator<
bool operator<(const DataPointPath &lhs, const char *rhs) noexcept
Definition: dataPointPath.hpp:310
rtctk::componentFramework::operator+
DataPointPath operator+(DataPointPath lhs, const DataPointPath &rhs)
Definition: dataPointPath.hpp:366
rtctk::componentFramework::DataPointPath::ToRepositoryURI
elt::mal::Uri ToRepositoryURI(const elt::mal::Uri &base_uri) const
Creates and returns a complete URI.
Definition: dataPointPath.cpp:65
rtctk::componentFramework::DataPointPath::operator<=
friend bool operator<=(const DataPointPath &lhs, const char *rhs) noexcept
Definition: dataPointPath.hpp:314
rtctk::componentFramework::operator>=
bool operator>=(const DataPointPath &lhs, const char *rhs) noexcept
Definition: dataPointPath.hpp:322
rtctk::componentFramework::DataPointPath::operator<=
friend bool operator<=(const std::string &lhs, const DataPointPath &rhs) noexcept
Definition: dataPointPath.hpp:244