0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 15:33:54 +01:00

ircd::json: Add vector utility methods to interface.

This commit is contained in:
Jason Volk 2019-02-27 11:23:52 -08:00
parent 3f85eb761a
commit 9ac64fcff7
2 changed files with 64 additions and 20 deletions

View file

@ -14,6 +14,10 @@
namespace ircd::json namespace ircd::json
{ {
struct vector; 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 /// Interface for non-standard, non-delimited concatenations of objects
@ -43,12 +47,14 @@ struct ircd::json::vector
const_iterator begin() const; const_iterator begin() const;
const_iterator find(size_t i) 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 at(const size_t &i) const;
value_type operator[](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; using string_view::string_view;
}; };

View file

@ -1858,6 +1858,61 @@ const
// json/vector.h // 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::value_type
ircd::json::vector::operator[](const size_t &i) ircd::json::vector::operator[](const size_t &i)
const const
@ -1888,23 +1943,6 @@ const
for(; it != end() && i; ++it, i--); for(; it != end() && i; ++it, i--);
return it; 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 // vector::const_iterator
// //