13#ifndef RTCTK_COMPONENTFRAMEWORK_REPOSITORYIF_HPP
14#define RTCTK_COMPONENTFRAMEWORK_REPOSITORYIF_HPP
22#include <taiclock/taiClock.hpp>
35#include <initializer_list>
120 using RtctkException::RtctkException;
124 using UnsupportedTypeException::UnsupportedTypeException;
128 using RtctkException::RtctkException;
132 using RtctkException::RtctkException;
136 using RtctkException::RtctkException;
145 using RtctkException::RtctkException;
149 using RtctkException::RtctkException;
154 enum class Status : uint8_t { Success, Failed, Skipped };
162 const std::vector<Info>& GetInfo()
const;
165 static RTCTK_LOCAL std::string InfoToString(
const std::vector<Info>& info);
167 std::shared_ptr<std::vector<Info>> m_info;
215 inline bool HasValue() const noexcept;
221 const std::type_info& GetValueType() const noexcept;
227 inline operator const std::any&() const;
236 template <typename T>
237 const T& Cast() const;
245 const std::
string& m_key;
248 const std::any& m_value;
269 inline bool HasValue() const noexcept;
275 const std::type_info& GetValueType() const noexcept;
281 inline operator const std::any&() const;
290 template <typename T>
300 template <typename T>
301 const T& Cast() const;
322 template <typename T>
330 inline
void Reset() noexcept;
338 const std::
string& m_key;
345 using MapType = std::map<std::
string, std::any>;
354 template <typename MapIterType, typename ProxyType>
357 using iterator_concept = std::bidirectional_iterator_tag;
358 using iterator_category = std::bidirectional_iterator_tag;
359 using value_type = std::pair<const MapType::key_type&, ProxyType>;
360 using difference_type = MapType::difference_type;
361 using pointer = void;
362 using reference = std::conditional_t<std::is_same_v<ProxyType, ConstValueProxy>,
366 IteratorImpl() =
default;
367 IteratorImpl(
const IteratorImpl& rhs) =
default;
368 IteratorImpl(IteratorImpl&& rhs)
noexcept =
default;
369 ~IteratorImpl() =
default;
370 IteratorImpl& operator=(
const IteratorImpl& rhs) =
default;
371 IteratorImpl& operator=(IteratorImpl&& rhs)
noexcept =
default;
372 value_type& operator*();
373 value_type operator*()
const;
374 value_type* operator->();
375 const value_type* operator->()
const;
376 IteratorImpl& operator++();
377 IteratorImpl operator++(
int);
378 IteratorImpl& operator--();
379 IteratorImpl operator--(
int);
380 bool operator==(
const IteratorImpl& rhs)
const;
381 bool operator!=(
const IteratorImpl& rhs)
const;
386 MapIterType m_iterator;
392 std::optional<value_type> m_pair;
410 :
public IteratorImpl<MapType::const_iterator, ConstValueProxy> {
420 :
public IteratorImpl<MapType::reverse_iterator, ValueProxy> {
431 :
public IteratorImpl<MapType::const_reverse_iterator, ConstValueProxy> {
443 const std::string& GetKey()
const;
446 std::shared_ptr<std::string> m_key;
455 const std::string& GetKey()
const;
458 std::shared_ptr<std::string> m_key;
468 const std::type_info& type_used,
469 const std::type_info& type_expected);
470 const std::string& GetKey()
const;
471 const std::type_info& GetTypeUsed()
const;
472 const std::type_info& GetTypeExpected()
const;
476 inline Attributes(
const std::string& key,
477 const std::type_info& type_used,
478 const std::type_info& type_expected);
480 std::reference_wrapper<const std::type_info> m_type_used;
481 std::reference_wrapper<const std::type_info> m_type_expected;
484 std::shared_ptr<Attributes> m_attribs;
492 using UnsupportedTypeException::UnsupportedTypeException;
498 MetaData(std::initializer_list<std::pair<std::string, std::any>> init_list);
507 inline bool Empty()
const;
513 inline size_t GetSize() const noexcept;
520 inline
bool Contains(const std::
string& key) const;
546 template <typename T>
547 auto& Insert(const std::
string& key, T&& value);
557 template <typename T>
558 auto& Insert(std::
string&& key, T&& value);
565 bool Remove(const std::
string& key);
572 ValueProxy operator[](const std::
string& key);
711 template <
typename T>
712 void CreateDataPoint(
714 const T& initial_value,
715 std::optional<std::reference_wrapper<const MetaData>> metadata = std::nullopt,
721 template <
typename T>
724 const T&& initial_value,
725 std::optional<std::reference_wrapper<const MetaData>> metadata = std::nullopt,
766 std::pair<PathList, PathList>& result,
767 bool recurse =
false,
774 std::pair<PathList, PathList>&& result,
775 bool recurse =
false,
778 template <
typename T>
781 std::optional<std::reference_wrapper<MetaData>> metadata = std::nullopt,
787 template <
typename T>
790 std::optional<std::reference_wrapper<MetaData>> metadata = std::nullopt,
793 template <
typename T>
797 std::optional<std::reference_wrapper<const MetaData>> metadata = std::nullopt,
803 template <
typename T>
807 std::optional<std::reference_wrapper<const MetaData>> metadata = std::nullopt,
846 template <
typename T>
847 void PartialReadDataPoint(
853 std::optional<std::reference_wrapper<MetaData>> metadata = std::nullopt,
859 template <
typename T>
866 std::optional<std::reference_wrapper<MetaData>> metadata = std::nullopt,
869 template <
typename T>
870 void PartialWriteDataPoint(
876 std::optional<std::reference_wrapper<const MetaData>> metadata = std::nullopt,
882 template <
typename T>
889 std::optional<std::reference_wrapper<const MetaData>> metadata = std::nullopt,
929 template <
typename Rep,
typename Period>
930 bool WaitFor(
const std::chrono::duration<Rep, Period>& timeout);
932 template <
typename Clk,
typename Duration>
933 bool WaitUntil(
const std::chrono::time_point<Clk, Duration>& timeout);
956 template <
typename T>
971 template <
typename T>
972 void CreateDataPoint(
const DataPointPath& path,
const T& initial_value);
974 void CreateDataPoint(
const DataPointPath& path,
const char* initial_value);
985 void DeleteDataPoint(
const DataPointPath& path,
bool recurse =
false);
1000 const std::type_info& GetDataPointType(
const DataPointPath& path)
const;
1088 std::pair<PathList, PathList>
1089 GetChildren(
const DataPointPath& path,
bool recurse =
false)
const;
1105 template <
typename T>
1122 template <
typename T>
1123 void SetDataPoint(
const DataPointPath& path,
const T& value);
1125 void SetDataPoint(
const DataPointPath& path,
const char* value);
1142 template <
typename T>
1143 void ReadDataPoint(
const DataPointPath& path, T& buffer)
const;
1163 template <
typename T>
1164 void WriteDataPoint(
const DataPointPath& path,
const T& buffer);
1166 void WriteDataPoint(
const DataPointPath& path,
const char* buffer);
1168 template <
typename... T>
1169 void WriteDataPoints(
const T&... args);
1171 template <
typename... T>
1172 void ReadDataPoints(T&... args)
const;
1181 static const std::type_info& StringToType(
const std::string& arg);
1190 static std::string TypeToString(
const std::type_info& arg);
1225 const std::type_info& type,
1226 const std::function<
void()>& callback)
1227 :
m_path(path), m_buffer(buffer), m_type(&type), m_callback(callback) {
1251 const std::type_info* m_type;
1254 std::function<void()> m_callback;
1257 template <
typename T>
1259 template <
typename T,
typename F>
1269 std::vector<Parameters> m_params;
1298 const std::type_info& type,
1299 const std::function<
void()>& callback)
1300 :
m_path(path), m_buffer(buffer), m_type(&type), m_callback(callback) {
1321 const void* m_buffer;
1324 const std::type_info* m_type;
1327 std::function<void()> m_callback;
1330 template <
typename T>
1332 template <
typename T,
typename F>
1333 void Add(
const DataPointPath& path,
const T& buffer, F handler);
1342 std::vector<Parameters> m_params;
1356 explicit Response(std::future<void>&& future)
noexcept;
1385 bool Wait(
const std::chrono::microseconds& timeout);
1391 std::future<void> m_future;
1425 virtual void CreateDataPoint(
const DataPointPath& path,
const std::type_info& type);
1436 virtual void DeleteDataPointLegacy(
const DataPointPath& path);
1449 virtual const std::type_info& GetDataPointTypeLegacy(
const DataPointPath& path)
const;
1470 virtual size_t GetDataPointSizeLegacy(
const DataPointPath& path)
const;
1481 virtual bool DataPointExistsLegacy(
const DataPointPath& path)
const;
1504 virtual std::pair<PathList, PathList> GetChildrenLegacy(
const DataPointPath& path)
const;
The BufferTooSmall is thrown when an API call fails because the provided buffer is not big enough to ...
Definition exceptions.hpp:264
BufferTooSmall(const std::size_t actual, const std::size_t expected)
Construct exception object.
Definition exceptions.cpp:159
This class provides a wrapper for a data point path.
Definition dataPointPath.hpp:74
A buffer class representing 2D matrix data.
Definition matrixBuffer.hpp:28
Definition repositoryIf.hpp:144
An object representing one or more asynchronous I/O requests to a repository.
Definition repositoryIf.hpp:683
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.
void PartialWriteDataPoint(const DataPointPath &path, const T &&buffer, size_t first, size_t last, size_t d_first, std::optional< std::reference_wrapper< const MetaData > > metadata=std::nullopt, const CallbackType &callback=nullptr)=delete
Writing to a datapoint from an rvalue reference is not allowed.
RequestList m_requests
Definition repositoryIf.hpp:917
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.
virtual ~BatchRequest()=default
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 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 WriteDataPoint(const DataPointPath &path, const T &&buffer, std::optional< std::reference_wrapper< const MetaData > > metadata=std::nullopt, const CallbackType &callback=nullptr)=delete
Writing to a datapoint from an rvalue reference is not allowed.
void ReadMetaData(const DataPointPath &path, MetaData &&metadata, const CallbackType &callback=nullptr) const =delete
Reading metadata into an rvalue reference is not allowed.
friend RepositoryIf
Definition repositoryIf.hpp:916
Definition repositoryIf.hpp:920
std::vector< std::future< void > > ResponseList
Definition repositoryIf.hpp:922
ResponseList m_responses
Definition repositoryIf.hpp:936
Definition repositoryIf.hpp:139
Definition repositoryIf.hpp:135
Definition repositoryIf.hpp:131
Definition repositoryIf.hpp:127
Definition repositoryIf.hpp:152
Status
Definition repositoryIf.hpp:154
Definition repositoryIf.hpp:148
A structure to hold the arguments passed with one of the Add methods.
Definition repositoryIf.hpp:1212
const DataPointPath & GetPath() const
Definition repositoryIf.hpp:1230
const std::function< void()> & GetCallback() const
Definition repositoryIf.hpp:1239
Parameters(const DataPointPath &path, void *buffer, const std::type_info &type, const std::function< void()> &callback)
Allows to explicitly construct a complete parameters structure.
Definition repositoryIf.hpp:1223
const std::type_info & GetType() const
Definition repositoryIf.hpp:1236
void * GetBuffer() const
Definition repositoryIf.hpp:1233
A request object to pass information about datapoints that should be read from the repository.
Definition repositoryIf.hpp:1206
std::vector< Parameters > & GetParams()
Definition repositoryIf.hpp:1264
const std::vector< Parameters > & GetParams() const
Definition repositoryIf.hpp:1261
An object used to wait for a request to complete.
Definition repositoryIf.hpp:1354
Definition repositoryIf.hpp:119
Definition repositoryIf.hpp:123
A structure to hold the arguments passed with one of the Add methods.
Definition repositoryIf.hpp:1285
const void * GetBuffer() const
Definition repositoryIf.hpp:1306
const std::type_info & GetType() const
Definition repositoryIf.hpp:1309
const DataPointPath & GetPath() const
Definition repositoryIf.hpp:1303
const std::function< void()> & GetCallback() const
Definition repositoryIf.hpp:1312
Parameters(const DataPointPath &path, const void *buffer, const std::type_info &type, const std::function< void()> &callback)
Allows to explicitly construct a complete parameters structure.
Definition repositoryIf.hpp:1296
A request object to pass information about datapoints that should be written to the repository.
Definition repositoryIf.hpp:1279
std::vector< Parameters > & GetParams()
Definition repositoryIf.hpp:1337
const std::vector< Parameters > & GetParams() const
Definition repositoryIf.hpp:1334
Abstract interface providing basic read and write facilities to a repository.
Definition repositoryIf.hpp:104
virtual BatchResponse ProcessRequests(const RequestList &requests)=0
Clock::time_point Timestamp
Definition repositoryIf.hpp:111
taiclock::TaiClock Clock
Definition repositoryIf.hpp:110
std::vector< std::any > RequestList
Definition repositoryIf.hpp:106
std::vector< DataPointPath > PathList
Definition repositoryIf.hpp:109
std::function< void(const DataPointPath &)> CallbackType
Signature of the callback functions that can be registered with the repository requests.
Definition repositoryIf.hpp:114
virtual ~RepositoryIf()=default
The RtctkException class is the base class for all Rtctk exceptions.
Definition exceptions.hpp:211
The UnsupportedTypeException is thrown whenever an attempt is made to use an unsupported type in the ...
Definition exceptions.hpp:239
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
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:22
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:129
bool operator==(const DataPointPath &lhs, const char *rhs) noexcept
Definition dataPointPath.hpp:358
Definition commandReplier.cpp:22
uint64_t RtcUInt64
Definition repositoryIf.hpp:61
uint8_t RtcUInt8
Definition repositoryIf.hpp:58
int64_t RtcInt64
Definition repositoryIf.hpp:57
float RtcFloat
Definition repositoryIf.hpp:62
RtcVector< RtcUInt32 > RtcVectorUInt32
Definition repositoryIf.hpp:73
RtcVector< RtcDouble > RtcVectorDouble
Definition repositoryIf.hpp:76
std::string RtcString
Definition repositoryIf.hpp:64
int8_t RtcInt8
Definition repositoryIf.hpp:54
std::vector< T > RtcVector
Definition repositoryIf.hpp:45
uint32_t RtcUInt32
Definition repositoryIf.hpp:60
bool RtcBool
Definition repositoryIf.hpp:53
int16_t RtcInt16
Definition repositoryIf.hpp:55
RtcVector< RtcUInt16 > RtcVectorUInt16
Definition repositoryIf.hpp:72
RtcVector< RtcInt16 > RtcVectorInt16
Definition repositoryIf.hpp:68
RtcVector< RtcFloat > RtcVectorFloat
Definition repositoryIf.hpp:75
RtcVector< RtcInt8 > RtcVectorInt8
Definition repositoryIf.hpp:67
uint16_t RtcUInt16
Definition repositoryIf.hpp:59
RtcVector< RtcBool > RtcVectorBool
Definition repositoryIf.hpp:66
int32_t RtcInt32
Definition repositoryIf.hpp:56
RtcVector< RtcUInt64 > RtcVectorUInt64
Definition repositoryIf.hpp:74
RtcVector< RtcString > RtcVectorString
Definition repositoryIf.hpp:77
RtcVector< RtcInt32 > RtcVectorInt32
Definition repositoryIf.hpp:69
std::vector< std::byte > RtcBinary
Definition repositoryIf.hpp:65
RtcVector< RtcUInt8 > RtcVectorUInt8
Definition repositoryIf.hpp:71
RtcVector< RtcInt64 > RtcVectorInt64
Definition repositoryIf.hpp:70
double RtcDouble
Definition repositoryIf.hpp:63
rtctk::componentFramework::RepositoryIf::Response Response
Definition oldbAdapterLegacy.cpp:54
DataPointPath m_path
Definition populateConfig.cpp:165
Implementation file for RepositoryIf template methods and related classes.
Definition repositoryIf.hpp:156
Status status
Definition repositoryIf.hpp:157
std::exception_ptr exception
Definition repositoryIf.hpp:158