Flow 2.0.0
Flow project: Full implementation reference.
stat_set.cpp
Go to the documentation of this file.
1/* Flow
2 * Copyright 2023 Akamai Technologies, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the
5 * "License"); you may not use this file except in
6 * compliance with the License. You may obtain a copy
7 * of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in
12 * writing, software distributed under the License is
13 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14 * CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing
16 * permissions and limitations under the License. */
17
18/// @file
19
21#include "flow/cfg/cfg_fwd.hpp"
22#include <ostream>
23#include <string>
24
25namespace flow::util::stat
26{
27
28// Stat_name implementations.
29
31 m_base(nullptr),
32 m_fragment(fragment),
33 m_fragment_kind(Fragment_kind::S_LITERAL)
34{
35 // Yep.
36}
37
38Stat_name::Stat_name(const char* fragment) :
39 Stat_name(String_view{fragment})
40{
41 // Yep.
42}
43
44Stat_name::Stat_name(const Stat_name& base, String_view fragment, Fragment_kind fragment_kind) :
45 m_base(&base),
46 m_fragment(fragment),
47 m_fragment_kind(fragment_kind)
48{
49 // Yep.
50}
51
52void Stat_name::append_to(std::string* target) const
53{
54 // Keep in-sync with to_ostream().
55 if (m_base)
56 {
57 m_base->append_to(target); // Root first: each fragment is appended once, in order.
58 }
59
61 {
63 }
64 else
65 {
66 *target += m_fragment;
67 }
68}
69
70void Stat_name::to_ostream(std::ostream& os) const
71{
72 // Keep in-sync with append_to().
73 if (m_base)
74 {
75 m_base->to_ostream(os); // Root first: each fragment is written once, in order.
76 }
77
79 {
81 }
82 else
83 {
84 os << m_fragment;
85 }
86}
87
88std::string Stat_name::str() const
89{
90 std::string name;
91 append_to(&name);
92 return name;
93}
94
95} // namespace flow::util::stat
Specialized class that (at a light weight) represents a printable Stat_set-member name,...
Definition: stat_set.hpp:239
Stat_name(String_view fragment={})
Constructs a Stat_name that represents only a name fragment with no reference to another Stat_name.
Definition: stat_set.cpp:30
void to_ostream(std::ostream &os) const
On-demand evaluation: os << this->str() but faster.
Definition: stat_set.cpp:70
const String_view m_fragment
Second part, if any, of the concatenation in str(), interpreted according to m_fragment_kind.
Definition: stat_set.hpp:323
std::string str() const
On-demand evaluation: Returns the full name – all fragments, from the root on, each rendered per its ...
Definition: stat_set.cpp:88
const Fragment_kind m_fragment_kind
How to render m_fragment.
Definition: stat_set.hpp:326
void append_to(std::string *target) const
On-demand evaluation: *target += this->str() but faster.
Definition: stat_set.cpp:52
const Stat_name *const m_base
First part, if any, of the concatenation in str().
Definition: stat_set.hpp:320
Fragment_kind
How a fragment of text is rendered into the name.
Definition: stat_set.hpp:245
@ S_MEMBER_ID
The fragment is a data member identifier (e.g., m_msg_count or m_rcv.m_n_transmitted) and is rendered...
std::string value_set_member_id_to_opt_name(util::String_view member_id, char sep_replacement='-')
Utility, used by FLOW_CFG_OPTION_SET_DECLARE_OPTION() internally but made available as a public API i...
Definition: option_set.cpp:41
Sub-module of flow::util providing lightweight facilities for working with simple structs of stat cou...
Definition: histo.cpp:26
Basic_string_view< char > String_view
Commonly used char-based Basic_string_view. See its doc header.