mirror of
https://github.com/matrix-construct/construct
synced 2024-12-26 07:23:53 +01:00
ircd::json: Inline object::const_iterator comparison suite.
ircd::json: Split object::const_iterator from object header. ircd::json: Split object::member related from object header.
This commit is contained in:
parent
17628cbc44
commit
c4d041d1ae
4 changed files with 205 additions and 152 deletions
|
@ -108,79 +108,8 @@ struct ircd::json::object
|
|||
using string_view::string_view;
|
||||
};
|
||||
|
||||
namespace ircd::json
|
||||
{
|
||||
bool operator==(const object::member &, const object::member &);
|
||||
bool operator!=(const object::member &, const object::member &);
|
||||
bool operator<=(const object::member &, const object::member &);
|
||||
bool operator>=(const object::member &, const object::member &);
|
||||
bool operator<(const object::member &, const object::member &);
|
||||
bool operator>(const object::member &, const object::member &);
|
||||
|
||||
bool sorted(const object::member *const &, const object::member *const &);
|
||||
size_t serialized(const object::member *const &, const object::member *const &);
|
||||
size_t serialized(const object::member &);
|
||||
string_view stringify(mutable_buffer &, const object::member *const &, const object::member *const &);
|
||||
string_view stringify(mutable_buffer &, const object::member &);
|
||||
std::ostream &operator<<(std::ostream &, const object::member &);
|
||||
}
|
||||
|
||||
struct ircd::json::object::member
|
||||
:std::pair<string_view, string_view>
|
||||
{
|
||||
member(const string_view &first = {}, const string_view &second = {})
|
||||
:std::pair<string_view, string_view>{first, second}
|
||||
{}
|
||||
};
|
||||
|
||||
namespace ircd::json
|
||||
{
|
||||
bool operator==(const object::const_iterator &, const object::const_iterator &);
|
||||
bool operator!=(const object::const_iterator &, const object::const_iterator &);
|
||||
bool operator<=(const object::const_iterator &, const object::const_iterator &);
|
||||
bool operator>=(const object::const_iterator &, const object::const_iterator &);
|
||||
bool operator<(const object::const_iterator &, const object::const_iterator &);
|
||||
bool operator>(const object::const_iterator &, const object::const_iterator &);
|
||||
}
|
||||
|
||||
struct ircd::json::object::const_iterator
|
||||
{
|
||||
friend class object;
|
||||
|
||||
using key_type = string_view;
|
||||
using mapped_type = string_view;
|
||||
using value_type = const member;
|
||||
using pointer = value_type *;
|
||||
using reference = value_type &;
|
||||
using size_type = size_t;
|
||||
using difference_type = size_t;
|
||||
using key_compare = std::less<value_type>;
|
||||
using iterator_category = std::forward_iterator_tag;
|
||||
|
||||
const char *start {nullptr};
|
||||
const char *stop {nullptr};
|
||||
member 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;
|
||||
};
|
||||
#include "object_member.h"
|
||||
#include "object_iterator.h"
|
||||
|
||||
template<ircd::json::name_hash_t key,
|
||||
class T>
|
||||
|
@ -287,3 +216,10 @@ catch(const bad_lex_cast &e)
|
|||
{
|
||||
return def;
|
||||
}
|
||||
|
||||
inline ircd::json::object::const_iterator
|
||||
ircd::json::object::end()
|
||||
const
|
||||
{
|
||||
return { string_view::end(), string_view::end() };
|
||||
}
|
||||
|
|
110
include/ircd/json/object_iterator.h
Normal file
110
include/ircd/json/object_iterator.h
Normal file
|
@ -0,0 +1,110 @@
|
|||
// The Construct
|
||||
//
|
||||
// Copyright (C) The Construct Developers, Authors & Contributors
|
||||
// Copyright (C) 2016-2020 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_OBJECT_ITERATOR_H
|
||||
|
||||
namespace ircd::json
|
||||
{
|
||||
bool operator==(const object::const_iterator &, const object::const_iterator &);
|
||||
bool operator!=(const object::const_iterator &, const object::const_iterator &);
|
||||
bool operator<=(const object::const_iterator &, const object::const_iterator &);
|
||||
bool operator>=(const object::const_iterator &, const object::const_iterator &);
|
||||
bool operator<(const object::const_iterator &, const object::const_iterator &);
|
||||
bool operator>(const object::const_iterator &, const object::const_iterator &);
|
||||
}
|
||||
|
||||
struct ircd::json::object::const_iterator
|
||||
{
|
||||
friend class object;
|
||||
|
||||
using key_type = string_view;
|
||||
using mapped_type = string_view;
|
||||
using value_type = const member;
|
||||
using pointer = value_type *;
|
||||
using reference = value_type &;
|
||||
using size_type = size_t;
|
||||
using difference_type = size_t;
|
||||
using key_compare = std::less<value_type>;
|
||||
using iterator_category = std::forward_iterator_tag;
|
||||
|
||||
const char *start {nullptr};
|
||||
const char *stop {nullptr};
|
||||
member 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::object::const_iterator::value_type &
|
||||
ircd::json::object::const_iterator::operator*()
|
||||
const
|
||||
{
|
||||
return *operator->();
|
||||
}
|
||||
|
||||
inline ircd::json::object::const_iterator::value_type *
|
||||
ircd::json::object::const_iterator::operator->()
|
||||
const
|
||||
{
|
||||
return &state;
|
||||
}
|
||||
|
||||
inline bool
|
||||
ircd::json::operator==(const object::const_iterator &a,
|
||||
const object::const_iterator &b)
|
||||
{
|
||||
return a.start == b.start;
|
||||
}
|
||||
|
||||
inline bool
|
||||
ircd::json::operator!=(const object::const_iterator &a,
|
||||
const object::const_iterator &b)
|
||||
{
|
||||
return a.start != b.start;
|
||||
}
|
||||
|
||||
inline bool
|
||||
ircd::json::operator<=(const object::const_iterator &a,
|
||||
const object::const_iterator &b)
|
||||
{
|
||||
return a.start <= b.start;
|
||||
}
|
||||
|
||||
inline bool
|
||||
ircd::json::operator>=(const object::const_iterator &a,
|
||||
const object::const_iterator &b)
|
||||
{
|
||||
return a.start >= b.start;
|
||||
}
|
||||
|
||||
inline bool
|
||||
ircd::json::operator<(const object::const_iterator &a,
|
||||
const object::const_iterator &b)
|
||||
{
|
||||
return a.start < b.start;
|
||||
}
|
||||
|
||||
inline bool
|
||||
ircd::json::operator>(const object::const_iterator &a,
|
||||
const object::const_iterator &b)
|
||||
{
|
||||
return a.start > b.start;
|
||||
}
|
86
include/ircd/json/object_member.h
Normal file
86
include/ircd/json/object_member.h
Normal file
|
@ -0,0 +1,86 @@
|
|||
// The Construct
|
||||
//
|
||||
// Copyright (C) The Construct Developers, Authors & Contributors
|
||||
// Copyright (C) 2016-2020 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_OBJECT_MEMBER_H
|
||||
|
||||
namespace ircd::json
|
||||
{
|
||||
bool operator==(const object::member &, const object::member &);
|
||||
bool operator!=(const object::member &, const object::member &);
|
||||
bool operator<=(const object::member &, const object::member &);
|
||||
bool operator>=(const object::member &, const object::member &);
|
||||
bool operator<(const object::member &, const object::member &);
|
||||
bool operator>(const object::member &, const object::member &);
|
||||
|
||||
bool sorted(const object::member *const &, const object::member *const &);
|
||||
size_t serialized(const object::member *const &, const object::member *const &);
|
||||
size_t serialized(const object::member &);
|
||||
string_view stringify(mutable_buffer &, const object::member *const &, const object::member *const &);
|
||||
string_view stringify(mutable_buffer &, const object::member &);
|
||||
std::ostream &operator<<(std::ostream &, const object::member &);
|
||||
}
|
||||
|
||||
struct ircd::json::object::member
|
||||
:std::pair<string_view, string_view>
|
||||
{
|
||||
member(const string_view &first = {}, const string_view &second = {});
|
||||
};
|
||||
|
||||
inline
|
||||
ircd::json::object::member::member(const string_view &first,
|
||||
const string_view &second)
|
||||
:std::pair<string_view, string_view>
|
||||
{
|
||||
first, second
|
||||
}
|
||||
{}
|
||||
|
||||
inline bool
|
||||
ircd::json::operator==(const object::member &a,
|
||||
const object::member &b)
|
||||
{
|
||||
return a.first == b.first;
|
||||
}
|
||||
|
||||
inline bool
|
||||
ircd::json::operator!=(const object::member &a,
|
||||
const object::member &b)
|
||||
{
|
||||
return a.first != b.first;
|
||||
}
|
||||
|
||||
inline bool
|
||||
ircd::json::operator<=(const object::member &a,
|
||||
const object::member &b)
|
||||
{
|
||||
return a.first <= b.first;
|
||||
}
|
||||
|
||||
inline bool
|
||||
ircd::json::operator>=(const object::member &a,
|
||||
const object::member &b)
|
||||
{
|
||||
return a.first >= b.first;
|
||||
}
|
||||
|
||||
inline bool
|
||||
ircd::json::operator<(const object::member &a,
|
||||
const object::member &b)
|
||||
{
|
||||
return a.first < b.first;
|
||||
}
|
||||
|
||||
inline bool
|
||||
ircd::json::operator>(const object::member &a,
|
||||
const object::member &b)
|
||||
{
|
||||
return a.first > b.first;
|
||||
}
|
79
ircd/json.cc
79
ircd/json.cc
|
@ -2679,53 +2679,10 @@ catch(const qi::expectation_failure<const char *> &e)
|
|||
};
|
||||
}
|
||||
|
||||
ircd::json::object::const_iterator
|
||||
ircd::json::object::end()
|
||||
const
|
||||
{
|
||||
return { string_view::end(), string_view::end() };
|
||||
}
|
||||
|
||||
//
|
||||
// object::const_iterator
|
||||
//
|
||||
|
||||
bool
|
||||
ircd::json::operator==(const object::const_iterator &a, const object::const_iterator &b)
|
||||
{
|
||||
return a.start == b.start;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::json::operator!=(const object::const_iterator &a, const object::const_iterator &b)
|
||||
{
|
||||
return a.start != b.start;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::json::operator<=(const object::const_iterator &a, const object::const_iterator &b)
|
||||
{
|
||||
return a.start <= b.start;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::json::operator>=(const object::const_iterator &a, const object::const_iterator &b)
|
||||
{
|
||||
return a.start >= b.start;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::json::operator<(const object::const_iterator &a, const object::const_iterator &b)
|
||||
{
|
||||
return a.start < b.start;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::json::operator>(const object::const_iterator &a, const object::const_iterator &b)
|
||||
{
|
||||
return a.start > b.start;
|
||||
}
|
||||
|
||||
ircd::json::object::const_iterator &
|
||||
ircd::json::object::const_iterator::operator++()
|
||||
try
|
||||
|
@ -2845,42 +2802,6 @@ ircd::json::sorted(const object::member *const &begin,
|
|||
});
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::json::operator==(const object::member &a, const object::member &b)
|
||||
{
|
||||
return a.first == b.first;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::json::operator!=(const object::member &a, const object::member &b)
|
||||
{
|
||||
return a.first != b.first;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::json::operator<=(const object::member &a, const object::member &b)
|
||||
{
|
||||
return a.first <= b.first;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::json::operator>=(const object::member &a, const object::member &b)
|
||||
{
|
||||
return a.first >= b.first;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::json::operator<(const object::member &a, const object::member &b)
|
||||
{
|
||||
return a.first < b.first;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::json::operator>(const object::member &a, const object::member &b)
|
||||
{
|
||||
return a.first > b.first;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// json/array.h
|
||||
|
|
Loading…
Reference in a new issue