87 Writer(Writer&& other) =
delete;
88 Writer(
const Writer&) =
delete;
89 Writer& operator=(Writer&&) =
delete;
90 Writer& operator=(
const Writer&) =
delete;
95 [[nodiscard]] Writer
operator[](std::string_view path) &;
98 [[nodiscard]] Writer
operator[](std::string_view path) &&;
104 if constexpr (std::is_arithmetic_v<T> || std::is_same_v<std::decay_t<T>,
Rate> ||
105 std::is_same_v<std::decay_t<T>, HistogramView> || std::is_same_v<std::decay_t<T>, MetricValue>)
112 "Cast the metric to an arithmetic type or provide a "
113 "`void DumpMetric(utils::statistics::Writer& writer, "
114 "const Metric& value)` function for the `Metric` type"
116 DumpMetric(*
this, value);
124 auto new_writer = MakeChild();
125 new_writer.AppendLabelsSpan(labels);
132 ValueWithLabels(value, LabelsSpan{il});
138 ValueWithLabels(value, LabelsSpan{&label, &label + 1});
144 template <
class Func>
145 void WithLabels(
utils::impl::InternalTag, LabelsSpan labels, Func func) {
146 auto new_writer = MakeChild();
147 new_writer.AppendLabelsSpan(labels);
151 template <
class Func>
152 void WithLabels(
utils::impl::InternalTag, std::initializer_list<LabelView> il, Func func) {
153 WithLabels(
utils::impl::InternalTag{}, LabelsSpan{il}, func);
156 template <
class Func>
157 void WithLabels(
utils::impl::InternalTag,
const LabelView& label, Func func) {
158 WithLabels(
utils::impl::InternalTag{}, LabelsSpan{&label, &label + 1}, func);
165 explicit operator bool()
const noexcept {
return !!state_; }
168 explicit Writer(impl::WriterState* state)
noexcept;
169 explicit Writer(impl::WriterState& state, LabelsSpan labels);
173 using ULongLong =
unsigned long long;
175 using PathSizeType = std::uint16_t;
176 using LabelsSizeType = std::uint8_t;
178 void Write(
unsigned long long value);
179 void Write(
long long value);
180 void Write(
double value);
181 void Write(
Rate value);
182 void Write(HistogramView value);
183 void Write(MetricValue value);
185 void Write(
float value) { Write(
static_cast<
double>(value)); }
187 void Write(
unsigned long value) { Write(
static_cast<ULongLong>(value)); }
188 void Write(
long value) { Write(
static_cast<
long long>(value)); }
189 void Write(
unsigned int value) { Write(
static_cast<
long long>(value)); }
190 void Write(
int value) { Write(
static_cast<
long long>(value)); }
191 void Write(
unsigned short value) { Write(
static_cast<
long long>(value)); }
192 void Write(
short value) { Write(
static_cast<
long long>(value)); }
197 Writer(Writer& other, MoveTag)
noexcept;
199 Writer MoveOut()
noexcept {
return Writer{*
this, MoveTag{}}; }
201 void ResetState()
noexcept;
202 void ValidateUsage();
204 void AppendPath(std::string_view path);
205 void AppendLabelsSpan(LabelsSpan labels);
207 impl::WriterState* state_;
208 const PathSizeType initial_path_size_;
209 PathSizeType current_path_size_;
210 const LabelsSizeType initial_labels_size_;
211 LabelsSizeType current_labels_size_;
218void DumpMetric(Writer& writer,
const std::atomic<Metric>& m) {