28 noexcept ->
decltype(DumpMetric(std::declval<Writer&>(), std::declval<
const Metric&>()), std::true_type{}) {
98 Writer(Writer&& other) =
delete;
99 Writer(
const Writer&) =
delete;
100 Writer& operator=(Writer&&) =
delete;
101 Writer& operator=(
const Writer&) =
delete;
106 [[nodiscard]] Writer
operator[](std::string_view path) &;
109 [[nodiscard]] Writer
operator[](std::string_view path) &&;
115 if constexpr (std::is_arithmetic_v<T> || std::is_same_v<std::decay_t<T>,
Rate> ||
116 std::is_same_v<std::decay_t<T>, HistogramView> || std::is_same_v<std::decay_t<T>, MetricValue>)
122 kHasWriterSupport<T>,
123 "Cast the metric to an arithmetic type or provide a "
124 "`void DumpMetric(utils::statistics::Writer& writer, "
125 "const Metric& value)` function for the `Metric` type"
127 DumpMetric(*
this, value);
135 auto new_writer = MakeChild();
136 new_writer.AppendLabelsSpan(labels);
143 ValueWithLabels(value, LabelsSpan{il});
149 ValueWithLabels(value, LabelsSpan{&label, &label + 1});
155 template <
class Func>
156 void WithLabels(utils::
impl::InternalTag, LabelsSpan labels, Func func) {
157 auto new_writer = MakeChild();
158 new_writer.AppendLabelsSpan(labels);
162 template <
class Func>
163 void WithLabels(utils::
impl::InternalTag, std::initializer_list<LabelView> il, Func func) {
164 WithLabels(utils::
impl::InternalTag{}, LabelsSpan{il}, func);
167 template <
class Func>
168 void WithLabels(utils::
impl::InternalTag,
const LabelView& label, Func func) {
169 WithLabels(utils::
impl::InternalTag{}, LabelsSpan{&label, &label + 1}, func);
176 explicit operator bool()
const noexcept {
return !!state_; }
179 explicit Writer(impl::WriterState* state)
noexcept;
180 explicit Writer(impl::WriterState& state, LabelsSpan labels);
184 using ULongLong =
unsigned long long;
186 using PathSizeType = std::uint16_t;
187 using LabelsSizeType = std::uint8_t;
189 void Write(
unsigned long long value);
190 void Write(
long long value);
191 void Write(
double value);
192 void Write(
Rate value);
193 void Write(HistogramView value);
194 void Write(MetricValue value);
196 void Write(
float value) { Write(
static_cast<
double>(value)); }
198 void Write(
unsigned long value) { Write(
static_cast<ULongLong>(value)); }
199 void Write(
long value) { Write(
static_cast<
long long>(value)); }
200 void Write(
unsigned int value) { Write(
static_cast<
long long>(value)); }
201 void Write(
int value) { Write(
static_cast<
long long>(value)); }
202 void Write(
unsigned short value) { Write(
static_cast<
long long>(value)); }
203 void Write(
short value) { Write(
static_cast<
long long>(value)); }
208 Writer(Writer& other, MoveTag)
noexcept;
210 Writer MoveOut()
noexcept {
return Writer{*
this, MoveTag{}}; }
212 void ResetState()
noexcept;
213 void ValidateUsage();
215 void AppendPath(std::string_view path);
216 void AppendLabelsSpan(LabelsSpan labels);
218 impl::WriterState* state_;
219 const PathSizeType initial_path_size_;
220 PathSizeType current_path_size_;
221 const LabelsSizeType initial_labels_size_;
222 LabelsSizeType current_labels_size_;
226void DumpMetric(Writer& writer,
const std::atomic<Metric>& m) {