mirror of
https://github.com/matrix-construct/construct
synced 2024-12-26 15:33:54 +01:00
ircd::stats: Additional arithmetic/access operators on item.
This commit is contained in:
parent
688340a8a2
commit
1bf17da6d1
2 changed files with 53 additions and 0 deletions
|
@ -27,6 +27,8 @@ namespace ircd::stats
|
|||
value_type &inc(item &, const value_type & = 1);
|
||||
value_type &dec(item &, const value_type & = 1);
|
||||
value_type &set(item &, const value_type & = 0);
|
||||
|
||||
std::ostream &operator<<(std::ostream &, const item &);
|
||||
}
|
||||
|
||||
struct ircd::stats::item
|
||||
|
@ -39,9 +41,15 @@ struct ircd::stats::item
|
|||
value_type val;
|
||||
|
||||
public:
|
||||
explicit operator const value_type &() const;
|
||||
explicit operator value_type &();
|
||||
bool operator!() const;
|
||||
|
||||
item &operator+=(const value_type &) &;
|
||||
item &operator-=(const value_type &) &;
|
||||
item &operator=(const value_type &) &;
|
||||
item &operator++();
|
||||
item &operator--();
|
||||
|
||||
item(const json::members &);
|
||||
item(item &&) = delete;
|
||||
|
@ -49,6 +57,20 @@ struct ircd::stats::item
|
|||
~item() noexcept;
|
||||
};
|
||||
|
||||
inline ircd::stats::item &
|
||||
ircd::stats::item::operator--()
|
||||
{
|
||||
--val;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline ircd::stats::item &
|
||||
ircd::stats::item::operator++()
|
||||
{
|
||||
++val;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline ircd::stats::item &
|
||||
ircd::stats::item::operator=(const value_type &v)
|
||||
&
|
||||
|
@ -73,6 +95,26 @@ ircd::stats::item::operator+=(const value_type &v)
|
|||
return *this;
|
||||
}
|
||||
|
||||
inline bool
|
||||
ircd::stats::item::operator!()
|
||||
const
|
||||
{
|
||||
return !val;
|
||||
}
|
||||
|
||||
inline ircd::stats::item::operator
|
||||
value_type &()
|
||||
{
|
||||
return val;
|
||||
}
|
||||
|
||||
inline ircd::stats::item::operator
|
||||
const value_type &()
|
||||
const
|
||||
{
|
||||
return val;
|
||||
}
|
||||
|
||||
inline ircd::stats::value_type &
|
||||
ircd::stats::set(item &item,
|
||||
const value_type &v)
|
||||
|
|
|
@ -12,6 +12,13 @@ decltype(ircd::stats::items)
|
|||
ircd::stats::items
|
||||
{};
|
||||
|
||||
std::ostream &
|
||||
ircd::stats::operator<<(std::ostream &s, const item &item)
|
||||
{
|
||||
s << static_cast<long long>(item.val);
|
||||
return s;
|
||||
}
|
||||
|
||||
//
|
||||
// item
|
||||
//
|
||||
|
@ -22,6 +29,10 @@ ircd::stats::item::NAME_MAX_LEN
|
|||
127
|
||||
};
|
||||
|
||||
//
|
||||
// item::item
|
||||
//
|
||||
|
||||
ircd::stats::item::item(const json::members &opts)
|
||||
:feature_
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue