Astarte device API for C++ 0.8.1
Astarte device SDK for C++
Loading...
Searching...
No Matches
property.hpp
Go to the documentation of this file.
1// (C) Copyright 2025, SECO Mind Srl
2//
3// SPDX-License-Identifier: Apache-2.0
4
5#ifndef ASTARTE_DEVICE_SDK_PROPERTY_H
6#define ASTARTE_DEVICE_SDK_PROPERTY_H
7
12
13#include <optional>
14#include <ostream>
15
18
19namespace astarte::device {
20
23 public:
29 explicit PropertyIndividual(const std::optional<Data>& data);
30
36 [[nodiscard]] auto get_value() const -> const std::optional<Data>&;
37
44 [[nodiscard]] auto operator==(const PropertyIndividual& other) const -> bool;
45
52 [[nodiscard]] auto operator!=(const PropertyIndividual& other) const -> bool;
53
54 private:
55 std::optional<Data> data_;
56};
57
58} // namespace astarte::device
59
61template <>
69 template <typename ParseContext>
70 constexpr auto parse(ParseContext& ctx) const {
71 return ctx.begin();
72 }
73
81 template <typename FormatContext>
82 auto format(const astarte::device::PropertyIndividual& data, FormatContext& ctx) const {
83 const auto& opt_data = data.get_value();
84 if (opt_data.has_value()) {
85 return astarte_fmt::format_to(ctx.out(), "{}", opt_data.value());
86 }
87
88 return ctx.out();
89 }
90};
91
99inline auto operator<<(std::ostream& out, const astarte::device::PropertyIndividual& data)
100 -> std::ostream& {
101 out << astarte_fmt::format("{}", data);
102 return out;
103}
104
105#endif // ASTARTE_DEVICE_SDK_PROPERTY_H
Represents a single Astarte data value.
Definition data.hpp:61
Representing the Astarte individual property data.
Definition property.hpp:22
auto get_value() const -> const std::optional< Data > &
Gets the value contained within the object.
PropertyIndividual(const std::optional< Data > &data)
Constructor for the PropertyIndividual class.
Astarte data class and its related methods.
auto operator<<(std::ostream &out, const astarte::device::Data &data) -> std::ostream &
Stream insertion operator for Data.
Definition data.hpp:243
Data formatting utilities for Astarte types.
Umbrella namespace for the Astarte device library.
Definition data.hpp:29
Namespace alias for the formatting library (std or fmt).
Definition formatter.hpp:45
Global namespace for all Astarte related functionality.
Definition data.hpp:29
auto format(const astarte::device::PropertyIndividual &data, FormatContext &ctx) const
Formats the PropertyIndividual object.
Definition property.hpp:82
constexpr auto parse(ParseContext &ctx) const
Parses the format string. Default implementation.
Definition property.hpp:70
Base formatter struct declaration for Doxygen.
Definition formatter.hpp:48