mirror of
https://github.com/matrix-construct/construct
synced 2024-12-26 07:23:53 +01:00
ircd::json: Add vector utility methods to interface.
This commit is contained in:
parent
3f85eb761a
commit
9ac64fcff7
2 changed files with 64 additions and 20 deletions
|
@ -14,6 +14,10 @@
|
|||
namespace ircd::json
|
||||
{
|
||||
struct vector;
|
||||
|
||||
bool empty(const json::vector &);
|
||||
size_t size(const json::vector &);
|
||||
bool operator!(const json::vector &);
|
||||
}
|
||||
|
||||
/// Interface for non-standard, non-delimited concatenations of objects
|
||||
|
@ -43,12 +47,14 @@ struct ircd::json::vector
|
|||
const_iterator begin() const;
|
||||
|
||||
const_iterator find(size_t i) const;
|
||||
size_t count() const;
|
||||
size_t size() const;
|
||||
|
||||
value_type at(const size_t &i) const;
|
||||
value_type operator[](const size_t &i) const;
|
||||
|
||||
bool empty() const;
|
||||
operator bool() const;
|
||||
size_t count() const;
|
||||
size_t size() const;
|
||||
|
||||
using string_view::string_view;
|
||||
};
|
||||
|
||||
|
|
72
ircd/json.cc
72
ircd/json.cc
|
@ -1858,6 +1858,61 @@ const
|
|||
// json/vector.h
|
||||
//
|
||||
|
||||
bool
|
||||
ircd::json::operator!(const vector &v)
|
||||
{
|
||||
return v.empty();
|
||||
}
|
||||
|
||||
size_t
|
||||
ircd::json::size(const vector &v)
|
||||
{
|
||||
return v.size();
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::json::empty(const vector &v)
|
||||
{
|
||||
return v.empty();
|
||||
}
|
||||
|
||||
//
|
||||
// vector::vector
|
||||
//
|
||||
|
||||
size_t
|
||||
ircd::json::vector::size()
|
||||
const
|
||||
{
|
||||
return count();
|
||||
}
|
||||
|
||||
size_t
|
||||
ircd::json::vector::count()
|
||||
const
|
||||
{
|
||||
return std::distance(begin(), end());
|
||||
}
|
||||
|
||||
ircd::json::vector::operator
|
||||
bool()
|
||||
const
|
||||
{
|
||||
return !empty();
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::json::vector::empty()
|
||||
const
|
||||
{
|
||||
const string_view &sv
|
||||
{
|
||||
*static_cast<const string_view *>(this)
|
||||
};
|
||||
|
||||
return sv.empty();
|
||||
}
|
||||
|
||||
ircd::json::vector::value_type
|
||||
ircd::json::vector::operator[](const size_t &i)
|
||||
const
|
||||
|
@ -1888,23 +1943,6 @@ const
|
|||
for(; it != end() && i; ++it, i--);
|
||||
return it;
|
||||
}
|
||||
|
||||
__attribute__((warning("Taking string_view::size() not the count() of vector elements")))
|
||||
size_t
|
||||
ircd::json::vector::size()
|
||||
const
|
||||
{
|
||||
return count();
|
||||
}
|
||||
|
||||
size_t
|
||||
ircd::json::vector::count()
|
||||
const
|
||||
{
|
||||
return std::distance(begin(), end());
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// vector::const_iterator
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue