85 Writer(Writer&& other) =
delete;
86 Writer(
const Writer&) =
delete;
87 Writer& operator=(Writer&&) =
delete;
88 Writer& operator=(
const Writer&) =
delete;
93 [[nodiscard]] Writer
operator[](std::string_view path) &;
96 [[nodiscard]] Writer
operator[](std::string_view path) &&;
102 if constexpr (std::is_arithmetic_v<T> || std::is_same_v<std::decay_t<T>,
Rate> ||
103 std::is_same_v<std::decay_t<T>, HistogramView> || std::is_same_v<std::decay_t<T>, MetricValue>)
110 "Cast the metric to an arithmetic type or provide a "
111 "`void DumpMetric(utils::statistics::Writer& writer, "
112 "const Metric& value)` function for the `Metric` type"
114 DumpMetric(*
this, value);
122 auto new_writer = MakeChild();
123 new_writer.AppendLabelsSpan(labels);
130 ValueWithLabels(value, LabelsSpan{il});
136 ValueWithLabels(value, LabelsSpan{&label, &label + 1});
142 template <
class Func>
143 void WithLabels(
utils::impl::InternalTag, LabelsSpan labels, Func func) {
144 auto new_writer = MakeChild();
145 new_writer.AppendLabelsSpan(labels);
149 template <
class Func>
150 void WithLabels(
utils::impl::InternalTag, std::initializer_list<LabelView> il, Func func) {
151 WithLabels(
utils::impl::InternalTag{}, LabelsSpan{il}, func);
154 template <
class Func>
155 void WithLabels(
utils::impl::InternalTag,
const LabelView& label, Func func) {
156 WithLabels(
utils::impl::InternalTag{}, LabelsSpan{&label, &label + 1}, func);
163 explicit operator bool()
const noexcept {
return !!state_; }
166 explicit Writer(impl::WriterState* state)
noexcept;
167 explicit Writer(impl::WriterState& state, LabelsSpan labels);
171 using ULongLong =
unsigned long long;
173 using PathSizeType = std::uint16_t;
174 using LabelsSizeType = std::uint8_t;
176 void Write(
unsigned long long value);
177 void Write(
long long value);
178 void Write(
double value);
179 void Write(
Rate value);
180 void Write(HistogramView value);
181 void Write(MetricValue value);
183 void Write(
float value) { Write(
static_cast<
double>(value)); }
185 void Write(
unsigned long value) { Write(
static_cast<ULongLong>(value)); }
186 void Write(
long value) { Write(
static_cast<
long long>(value)); }
187 void Write(
unsigned int value) { Write(
static_cast<
long long>(value)); }
188 void Write(
int value) { Write(
static_cast<
long long>(value)); }
189 void Write(
unsigned short value) { Write(
static_cast<
long long>(value)); }
190 void Write(
short value) { Write(
static_cast<
long long>(value)); }
195 Writer(Writer& other, MoveTag)
noexcept;
197 Writer MoveOut()
noexcept {
return Writer{*
this, MoveTag{}}; }
199 void ResetState()
noexcept;
200 void ValidateUsage();
202 void AppendPath(std::string_view path);
203 void AppendLabelsSpan(LabelsSpan labels);
205 impl::WriterState* state_;
206 const PathSizeType initial_path_size_;
207 PathSizeType current_path_size_;
208 const LabelsSizeType initial_labels_size_;
209 LabelsSizeType current_labels_size_;
213void DumpMetric(Writer& writer,
const std::atomic<Metric>& m) {