2022-07-20 12:38:07 +02:00
|
|
|
// __ _____ _____ _____
|
|
|
|
// __| | __| | | | JSON for Modern C++
|
2023-11-28 22:36:31 +01:00
|
|
|
// | | |__ | | | | | | version 3.11.3
|
2022-07-20 12:38:07 +02:00
|
|
|
// |_____|_____|_____|_|___| https://github.com/nlohmann/json
|
|
|
|
//
|
2023-11-26 15:51:19 +01:00
|
|
|
// SPDX-FileCopyrightText: 2013-2023 Niels Lohmann <https://nlohmann.me>
|
2022-07-20 12:38:07 +02:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2018-01-10 10:18:31 +01:00
|
|
|
#pragma once
|
2017-08-14 17:10:32 +02:00
|
|
|
|
2017-08-14 19:28:01 +02:00
|
|
|
#include <cstddef> // ptrdiff_t
|
|
|
|
#include <limits> // numeric_limits
|
2017-08-14 17:10:32 +02:00
|
|
|
|
2020-12-26 17:56:16 +01:00
|
|
|
#include <nlohmann/detail/macro_scope.hpp>
|
|
|
|
|
2022-07-30 21:59:13 +02:00
|
|
|
NLOHMANN_JSON_NAMESPACE_BEGIN
|
2017-08-14 17:10:32 +02:00
|
|
|
namespace detail
|
|
|
|
{
|
2022-07-30 21:59:13 +02:00
|
|
|
|
2017-08-14 17:10:32 +02:00
|
|
|
/*
|
|
|
|
@brief an iterator for primitive JSON types
|
|
|
|
|
|
|
|
This class models an iterator for primitive JSON types (boolean, number,
|
|
|
|
string). It's only purpose is to allow the iterator/const_iterator classes
|
|
|
|
to "iterate" over primitive values. Internally, the iterator is modeled by
|
|
|
|
a `difference_type` variable. Value begin_value (`0`) models the begin,
|
|
|
|
end_value (`1`) models past the end.
|
|
|
|
*/
|
|
|
|
class primitive_iterator_t
|
|
|
|
{
|
2018-01-16 20:41:04 +01:00
|
|
|
private:
|
2017-08-14 17:10:32 +02:00
|
|
|
using difference_type = std::ptrdiff_t;
|
2018-01-16 20:41:04 +01:00
|
|
|
static constexpr difference_type begin_value = 0;
|
|
|
|
static constexpr difference_type end_value = begin_value + 1;
|
2017-08-14 17:10:32 +02:00
|
|
|
|
2020-08-12 13:30:06 +02:00
|
|
|
JSON_PRIVATE_UNLESS_TESTED:
|
2018-01-16 20:41:04 +01:00
|
|
|
/// iterator as signed integer type
|
|
|
|
difference_type m_it = (std::numeric_limits<std::ptrdiff_t>::min)();
|
|
|
|
|
|
|
|
public:
|
2017-08-14 17:10:32 +02:00
|
|
|
constexpr difference_type get_value() const noexcept
|
|
|
|
{
|
|
|
|
return m_it;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// set iterator to a defined beginning
|
|
|
|
void set_begin() noexcept
|
|
|
|
{
|
|
|
|
m_it = begin_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// set iterator to a defined past the end
|
|
|
|
void set_end() noexcept
|
|
|
|
{
|
|
|
|
m_it = end_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// return whether the iterator can be dereferenced
|
|
|
|
constexpr bool is_begin() const noexcept
|
|
|
|
{
|
|
|
|
return m_it == begin_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// return whether the iterator is at end
|
|
|
|
constexpr bool is_end() const noexcept
|
|
|
|
{
|
|
|
|
return m_it == end_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend constexpr bool operator==(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
|
|
|
|
{
|
|
|
|
return lhs.m_it == rhs.m_it;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend constexpr bool operator<(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
|
|
|
|
{
|
|
|
|
return lhs.m_it < rhs.m_it;
|
|
|
|
}
|
|
|
|
|
2018-01-16 20:41:04 +01:00
|
|
|
primitive_iterator_t operator+(difference_type n) noexcept
|
2017-08-14 17:10:32 +02:00
|
|
|
{
|
|
|
|
auto result = *this;
|
2018-01-16 20:41:04 +01:00
|
|
|
result += n;
|
2017-08-14 17:10:32 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend constexpr difference_type operator-(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept
|
|
|
|
{
|
|
|
|
return lhs.m_it - rhs.m_it;
|
|
|
|
}
|
|
|
|
|
2018-01-16 20:41:04 +01:00
|
|
|
primitive_iterator_t& operator++() noexcept
|
2017-08-14 17:10:32 +02:00
|
|
|
{
|
|
|
|
++m_it;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2022-03-08 10:10:50 +01:00
|
|
|
primitive_iterator_t operator++(int)& noexcept // NOLINT(cert-dcl21-cpp)
|
2017-08-14 17:10:32 +02:00
|
|
|
{
|
|
|
|
auto result = *this;
|
2018-06-23 10:47:55 +02:00
|
|
|
++m_it;
|
2017-08-14 17:10:32 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-01-16 20:41:04 +01:00
|
|
|
primitive_iterator_t& operator--() noexcept
|
2017-08-14 17:10:32 +02:00
|
|
|
{
|
|
|
|
--m_it;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2022-03-08 10:10:50 +01:00
|
|
|
primitive_iterator_t operator--(int)& noexcept // NOLINT(cert-dcl21-cpp)
|
2017-08-14 17:10:32 +02:00
|
|
|
{
|
|
|
|
auto result = *this;
|
2018-06-23 10:47:55 +02:00
|
|
|
--m_it;
|
2017-08-14 17:10:32 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-01-16 20:41:04 +01:00
|
|
|
primitive_iterator_t& operator+=(difference_type n) noexcept
|
2017-08-14 17:10:32 +02:00
|
|
|
{
|
|
|
|
m_it += n;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2018-01-16 20:41:04 +01:00
|
|
|
primitive_iterator_t& operator-=(difference_type n) noexcept
|
2017-08-14 17:10:32 +02:00
|
|
|
{
|
|
|
|
m_it -= n;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
};
|
2022-07-30 21:59:13 +02:00
|
|
|
|
2018-10-07 18:39:18 +02:00
|
|
|
} // namespace detail
|
2022-07-30 21:59:13 +02:00
|
|
|
NLOHMANN_JSON_NAMESPACE_END
|