0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 07:23:53 +01:00

ircd::json: Split array::const_iterator from array header; inline comparison suite.

This commit is contained in:
Jason Volk 2020-04-03 10:53:01 -07:00
parent c4d041d1ae
commit a7d9476a05
3 changed files with 116 additions and 91 deletions

View file

@ -73,53 +73,7 @@ struct ircd::json::array
template<class it> static string_view stringify(mutable_buffer &, const it &b, const it &e);
};
namespace ircd::json
{
bool operator==(const array::const_iterator &, const array::const_iterator &);
bool operator!=(const array::const_iterator &, const array::const_iterator &);
bool operator<=(const array::const_iterator &, const array::const_iterator &);
bool operator>=(const array::const_iterator &, const array::const_iterator &);
bool operator<(const array::const_iterator &, const array::const_iterator &);
bool operator>(const array::const_iterator &, const array::const_iterator &);
}
struct ircd::json::array::const_iterator
{
using value_type = const string_view;
using pointer = value_type *;
using reference = value_type &;
using iterator = const_iterator;
using size_type = size_t;
using difference_type = ptrdiff_t;
using iterator_category = std::forward_iterator_tag;
protected:
friend class array;
const char *start {nullptr};
const char *stop {nullptr};
string_view state;
const_iterator(const char *const &start, const char *const &stop)
:start{start}
,stop{stop}
{}
public:
value_type *operator->() const { return &state; }
value_type &operator*() const { return *operator->(); }
const_iterator &operator++();
const_iterator() = default;
friend bool operator==(const const_iterator &, const const_iterator &);
friend bool operator!=(const const_iterator &, const const_iterator &);
friend bool operator<=(const const_iterator &, const const_iterator &);
friend bool operator>=(const const_iterator &, const const_iterator &);
friend bool operator<(const const_iterator &, const const_iterator &);
friend bool operator>(const const_iterator &, const const_iterator &);
};
#include "array_iterator.h"
template<class T>
T
@ -135,3 +89,10 @@ catch(const bad_lex_cast &e)
"indice %zu must cast to type %s", i, typeid(T).name()
};
}
inline ircd::json::array::const_iterator
ircd::json::array::end()
const
{
return { string_view::end(), string_view::end() };
}

View file

@ -0,0 +1,108 @@
// The Construct
//
// Copyright (C) The Construct Developers, Authors & Contributors
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
#pragma once
#define HAVE_IRCD_JSON_ARRAY_ITERATOR_H
namespace ircd::json
{
bool operator==(const array::const_iterator &, const array::const_iterator &);
bool operator!=(const array::const_iterator &, const array::const_iterator &);
bool operator<=(const array::const_iterator &, const array::const_iterator &);
bool operator>=(const array::const_iterator &, const array::const_iterator &);
bool operator<(const array::const_iterator &, const array::const_iterator &);
bool operator>(const array::const_iterator &, const array::const_iterator &);
}
struct ircd::json::array::const_iterator
{
friend class array;
using value_type = const string_view;
using pointer = value_type *;
using reference = value_type &;
using iterator = const_iterator;
using size_type = size_t;
using difference_type = ptrdiff_t;
using iterator_category = std::forward_iterator_tag;
const char *start {nullptr};
const char *stop {nullptr};
string_view state;
const_iterator(const char *const &start, const char *const &stop)
:start{start}
,stop{stop}
{}
public:
value_type *operator->() const;
value_type &operator*() const;
const_iterator &operator++();
const_iterator() = default;
};
inline ircd::json::array::const_iterator::value_type &
ircd::json::array::const_iterator::operator*()
const
{
return *operator->();
}
inline ircd::json::array::const_iterator::value_type *
ircd::json::array::const_iterator::operator->()
const
{
return &state;
}
inline bool
ircd::json::operator==(const array::const_iterator &a,
const array::const_iterator &b)
{
return a.start == b.start;
}
inline bool
ircd::json::operator!=(const array::const_iterator &a,
const array::const_iterator &b)
{
return a.start != b.start;
}
inline bool
ircd::json::operator<=(const array::const_iterator &a,
const array::const_iterator &b)
{
return a.start <= b.start;
}
inline bool
ircd::json::operator>=(const array::const_iterator &a,
const array::const_iterator &b)
{
return a.start >= b.start;
}
inline bool
ircd::json::operator<(const array::const_iterator &a,
const array::const_iterator &b)
{
return a.start < b.start;
}
inline bool
ircd::json::operator>(const array::const_iterator &a,
const array::const_iterator &b)
{
return a.start > b.start;
}

View file

@ -2982,14 +2982,6 @@ catch(const qi::expectation_failure<const char *> &e)
};
}
ircd::json::array::const_iterator
ircd::json::array::end()
const
{
return { string_view::end(), string_view::end() };
}
ircd::string_view
ircd::json::array::operator[](const size_t &i)
const
@ -3085,42 +3077,6 @@ catch(const qi::expectation_failure<const char *> &e)
};
}
bool
ircd::json::operator==(const array::const_iterator &a, const array::const_iterator &b)
{
return a.start == b.start;
}
bool
ircd::json::operator!=(const array::const_iterator &a, const array::const_iterator &b)
{
return a.start != b.start;
}
bool
ircd::json::operator<=(const array::const_iterator &a, const array::const_iterator &b)
{
return a.start <= b.start;
}
bool
ircd::json::operator>=(const array::const_iterator &a, const array::const_iterator &b)
{
return a.start >= b.start;
}
bool
ircd::json::operator<(const array::const_iterator &a, const array::const_iterator &b)
{
return a.start < b.start;
}
bool
ircd::json::operator>(const array::const_iterator &a, const array::const_iterator &b)
{
return a.start > b.start;
}
///////////////////////////////////////////////////////////////////////////////
//
// json/member.h