| 173 | |
| 174 | // Static methods to encapsulate access to the atomic's |
| 175 | class iterator |
| 176 | { |
| 177 | public: |
| 178 | using iterator_category = std::input_iterator_tag; |
| 179 | using value_type = std::tuple<std::string_view, int64_t>; |
| 180 | using difference_type = ptrdiff_t; |
| 181 | using pointer = value_type *; |
| 182 | using reference = value_type &; |
| 183 | |
| 184 | iterator(const Metrics &m, IdType pos) : _metrics(m), _it(pos) {} |
| 185 | |
| 186 | iterator & |
| 187 | operator++() |
| 188 | { |
| 189 | next(); |
| 190 | |
| 191 | return *this; |
| 192 | } |
| 193 | |
| 194 | iterator |
| 195 | operator++(int) |
| 196 | { |
| 197 | iterator result = *this; |
| 198 | |
| 199 | next(); |
| 200 | |
| 201 | return result; |
| 202 | } |
| 203 | |
| 204 | value_type |
| 205 | operator*() const |
| 206 | { |
| 207 | std::string_view name; |
| 208 | auto metric = _metrics.lookup(_it, &name); |
| 209 | |
| 210 | return std::make_tuple(name, metric->_value.load()); |
| 211 | } |
| 212 | |
| 213 | bool |
| 214 | operator==(const iterator &o) const |
| 215 | { |
| 216 | return _it == o._it && std::addressof(_metrics) == std::addressof(o._metrics); |
| 217 | } |
| 218 | |
| 219 | bool |
| 220 | operator!=(const iterator &o) const |
| 221 | { |
| 222 | return _it != o._it || std::addressof(_metrics) != std::addressof(o._metrics); |
| 223 | } |
| 224 | |
| 225 | private: |
| 226 | void next(); |
| 227 | |
| 228 | const Metrics &_metrics; |
| 229 | Metrics::IdType _it; |
| 230 | }; |
| 231 | |
| 232 | iterator |