From 9ac64fcff7af29deb938dfbe75f3ed9d04bbe1cc Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 27 Feb 2019 11:23:52 -0800 Subject: [PATCH] ircd::json: Add vector utility methods to interface. --- include/ircd/json/vector.h | 12 +++++-- ircd/json.cc | 72 +++++++++++++++++++++++++++++--------- 2 files changed, 64 insertions(+), 20 deletions(-) diff --git a/include/ircd/json/vector.h b/include/ircd/json/vector.h index 18bf52381..6566af94b 100644 --- a/include/ircd/json/vector.h +++ b/include/ircd/json/vector.h @@ -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; }; diff --git a/ircd/json.cc b/ircd/json.cc index e6d19d320..d96e55a23 100644 --- a/ircd/json.cc +++ b/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(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 //