RTC Toolkit  1.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 
35 public:
39  class InvalidPathException : public elt::error::CiiBaseException {
40  public:
41  using elt::error::CiiBaseException::CiiBaseException;
42  explicit InvalidPathException(const std::string& path);
43  };
44 
45  DataPointPath() = default;
46  DataPointPath(const DataPointPath&) = default;
50  virtual ~DataPointPath() = default;
51 
58  explicit DataPointPath(const std::string& new_path);
59 
66  explicit DataPointPath(std::string&& new_path);
67 
74  explicit DataPointPath(const char* const new_path) : DataPointPath(std::string(new_path)) {
75  }
76 
80  const std::string& ToString() const noexcept;
81 
88  DataPointPath& operator=(const std::string& new_path);
89 
96  DataPointPath& operator=(std::string&& new_path);
97 
103  operator std::string() const noexcept;
104 
105  // Append Operators
111  DataPointPath& operator+=(const DataPointPath& rhs);
116  DataPointPath& operator/=(const DataPointPath& rhs);
117 
123  friend DataPointPath operator+(DataPointPath lhs, const DataPointPath& rhs);
124 
130  friend DataPointPath operator/(DataPointPath lhs, const DataPointPath& rhs);
131 
135  friend std::ostream& operator<<(std::ostream& out, const DataPointPath& rhs);
136 
137  // Comparison operators for DataPointPath, char * and string
138  friend bool operator==(const DataPointPath& lhs, const char* rhs) noexcept;
139  friend bool operator!=(const DataPointPath& lhs, const char* rhs) noexcept {
140  return !(lhs == rhs);
141  }
142 
143  friend bool operator==(const DataPointPath& lhs, const std::string& rhs) noexcept;
144  friend bool operator!=(const DataPointPath& lhs, const std::string& rhs) noexcept {
145  return !(lhs == rhs);
146  }
147 
148  friend bool operator==(const DataPointPath& lhs, const DataPointPath& rhs) noexcept;
149  friend bool operator!=(const DataPointPath& lhs, const DataPointPath& rhs) noexcept {
150  return !(lhs == rhs);
151  }
152 
153  // symmetry
154  friend bool operator==(const char* lhs, const DataPointPath& rhs) noexcept {
155  return rhs == lhs;
156  }
157  friend bool operator!=(const char* lhs, const DataPointPath& rhs) noexcept {
158  return !(rhs == lhs);
159  }
160 
161  friend bool operator==(const std::string& lhs, const DataPointPath& rhs) noexcept {
162  return rhs == lhs;
163  }
164  friend bool operator!=(const std::string& lhs, const DataPointPath& rhs) noexcept {
165  return !(rhs == lhs);
166  }
167 
171  friend std::istream& operator>>(std::istream& input, DataPointPath& path);
177  elt::mal::Uri ToRepositoryURI(const elt::mal::Uri& base_uri) const;
178 
179 private:
180  const static std::regex REGEX_VALID_CHARS;
181 
182  static bool ValidPath(const std::string& path);
183 
184  std::string path;
185 
189  const static char VALID_CHARACTERS[];
190 }; // class RepositoryPath
191 
192 DataPointPath operator"" _dppath(const char* str, std::size_t len);
193 
194 // inline implementations
195 
196 inline bool operator==(const DataPointPath& lhs, const char* rhs) noexcept {
197  return lhs.path == rhs;
198 }
199 
200 inline bool operator==(const DataPointPath& lhs, const std::string& rhs) noexcept {
201  return lhs.path == rhs;
202 }
203 
204 inline bool operator==(const DataPointPath& lhs, const DataPointPath& rhs) noexcept {
205  return lhs.path == rhs.path;
206 }
207 
209  lhs += rhs;
210  return lhs;
211 }
212 
214  lhs /= rhs;
215  return lhs;
216 }
217 
218 inline const std::string& DataPointPath::ToString() const noexcept {
219  return this->path;
220 }
221 
223  this->path += rhs.path;
224  return *this;
225 }
226 
228  this->path += "/" + rhs.path;
229  return *this;
230 }
231 
232 inline DataPointPath operator"" _dppath(const char* str, std::size_t len) {
233  return DataPointPath(std::string(str));
234 }
235 
236 inline DataPointPath::operator std::string() const noexcept {
237  return path;
238 }
239 
240 inline std::ostream& operator<<(std::ostream& out, const DataPointPath& rhs) {
241  out << rhs.path;
242  return out;
243 }
244 
245 } // namespace rtctk::componentFramework
246 
247 #endif // RTCTK_COMPONENTFRAMEWORK_DATAPOINTPATH_HPP
exceptions.hpp
Provides macros and utilities for exception handling.
rtctk::componentFramework::DataPointPath::DataPointPath
DataPointPath(DataPointPath &&)=default
rtctk::componentFramework::operator/
DataPointPath operator/(DataPointPath lhs, const DataPointPath &rhs)
Definition: dataPointPath.hpp:213
rtctk::componentFramework::DataPointPath::operator>>
friend std::istream & operator>>(std::istream &input, DataPointPath &path)
Read into DataPointPath from istream.
Definition: dataPointPath.cpp:68
rtctk::componentFramework::DataPointPath::operator=
DataPointPath & operator=(DataPointPath &&)=default
rtctk::componentFramework
Definition: commandReplier.cpp:20
rtctk::componentFramework::DataPointPath::operator==
friend bool operator==(const char *lhs, const DataPointPath &rhs) noexcept
Definition: dataPointPath.hpp:154
rtctk::componentFramework::DataPointPath::ToString
const std::string & ToString() const noexcept
Get string representing the DataPointPath.
Definition: dataPointPath.hpp:218
rtctk::componentFramework::DataPointPath::~DataPointPath
virtual ~DataPointPath()=default
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:144
rtctk::componentFramework::DataPointPath::DataPointPath
DataPointPath(const DataPointPath &)=default
rtctk::componentFramework::DataPointPath::operator==
friend bool operator==(const DataPointPath &lhs, const char *rhs) noexcept
Definition: dataPointPath.hpp:196
rtctk::componentFramework::DataPointPath::operator==
friend bool operator==(const std::string &lhs, const DataPointPath &rhs) noexcept
Definition: dataPointPath.hpp:161
rtctk::componentFramework::DataPointPath::InvalidPathException::InvalidPathException
InvalidPathException(const std::string &path)
Definition: dataPointPath.cpp:17
rtctk::componentFramework::DataPointPath::operator+=
DataPointPath & operator+=(const DataPointPath &rhs)
Append another DataPointPath to this DataPointPath without adding a path seperator.
Definition: dataPointPath.hpp:222
rtctk::componentFramework::DataPointPath::operator!=
friend bool operator!=(const char *lhs, const DataPointPath &rhs) noexcept
Definition: dataPointPath.hpp:157
rtctk::componentFramework::DataPointPath::InvalidPathException
Exception class used when an invalid character is used in a DataPointPath.
Definition: dataPointPath.hpp:39
rtctk::componentFramework::operator<<
std::ostream & operator<<(std::ostream &out, const DataPointPath &rhs)
Definition: dataPointPath.hpp:240
std
Definition: mudpiProcessingError.hpp:119
rtctk::componentFramework::DataPointPath::operator!=
friend bool operator!=(const std::string &lhs, const DataPointPath &rhs) noexcept
Definition: dataPointPath.hpp:164
rtctk::componentFramework::DataPointPath::DataPointPath
DataPointPath(const char *const new_path)
Create DataPointPath from a const char *.
Definition: dataPointPath.hpp:74
rtctk::componentFramework::DataPointPath::operator!=
friend bool operator!=(const DataPointPath &lhs, const DataPointPath &rhs) noexcept
Definition: dataPointPath.hpp:149
rtctk::componentFramework::DataPointPath
This class provides a wraper for DataPoint paths which ensures that they only contain valid character...
Definition: dataPointPath.hpp:34
rtctk::componentFramework::DataPointPath::operator/=
DataPointPath & operator/=(const DataPointPath &rhs)
Append another DataPointPath to this DataPointPath with a path seperator inbetween.
Definition: dataPointPath.hpp:227
rtctk::componentFramework::operator==
bool operator==(const DataPointPath &lhs, const char *rhs) noexcept
Definition: dataPointPath.hpp:196
rtctk::componentFramework::operator+
DataPointPath operator+(DataPointPath lhs, const DataPointPath &rhs)
Definition: dataPointPath.hpp:208
rtctk::componentFramework::DataPointPath::ToRepositoryURI
elt::mal::Uri ToRepositoryURI(const elt::mal::Uri &base_uri) const
Return URI.
Definition: dataPointPath.cpp:60