12#ifndef RTCTK_COMPONENTFRAMEWORK_REPOSITORYIF_HPP
13#define RTCTK_COMPONENTFRAMEWORK_REPOSITORYIF_HPP
20#include <initializer_list>
29#include <taiclock/taiClock.hpp>
56 using Clock = taiclock::TaiClock;
112 const std::vector<Info>&
GetInfo()
const;
115 static RTCTK_LOCAL std::string InfoToString(
const std::vector<Info>& info);
117 std::shared_ptr<std::vector<Info>> m_info;
165 inline bool HasValue() const noexcept;
177 inline operator const
std::any&() const;
186 template <typename T>
187 const T&
Cast() const;
195 const
std::
string& m_key;
198 const
std::any& m_value;
219 inline bool HasValue() const noexcept;
231 inline operator const
std::any&() const;
240 template <typename T>
250 template <typename T>
251 const T&
Cast() const;
272 template <typename T>
280 inline
void Reset() noexcept;
288 const
std::
string& m_key;
295 using MapType =
std::map<
std::
string,
std::any>;
304 template <typename MapIterType, typename ProxyType>
307 using iterator_concept = std::bidirectional_iterator_tag;
308 using iterator_category = std::bidirectional_iterator_tag;
309 using value_type = std::pair<const MapType::key_type&, ProxyType>;
310 using difference_type = MapType::difference_type;
311 using pointer = void;
312 using reference = std::conditional_t<std::is_same_v<ProxyType, ConstValueProxy>,
319 IteratorImpl() =
default;
321 IteratorImpl(
const IteratorImpl& rhs) =
default;
323 IteratorImpl(IteratorImpl&& rhs)
noexcept =
default;
324 ~IteratorImpl() =
default;
325 IteratorImpl&
operator=(
const IteratorImpl& rhs) =
default;
326 IteratorImpl&
operator=(IteratorImpl&& rhs)
noexcept =
default;
327 value_type& operator*();
328 value_type operator*()
const;
329 value_type* operator->();
330 const value_type* operator->()
const;
331 IteratorImpl& operator++();
332 IteratorImpl operator++(
int);
333 IteratorImpl& operator--();
334 IteratorImpl operator--(
int);
335 bool operator==(
const IteratorImpl& rhs)
const;
336 bool operator!=(
const IteratorImpl& rhs)
const;
339 RTCTK_LOCAL explicit IteratorImpl(MapIterType&& iter);
341 MapIterType m_iterator;
347 std::optional<value_type> m_pair;
354 class RTCTK_API Iterator final :
public IteratorImpl<MapType::iterator, ValueProxy> {
357 RTCTK_LOCAL inline Iterator(MapType::iterator&& iter);
365 :
public IteratorImpl<MapType::const_iterator, ConstValueProxy> {
368 RTCTK_LOCAL inline ConstIterator(MapType::const_iterator&& iter);
375 :
public IteratorImpl<MapType::reverse_iterator, ValueProxy> {
378 RTCTK_LOCAL inline ReverseIterator(MapType::reverse_iterator&& iter);
386 :
public IteratorImpl<MapType::const_reverse_iterator, ConstValueProxy> {
389 RTCTK_LOCAL inline ConstReverseIterator(MapType::const_reverse_iterator&& iter);
398 const std::string&
GetKey()
const;
401 std::shared_ptr<std::string> m_key;
410 const std::string&
GetKey()
const;
413 std::shared_ptr<std::string> m_key;
423 const std::type_info& type_used,
424 const std::type_info& type_expected);
425 const std::string&
GetKey()
const;
431 inline Attributes(
const std::string& key,
432 const std::type_info& type_used,
433 const std::type_info& type_expected);
435 std::reference_wrapper<const std::type_info> m_type_used;
436 std::reference_wrapper<const std::type_info> m_type_expected;
439 std::shared_ptr<Attributes> m_attribs;
453 MetaData(std::initializer_list<std::pair<std::string, std::any>> init_list);
462 inline bool Empty()
const;
468 inline size_t GetSize() const noexcept;
475 inline
bool Contains(const
std::
string& key) const;
501 template <typename T>
502 auto&
Insert(const
std::
string& key, T&& value);
512 template <typename T>
513 auto&
Insert(
std::
string&& key, T&& value);
668 template <
typename T>
671 const T& initial_value,
672 std::optional<std::reference_wrapper<const MetaData>> metadata = std::nullopt,
678 template <
typename T>
681 const T&& initial_value,
682 std::optional<std::reference_wrapper<const MetaData>> metadata = std::nullopt,
723 std::pair<PathList, PathList>& result,
724 bool recurse =
false,
731 std::pair<PathList, PathList>&& result,
732 bool recurse =
false,
735 template <
typename T>
738 std::optional<std::reference_wrapper<MetaData>> metadata = std::nullopt,
744 template <
typename T>
747 std::optional<std::reference_wrapper<MetaData>> metadata = std::nullopt,
773 template <
typename T>
776 std::optional<std::reference_wrapper<MetaData>> metadata = std::nullopt,
782 template <
typename T>
785 std::optional<std::reference_wrapper<MetaData>> metadata = std::nullopt,
824 template <
typename T>
831 std::optional<std::reference_wrapper<MetaData>> metadata = std::nullopt,
837 template <
typename T>
844 std::optional<std::reference_wrapper<MetaData>> metadata = std::nullopt,
880 template <
typename T>
887 std::optional<std::reference_wrapper<MetaData>> metadata = std::nullopt,
893 template <
typename T>
900 std::optional<std::reference_wrapper<MetaData>> metadata = std::nullopt,
931 template <
typename T>
934 std::optional<std::reference_wrapper<MetaData>> metadata,
937 template <
typename T>
943 std::optional<std::reference_wrapper<MetaData>> metadata,
956 template <
typename Rep,
typename Period>
957 bool WaitFor(
const std::chrono::duration<Rep, Period>& timeout);
959 template <
typename Clk,
typename Duration>
960 bool WaitUntil(
const std::chrono::time_point<Clk, Duration>& timeout);
983 template <
typename T>
999 template <
typename T>
1118 std::pair<PathList, PathList>
1135 template <
typename T>
1152 template <
typename T>
1169 template <
typename T>
1189 template <
typename T>
1210 template <
typename T>
1215 template <
typename... T>
1218 template <
typename... T>
1228 static const std::type_info&
StringToType(
const std::string& arg);
1237 static std::string
TypeToString(
const std::type_info& arg);
Header file for basic type aliases.
The BufferTooSmall is thrown when an API call fails because the provided buffer is not big enough to ...
Definition exceptions.hpp:273
BufferTooSmall(const std::size_t actual, const std::size_t expected)
Construct exception object.
Definition exceptions.cpp:158
This class provides a wrapper for a data point path.
Definition dataPointPath.hpp:76
Definition repositoryIf.hpp:94
An object representing one or more asynchronous I/O requests to a repository.
Definition repositoryIf.hpp:638
void DataPointExists(const DataPointPath &path, bool &result, const CallbackType &callback=nullptr) const
Definition repositoryIf.cpp:350
void PartialReadDataPoint(const DataPointPath &path, T &&buffer, size_t first, size_t last, size_t d_first, std::optional< std::reference_wrapper< MetaData > > metadata=std::nullopt, const CallbackType &callback=nullptr) const =delete
Reading from a datapoint into an rvalue reference is not allowed.
RequestList m_requests
Definition repositoryIf.hpp:928
void WriteDataPoint(const DataPointPath &path, const T &buffer, std::optional< std::reference_wrapper< MetaData > > metadata=std::nullopt, const CallbackType &callback=nullptr)
Add request to write a datapoint.
Definition repositoryIf.ipp:1557
void GetChildren(const DataPointPath &path, std::pair< PathList, PathList > &&result, bool recurse=false, const CallbackType &callback=nullptr) const =delete
Querying children with an rvalue reference for the result is not allowed.
void PartialWriteDataPoint(const DataPointPath &path, const T &&buffer, size_t first, size_t last, size_t d_first, std::optional< std::reference_wrapper< MetaData > > metadata=std::nullopt, const CallbackType &callback=nullptr)=delete
Writing to a datapoint from an rvalue reference is not allowed.
void DeleteDataPoint(const DataPointPath &path, const CallbackType &callback=nullptr)
Definition repositoryIf.cpp:344
virtual ~BatchRequest()=default
void WriteDataPoint(const DataPointPath &path, const T &&buffer, std::optional< std::reference_wrapper< MetaData > > metadata=std::nullopt, const CallbackType &callback=nullptr)=delete
Writing to a datapoint from an rvalue reference is not allowed.
void ReadDataPoint(const DataPointPath &path, T &buffer, std::optional< std::reference_wrapper< MetaData > > metadata=std::nullopt, const CallbackType &callback=nullptr) const
Definition repositoryIf.ipp:1459
void GetChildren(const DataPointPath &path, std::pair< PathList, PathList > &result, bool recurse=false, const CallbackType &callback=nullptr) const
Add request to query the child datapoints and paths for a given parent path.
void PartialReadDataPoint(const DataPointPath &path, T &buffer, size_t first, size_t last, size_t d_first, std::optional< std::reference_wrapper< MetaData > > metadata=std::nullopt, const CallbackType &callback=nullptr) const
Add request to partially read a datapoint.
Definition repositoryIf.ipp:1614
void CreateDataPoint(const DataPointPath &path, const T &&initial_value, std::optional< std::reference_wrapper< const MetaData > > metadata=std::nullopt, const CallbackType &callback=nullptr)=delete
Creation of datapoints from an rvalue reference is not allowed.
void ReadDataPoint(const DataPointPath &path, T &&buffer, std::optional< std::reference_wrapper< MetaData > > metadata=std::nullopt, const CallbackType &callback=nullptr) const =delete
Reading from a datapoint into an rvalue reference is not allowed.
void ReadMetaData(const DataPointPath &path, MetaData &metadata, const CallbackType &callback=nullptr) const
Definition repositoryIf.cpp:372
void CreateSymlink(const DataPointPath &dp, const DataPointPath &link, const CallbackType &callback=nullptr)
Definition repositoryIf.cpp:388
void PartialWriteDataPoint(const DataPointPath &path, const T &buffer, size_t first, size_t last, size_t d_first, std::optional< std::reference_wrapper< MetaData > > metadata=std::nullopt, const CallbackType &callback=nullptr)
Add request to partially write a datapoint.
Definition repositoryIf.ipp:1701
void ReadMetaData(const DataPointPath &path, MetaData &&metadata, const CallbackType &callback=nullptr) const =delete
Reading metadata into an rvalue reference is not allowed.
void CreateDataPoint(const DataPointPath &path, const T &initial_value, std::optional< std::reference_wrapper< const MetaData > > metadata=std::nullopt, const CallbackType &callback=nullptr)
Add a request to create a new datapoint.
Definition repositoryIf.ipp:1400
friend RepositoryIf
Definition repositoryIf.hpp:927
void UpdateSymlink(const DataPointPath &dp, const DataPointPath &link, const CallbackType &callback=nullptr)
Definition repositoryIf.cpp:397
void WriteMetaData(const DataPointPath &path, const MetaData &metadata, const CallbackType &callback=nullptr)
Definition repositoryIf.cpp:380
Definition repositoryIf.hpp:947
std::vector< std::future< void > > ResponseList
Definition repositoryIf.hpp:949
void Wait()
Definition repositoryIf.cpp:650
ResponseList m_responses
Definition repositoryIf.hpp:963
BatchResponse(ResponseList futures)
Definition repositoryIf.cpp:646
bool WaitFor(const std::chrono::duration< Rep, Period > &timeout)
Definition repositoryIf.ipp:1822
bool WaitUntil(const std::chrono::time_point< Clk, Duration > &timeout)
Definition repositoryIf.ipp:1833
BufferTooSmall(const std::size_t actual, const std::size_t expected)
Construct exception object.
Definition exceptions.cpp:158
Definition repositoryIf.hpp:85
Definition repositoryIf.hpp:81
Definition repositoryIf.hpp:77
Definition repositoryIf.hpp:73
const std::vector< Info > & GetInfo() const
Definition repositoryIf.cpp:139
MultipleRequestsFailed(const std::vector< Info > &info)
Definition repositoryIf.cpp:134
Status
Definition repositoryIf.hpp:104
@ Success
Definition repositoryIf.hpp:104
@ Failed
Definition repositoryIf.hpp:104
@ Skipped
Definition repositoryIf.hpp:104
Definition repositoryIf.hpp:98
Definition repositoryIf.hpp:65
Definition repositoryIf.hpp:69
static const std::type_info & StringToType(const std::string &arg)
Converts an RTC datapoint type string to a type_info.
Definition repositoryIf.cpp:886
virtual BatchResponse ProcessRequests(const RequestList &requests)=0
std::optional< T > TryGetDataPoint(const DataPointPath &path) const
Fetches a datapoint from the repository.
Definition repositoryIf.ipp:1882
Clock::time_point Timestamp
Definition repositoryIf.hpp:57
void WriteDataPoints(const T &... args)
Definition repositoryIf.ipp:1922
T GetDataPoint(const DataPointPath &path) const
Fetches a datapoint from the repository.
Definition repositoryIf.ipp:1864
static std::string TypeToString(const std::type_info &arg)
Converts a type_info to an RTC datapoint type string.
Definition repositoryIf.cpp:894
void ReadDataPoints(T &... args) const
Definition repositoryIf.ipp:1938
size_t GetDataPointSize(const DataPointPath &path) const
Fetches the size of the datapoint's data.
Definition repositoryIf.cpp:707
void CreateDataPoint(const DataPointPath &path)
Creates a new empty datapoint in the repository.
Definition repositoryIf.ipp:1847
std::pair< PathList, PathList > GetChildren(const DataPointPath &path, bool recurse=false) const
Queries the child datapoints and paths for a given parent path.
Definition repositoryIf.cpp:780
static std::any MakeAnyBuffer(const MetaData &metadata)
Helper method to create an std::any buffer compatible with a specific datapoint.
Definition repositoryIf.cpp:902
void SetDataPoint(const DataPointPath &path, const T &value)
Sets a datapoint in the repository.
Definition repositoryIf.ipp:1890
taiclock::TaiClock Clock
Definition repositoryIf.hpp:56
RtcVectorUInt64 GetDataPointShape(const DataPointPath &path) const
Fetches the shape of the datapoint's data.
Definition repositoryIf.cpp:762
std::vector< std::any > RequestList
Definition repositoryIf.hpp:52
void WriteDataPoint(const DataPointPath &path, const T &buffer)
Writes a datapoint to the repository.
Definition repositoryIf.ipp:1915
std::vector< DataPointPath > PathList
Definition repositoryIf.hpp:55
BatchResponse SendRequest(const BatchRequest &request)
Definition repositoryIf.cpp:674
void ReadDataPoint(const DataPointPath &path, T &buffer) const
Reads a datapoint from the repository.
Definition repositoryIf.ipp:1897
std::function< void(const DataPointPath &)> CallbackType
Signature of the callback functions that can be registered with the repository requests.
Definition repositoryIf.hpp:60
const std::type_info & GetDataPointType(const DataPointPath &path) const
Fetches the type of the datapoint.
Definition repositoryIf.cpp:698
void DeleteDataPoint(const DataPointPath &path, bool recurse=false)
Deletes a datapoint.
Definition repositoryIf.cpp:683
virtual ~RepositoryIf()=default
bool DataPointExists(const DataPointPath &path) const
Checks for the existence of a datapoint in the repository.
Definition repositoryIf.cpp:771
RtctkException() noexcept
Definition exceptions.cpp:112
UnsupportedTypeException(const std::string &type)
Definition exceptions.cpp:130
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
Header file for DataPointPath.
Provides macros and utilities for exception handling.
Declaration of the MatrixBuffer template class used in APIs.
Declaration of the MatrixSpan template class used in APIs.
Definition commandReplier.cpp:21
bool operator==(const DataPointPath &lhs, const char *rhs) noexcept
Definition dataPointPath.hpp:367
constexpr bool operator!=(const MatrixBuffer< T, A > &lhs, const MatrixBuffer< T, A > &rhs) noexcept
Compares two MatrixBuffer objects and returns true if they do not have the same shape or the elements...
Definition matrixBuffer.hpp:116
RtcVector< RtcUInt64 > RtcVectorUInt64
Definition basicTypes.hpp:57
Definition ddsSub.hpp:155
Implementation file for RepositoryIf template methods and related classes.
Definition repositoryIf.hpp:106
Status status
Definition repositoryIf.hpp:107
std::exception_ptr exception
Definition repositoryIf.hpp:108