|
Astarte device API for C++ 0.8.1
Astarte device SDK for C++
|
Represents a single Astarte data value. More...
#include <data.hpp>
Public Member Functions | |
| template<DataAllowedType T> | |
| Data (const T &value) | |
Constructs a Data object from a value of any DataAllowedType. | |
| template<DataAllowedType T> | |
| auto | into () const -> std::conditional_t< std::is_same_v< T, std::string_view >, std::string_view, const T & > |
Converts the Astarte data class to the specified type T. | |
| template<DataAllowedType T> | |
| auto | try_into () const -> std::optional< T > |
Attempts to convert the Astarte data class to the specified type T safely. | |
| auto | get_type () const -> Type |
| Gets the type of the data contained in this class instance. | |
| auto | get_raw_data () const -> const std::variant< int32_t, int64_t, double, bool, std::string, std::vector< uint8_t >, std::chrono::system_clock::time_point, std::vector< int32_t >, std::vector< int64_t >, std::vector< double >, std::vector< bool >, std::vector< std::string >, std::vector< std::vector< uint8_t > >, std::vector< std::chrono::system_clock::time_point > > & |
| Returns the raw data variant contained in this class instance. | |
| auto | operator== (const Data &other) const -> bool |
| Overloader for the comparison operator ==. | |
| auto | operator!= (const Data &other) const -> bool |
| Overloader for the comparison operator !=. | |
Represents a single Astarte data value.
The Data class acts as a versatile container for all data types supported by the Astarte platform. It abstracts away the underlying C++ types, providing a unified interface for handling data sent to and received from Astarte.
It uses std::variant internally to store different types, ensuring type safety while offering flexibility. The DataAllowedType concept restricts which C++ types can be stored, mapping them to Astarte's data model.
|
inlineexplicit |
Constructs a Data object from a value of any DataAllowedType.
The constructor implicitly copies the provided value into the internal storage. This ensures that the Data object manages its own data lifetime independently of the input value.
| T | The type of the value, must satisfy DataAllowedType. |
| [in] | value | The content to initialize the Astarte data instance with. |
|
nodiscard |
Returns the raw data variant contained in this class instance.
|
nodiscard |
Gets the type of the data contained in this class instance.
|
inlinenodiscard |
Converts the Astarte data class to the specified type T.
This method performs a direct extraction of the stored value using std::get<T>. It is the caller's responsibility to ensure that the Data object currently holds a value of type T.
| T | The target type to convert to, must satisfy DataAllowedType. |
| std::bad_variant_access | If the Data object does not contain a T. |
|
nodiscard |
Overloader for the comparison operator !=.
| [in] | other | The object to compare to. |
|
nodiscard |
Overloader for the comparison operator ==.
| [in] | other | The object to compare to. |
|
inlinenodiscard |
Attempts to convert the Astarte data class to the specified type T safely.
This method attempts to extract the stored value as type T. If the Data object currently holds a value of type T, an std::optional containing that value is returned.
| T | The target type to convert to, must satisfy DataAllowedType. |