mirror of
https://github.com/matrix-construct/construct
synced 2024-11-15 22:41:12 +01:00
ircd::json: Inline vector::const_iterator related.
This commit is contained in:
parent
d870385e6c
commit
648d6e42b4
3 changed files with 114 additions and 92 deletions
|
@ -58,50 +58,11 @@ struct ircd::json::vector
|
||||||
using string_view::string_view;
|
using string_view::string_view;
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace ircd::json
|
#include "vector_iterator.h"
|
||||||
|
|
||||||
|
inline ircd::json::vector::const_iterator
|
||||||
|
ircd::json::vector::end()
|
||||||
|
const
|
||||||
{
|
{
|
||||||
bool operator==(const vector::const_iterator &, const vector::const_iterator &);
|
return { string_view::end(), string_view::end() };
|
||||||
bool operator!=(const vector::const_iterator &, const vector::const_iterator &);
|
|
||||||
bool operator<=(const vector::const_iterator &, const vector::const_iterator &);
|
|
||||||
bool operator>=(const vector::const_iterator &, const vector::const_iterator &);
|
|
||||||
bool operator<(const vector::const_iterator &, const vector::const_iterator &);
|
|
||||||
bool operator>(const vector::const_iterator &, const vector::const_iterator &);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ircd::json::vector::const_iterator
|
|
||||||
{
|
|
||||||
using value_type = const object;
|
|
||||||
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 vector;
|
|
||||||
|
|
||||||
const char *start {nullptr};
|
|
||||||
const char *stop {nullptr};
|
|
||||||
object 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 &);
|
|
||||||
};
|
|
||||||
|
|
108
include/ircd/json/vector_iterator.h
Normal file
108
include/ircd/json/vector_iterator.h
Normal file
|
@ -0,0 +1,108 @@
|
||||||
|
// Matrix Construct
|
||||||
|
//
|
||||||
|
// Copyright (C) Matrix 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_VECTOR_ITERATOR_H
|
||||||
|
|
||||||
|
namespace ircd::json
|
||||||
|
{
|
||||||
|
bool operator==(const vector::const_iterator &, const vector::const_iterator &);
|
||||||
|
bool operator!=(const vector::const_iterator &, const vector::const_iterator &);
|
||||||
|
bool operator<=(const vector::const_iterator &, const vector::const_iterator &);
|
||||||
|
bool operator>=(const vector::const_iterator &, const vector::const_iterator &);
|
||||||
|
bool operator<(const vector::const_iterator &, const vector::const_iterator &);
|
||||||
|
bool operator>(const vector::const_iterator &, const vector::const_iterator &);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ircd::json::vector::const_iterator
|
||||||
|
{
|
||||||
|
friend class vector;
|
||||||
|
|
||||||
|
using value_type = const object;
|
||||||
|
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};
|
||||||
|
object 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::vector::const_iterator::value_type &
|
||||||
|
ircd::json::vector::const_iterator::operator*()
|
||||||
|
const
|
||||||
|
{
|
||||||
|
return *operator->();
|
||||||
|
}
|
||||||
|
|
||||||
|
inline ircd::json::vector::const_iterator::value_type *
|
||||||
|
ircd::json::vector::const_iterator::operator->()
|
||||||
|
const
|
||||||
|
{
|
||||||
|
return &state;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool
|
||||||
|
ircd::json::operator==(const vector::const_iterator &a,
|
||||||
|
const vector::const_iterator &b)
|
||||||
|
{
|
||||||
|
return a.start == b.start && a.state == b.state;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool
|
||||||
|
ircd::json::operator!=(const vector::const_iterator &a,
|
||||||
|
const vector::const_iterator &b)
|
||||||
|
{
|
||||||
|
return a.start != b.start || a.state != b.state;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool
|
||||||
|
ircd::json::operator<=(const vector::const_iterator &a,
|
||||||
|
const vector::const_iterator &b)
|
||||||
|
{
|
||||||
|
return a.start <= b.start && a.state == b.state;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool
|
||||||
|
ircd::json::operator>=(const vector::const_iterator &a,
|
||||||
|
const vector::const_iterator &b)
|
||||||
|
{
|
||||||
|
return a.start >= b.start && a.state == b.state;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool
|
||||||
|
ircd::json::operator<(const vector::const_iterator &a,
|
||||||
|
const vector::const_iterator &b)
|
||||||
|
{
|
||||||
|
return a.start < b.start && a.state == b.state;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool
|
||||||
|
ircd::json::operator>(const vector::const_iterator &a,
|
||||||
|
const vector::const_iterator &b)
|
||||||
|
{
|
||||||
|
return a.start > b.start && a.state == b.state;
|
||||||
|
}
|
47
ircd/json.cc
47
ircd/json.cc
|
@ -2393,53 +2393,6 @@ catch(const qi::expectation_failure<const char *> &e)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
ircd::json::vector::const_iterator
|
|
||||||
ircd::json::vector::end()
|
|
||||||
const
|
|
||||||
{
|
|
||||||
return { string_view::end(), string_view::end() };
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// vector::const_iterator
|
|
||||||
//
|
|
||||||
|
|
||||||
bool
|
|
||||||
ircd::json::operator==(const vector::const_iterator &a, const vector::const_iterator &b)
|
|
||||||
{
|
|
||||||
return a.state == b.state;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
ircd::json::operator!=(const vector::const_iterator &a, const vector::const_iterator &b)
|
|
||||||
{
|
|
||||||
return a.state != b.state;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
ircd::json::operator<=(const vector::const_iterator &a, const vector::const_iterator &b)
|
|
||||||
{
|
|
||||||
return a.state <= b.state;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
ircd::json::operator>=(const vector::const_iterator &a, const vector::const_iterator &b)
|
|
||||||
{
|
|
||||||
return a.state >= b.state;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
ircd::json::operator<(const vector::const_iterator &a, const vector::const_iterator &b)
|
|
||||||
{
|
|
||||||
return a.state < b.state;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
ircd::json::operator>(const vector::const_iterator &a, const vector::const_iterator &b)
|
|
||||||
{
|
|
||||||
return a.state > b.state;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// vector::const_iterator::const_iterator
|
// vector::const_iterator::const_iterator
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in a new issue