some cleanup

This commit is contained in:
Niels 2015-07-19 12:41:46 +02:00
parent 818ae5a524
commit 623c03bc49
4 changed files with 549 additions and 905 deletions

View file

@ -57,6 +57,7 @@ Though it's 2015 already, the support for C++11 is still a bit sparse. Currently
- GCC 4.9 - GCC 4.9
- GCC 5.0 - GCC 5.0
- GCC 5.1 - GCC 5.1
- GCC 5.2
- Clang 3.4 - Clang 3.4
- Clang 3.5 - Clang 3.5
- Clang 3.6 - Clang 3.6

View file

@ -37,7 +37,7 @@ OPTIMIZE_FOR_FORTRAN = NO
OPTIMIZE_OUTPUT_VHDL = NO OPTIMIZE_OUTPUT_VHDL = NO
EXTENSION_MAPPING = EXTENSION_MAPPING =
MARKDOWN_SUPPORT = YES MARKDOWN_SUPPORT = YES
AUTOLINK_SUPPORT = YES AUTOLINK_SUPPORT = NO
BUILTIN_STL_SUPPORT = YES BUILTIN_STL_SUPPORT = YES
CPP_CLI_SUPPORT = NO CPP_CLI_SUPPORT = NO
SIP_SUPPORT = NO SIP_SUPPORT = NO
@ -95,7 +95,7 @@ QUIET = YES
WARNINGS = YES WARNINGS = YES
WARN_IF_UNDOCUMENTED = YES WARN_IF_UNDOCUMENTED = YES
WARN_IF_DOC_ERROR = YES WARN_IF_DOC_ERROR = YES
WARN_NO_PARAMDOC = NO WARN_NO_PARAMDOC = YES
WARN_FORMAT = "$file:$line: $text" WARN_FORMAT = "$file:$line: $text"
WARN_LOGFILE = WARN_LOGFILE =
#--------------------------------------------------------------------------- #---------------------------------------------------------------------------
@ -108,7 +108,7 @@ RECURSIVE = NO
EXCLUDE = EXCLUDE =
EXCLUDE_SYMLINKS = NO EXCLUDE_SYMLINKS = NO
EXCLUDE_PATTERNS = EXCLUDE_PATTERNS =
EXCLUDE_SYMBOLS = nlohmann::internals EXCLUDE_SYMBOLS = nlohmann::anonymous_namespace
EXAMPLE_PATH = examples EXAMPLE_PATH = examples
EXAMPLE_PATTERNS = EXAMPLE_PATTERNS =
EXAMPLE_RECURSIVE = NO EXAMPLE_RECURSIVE = NO
@ -151,7 +151,7 @@ HTML_COLORSTYLE_HUE = 220
HTML_COLORSTYLE_SAT = 100 HTML_COLORSTYLE_SAT = 100
HTML_COLORSTYLE_GAMMA = 80 HTML_COLORSTYLE_GAMMA = 80
HTML_TIMESTAMP = YES HTML_TIMESTAMP = YES
HTML_DYNAMIC_SECTIONS = NO HTML_DYNAMIC_SECTIONS = YES
HTML_INDEX_NUM_ENTRIES = 100 HTML_INDEX_NUM_ENTRIES = 100
GENERATE_DOCSET = YES GENERATE_DOCSET = YES
DOCSET_FEEDNAME = "Doxygen generated docs" DOCSET_FEEDNAME = "Doxygen generated docs"

File diff suppressed because it is too large Load diff

View file

@ -103,24 +103,47 @@ default)
@requirement The class satisfies the following concept requirements: @requirement The class satisfies the following concept requirements:
- Basic - Basic
- [DefaultConstructible](http://en.cppreference.com/w/cpp/concept/DefaultConstructible) - [DefaultConstructible](http://en.cppreference.com/w/cpp/concept/DefaultConstructible):
- [MoveConstructible](http://en.cppreference.com/w/cpp/concept/MoveConstructible) JSON values can be default constructed. The result will be a JSON null value.
- [CopyConstructible](http://en.cppreference.com/w/cpp/concept/CopyConstructible) - [MoveConstructible](http://en.cppreference.com/w/cpp/concept/MoveConstructible):
- [MoveAssignable](http://en.cppreference.com/w/cpp/concept/MoveAssignable) A JSON value can be constructed from an rvalue argument.
- [CopyAssignable](http://en.cppreference.com/w/cpp/concept/CopyAssignable) - [CopyConstructible](http://en.cppreference.com/w/cpp/concept/CopyConstructible):
- [Destructible](http://en.cppreference.com/w/cpp/concept/Destructible) A JSON value can be copy-constrcuted from an lvalue expression.
- [MoveAssignable](http://en.cppreference.com/w/cpp/concept/MoveAssignable):
A JSON value van be assigned from an rvalue argument.
- [CopyAssignable](http://en.cppreference.com/w/cpp/concept/CopyAssignable):
A JSON value can be copy-assigned from an lvalue expression.
- [Destructible](http://en.cppreference.com/w/cpp/concept/Destructible):
JSON values can be destructed.
- Layout - Layout
- [StandardLayoutType](http://en.cppreference.com/w/cpp/concept/StandardLayoutType) - [StandardLayoutType](http://en.cppreference.com/w/cpp/concept/StandardLayoutType):
JSON values have
[standard layout](http://en.cppreference.com/w/cpp/language/data_members#Standard_layout):
All non-static data members are private and standard layout types, the class
has no virtual functions or (virtual) base classes.
- Library-wide - Library-wide
- [EqualityComparable](http://en.cppreference.com/w/cpp/concept/EqualityComparable) - [EqualityComparable](http://en.cppreference.com/w/cpp/concept/EqualityComparable):
- [LessThanComparable](http://en.cppreference.com/w/cpp/concept/LessThanComparable) JSON values can be compared with `==`, see @ref
- [Swappable](http://en.cppreference.com/w/cpp/concept/Swappable) operator==(const_reference,const_reference).
- [NullablePointer](http://en.cppreference.com/w/cpp/concept/NullablePointer) - [LessThanComparable](http://en.cppreference.com/w/cpp/concept/LessThanComparable):
JSON values can be compared with `<`, see @ref
operator<(const_reference,const_reference).
- [Swappable](http://en.cppreference.com/w/cpp/concept/Swappable):
Any JSON lvalue or rvalue of can be swapped with any lvalue or rvalue of
other compatible types, using unqualified function call @ref swap().
- [NullablePointer](http://en.cppreference.com/w/cpp/concept/NullablePointer):
JSON values can be compared against `std::nullptr_t` objects which are used
to model the `null` value.
- Container - Container
- [Container](http://en.cppreference.com/w/cpp/concept/Container) - [Container](http://en.cppreference.com/w/cpp/concept/Container):
- [ReversibleContainer](http://en.cppreference.com/w/cpp/concept/ReversibleContainer) JSON values can be used like STL containers and provide iterator access.
- [ReversibleContainer](http://en.cppreference.com/w/cpp/concept/ReversibleContainer);
JSON values can be used like STL containers and provide reverse iterator
access.
@internal
@note ObjectType trick from http://stackoverflow.com/a/9860911 @note ObjectType trick from http://stackoverflow.com/a/9860911
@endinternal
@see RFC 7159 <http://rfc7159.net/rfc7159> @see RFC 7159 <http://rfc7159.net/rfc7159>
*/ */
@ -137,8 +160,13 @@ class basic_json
{ {
private: private:
/// workaround type for MSVC /// workaround type for MSVC
using basic_json_t = using basic_json_t = basic_json<ObjectType,
basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberFloatType, AllocatorType>; ArrayType,
StringType,
BooleanType,
NumberIntegerType,
NumberFloatType,
AllocatorType>;
public: public:
@ -269,8 +297,11 @@ class basic_json
@sa array_t @sa array_t
*/ */
using object_t = using object_t = ObjectType<StringType,
ObjectType<StringType, basic_json, std::less<StringType>, AllocatorType<std::pair<const StringType, basic_json>>>; basic_json,
std::less<StringType>,
AllocatorType<std::pair<const StringType,
basic_json>>>;
/*! /*!
@brief a type for an array @brief a type for an array
@ -526,7 +557,7 @@ class basic_json
boolean, ///< boolean value boolean, ///< boolean value
number_integer, ///< number value (integer) number_integer, ///< number value (integer)
number_float, ///< number value (floating-point) number_float, ///< number value (floating-point)
discarded ///< (internal) indicates the parser callback chose not to keep the value discarded ///< discarded by the the parser callback function
}; };
@ -767,7 +798,6 @@ class basic_json
value.,basic_json} value.,basic_json}
@sa basic_json(std::nullptr_t) @sa basic_json(std::nullptr_t)
@ingroup container
*/ */
basic_json() noexcept = default; basic_json() noexcept = default;
@ -1503,9 +1533,7 @@ class basic_json
@throw std::bad_alloc if allocation for object, array, or string fails. @throw std::bad_alloc if allocation for object, array, or string fails.
@liveexample{The following code shows an example for the copy @liveexample{The following code shows an example for the copy
constructor.,basic_jsonbasic_json_t} constructor.,basic_json__basic_json}
@ingroup container
*/ */
basic_json(const basic_json& other) basic_json(const basic_json& other)
: m_type(other.m_type) : m_type(other.m_type)
@ -1599,8 +1627,6 @@ class basic_json
creates a copy of value `a` which is then swapped with `b`. Finally\, the creates a copy of value `a` which is then swapped with `b`. Finally\, the
copy of `a` (which is the null value after the swap) is copy of `a` (which is the null value after the swap) is
destroyed.,basic_json__copyassignment} destroyed.,basic_json__copyassignment}
@ingroup container
*/ */
reference& operator=(basic_json other) noexcept ( reference& operator=(basic_json other) noexcept (
std::is_nothrow_move_constructible<value_t>::value and std::is_nothrow_move_constructible<value_t>::value and
@ -1625,8 +1651,6 @@ class basic_json
@requirement This function satisfies the Container requirements: @requirement This function satisfies the Container requirements:
- The complexity is linear. - The complexity is linear.
- All stored elements are destroyed and all memory is freed. - All stored elements are destroyed and all memory is freed.
@ingroup container
*/ */
~basic_json() ~basic_json()
{ {
@ -3138,8 +3162,6 @@ class basic_json
- The complexity is constant. - The complexity is constant.
@liveexample{The following code shows an example for @ref begin.,begin} @liveexample{The following code shows an example for @ref begin.,begin}
@ingroup container
*/ */
iterator begin() iterator begin()
{ {
@ -3150,7 +3172,6 @@ class basic_json
/*! /*!
@copydoc basic_json::cbegin() @copydoc basic_json::cbegin()
@ingroup container
*/ */
const_iterator begin() const const_iterator begin() const
{ {
@ -3173,8 +3194,6 @@ class basic_json
- Has the semantics of `const_cast<const basic_json&>(*this).begin()`. - Has the semantics of `const_cast<const basic_json&>(*this).begin()`.
@liveexample{The following code shows an example for @ref cbegin.,cbegin} @liveexample{The following code shows an example for @ref cbegin.,cbegin}
@ingroup container
*/ */
const_iterator cbegin() const const_iterator cbegin() const
{ {
@ -3198,8 +3217,6 @@ class basic_json
- The complexity is constant. - The complexity is constant.
@liveexample{The following code shows an example for @ref end.,end} @liveexample{The following code shows an example for @ref end.,end}
@ingroup container
*/ */
iterator end() iterator end()
{ {
@ -3210,7 +3227,6 @@ class basic_json
/*! /*!
@copydoc basic_json::cend() @copydoc basic_json::cend()
@ingroup container
*/ */
const_iterator end() const const_iterator end() const
{ {
@ -3233,8 +3249,6 @@ class basic_json
- Has the semantics of `const_cast<const basic_json&>(*this).end()`. - Has the semantics of `const_cast<const basic_json&>(*this).end()`.
@liveexample{The following code shows an example for @ref cend.,cend} @liveexample{The following code shows an example for @ref cend.,cend}
@ingroup container
*/ */
const_iterator cend() const const_iterator cend() const
{ {
@ -3257,8 +3271,6 @@ class basic_json
- Has the semantics of `reverse_iterator(end())`. - Has the semantics of `reverse_iterator(end())`.
@liveexample{The following code shows an example for @ref rbegin.,rbegin} @liveexample{The following code shows an example for @ref rbegin.,rbegin}
@ingroup reversiblecontainer
*/ */
reverse_iterator rbegin() reverse_iterator rbegin()
{ {
@ -3267,7 +3279,6 @@ class basic_json
/*! /*!
@copydoc basic_json::crbegin() @copydoc basic_json::crbegin()
@ingroup reversiblecontainer
*/ */
const_reverse_iterator rbegin() const const_reverse_iterator rbegin() const
{ {
@ -3289,8 +3300,6 @@ class basic_json
- Has the semantics of `reverse_iterator(begin())`. - Has the semantics of `reverse_iterator(begin())`.
@liveexample{The following code shows an example for @ref rend.,rend} @liveexample{The following code shows an example for @ref rend.,rend}
@ingroup reversiblecontainer
*/ */
reverse_iterator rend() reverse_iterator rend()
{ {
@ -3299,7 +3308,6 @@ class basic_json
/*! /*!
@copydoc basic_json::crend() @copydoc basic_json::crend()
@ingroup reversiblecontainer
*/ */
const_reverse_iterator rend() const const_reverse_iterator rend() const
{ {
@ -3321,8 +3329,6 @@ class basic_json
- Has the semantics of `const_cast<const basic_json&>(*this).rbegin()`. - Has the semantics of `const_cast<const basic_json&>(*this).rbegin()`.
@liveexample{The following code shows an example for @ref crbegin.,crbegin} @liveexample{The following code shows an example for @ref crbegin.,crbegin}
@ingroup reversiblecontainer
*/ */
const_reverse_iterator crbegin() const const_reverse_iterator crbegin() const
{ {
@ -3344,8 +3350,6 @@ class basic_json
- Has the semantics of `const_cast<const basic_json&>(*this).rend()`. - Has the semantics of `const_cast<const basic_json&>(*this).rend()`.
@liveexample{The following code shows an example for @ref crend.,crend} @liveexample{The following code shows an example for @ref crend.,crend}
@ingroup reversiblecontainer
*/ */
const_reverse_iterator crend() const const_reverse_iterator crend() const
{ {
@ -3388,8 +3392,6 @@ class basic_json
@liveexample{The following code uses @ref empty to check if a @ref json @liveexample{The following code uses @ref empty to check if a @ref json
object contains any elements.,empty} object contains any elements.,empty}
@ingroup container
*/ */
bool empty() const noexcept bool empty() const noexcept
{ {
@ -3444,8 +3446,6 @@ class basic_json
@liveexample{The following code calls @ref size on the different value @liveexample{The following code calls @ref size on the different value
types.,size} types.,size}
@ingroup container
*/ */
size_type size() const noexcept size_type size() const noexcept
{ {
@ -3503,8 +3503,6 @@ class basic_json
@liveexample{The following code calls @ref max_size on the different value @liveexample{The following code calls @ref max_size on the different value
types. Note the output is implementation specific.,max_size} types. Note the output is implementation specific.,max_size}
@ingroup container
*/ */
size_type max_size() const noexcept size_type max_size() const noexcept
{ {
@ -3932,8 +3930,6 @@ class basic_json
@liveexample{The example below shows how JSON arrays can be @liveexample{The example below shows how JSON arrays can be
swapped.,swap__reference} swapped.,swap__reference}
@ingroup container
*/ */
void swap(reference other) noexcept ( void swap(reference other) noexcept (
std::is_nothrow_move_constructible<value_t>::value and std::is_nothrow_move_constructible<value_t>::value and
@ -3962,8 +3958,6 @@ class basic_json
@liveexample{The example below shows how JSON values can be @liveexample{The example below shows how JSON values can be
swapped.,swap__array_t} swapped.,swap__array_t}
@ingroup container
*/ */
void swap(array_t& other) void swap(array_t& other)
{ {
@ -3993,8 +3987,6 @@ class basic_json
@liveexample{The example below shows how JSON values can be @liveexample{The example below shows how JSON values can be
swapped.,swap__object_t} swapped.,swap__object_t}
@ingroup container
*/ */
void swap(object_t& other) void swap(object_t& other)
{ {
@ -4024,8 +4016,6 @@ class basic_json
@liveexample{The example below shows how JSON values can be @liveexample{The example below shows how JSON values can be
swapped.,swap__string_t} swapped.,swap__string_t}
@ingroup container
*/ */
void swap(string_t& other) void swap(string_t& other)
{ {
@ -4100,8 +4090,6 @@ class basic_json
@liveexample{The example demonstrates comparing several JSON @liveexample{The example demonstrates comparing several JSON
types.,operator__equal} types.,operator__equal}
@ingroup container
*/ */
friend bool operator==(const_reference lhs, const_reference rhs) noexcept friend bool operator==(const_reference lhs, const_reference rhs) noexcept
{ {
@ -4186,8 +4174,6 @@ class basic_json
@liveexample{The example demonstrates comparing several JSON @liveexample{The example demonstrates comparing several JSON
types.,operator__notequal} types.,operator__notequal}
@ingroup container
*/ */
friend bool operator!=(const_reference lhs, const_reference rhs) noexcept friend bool operator!=(const_reference lhs, const_reference rhs) noexcept
{ {
@ -4839,7 +4825,7 @@ class basic_json
} }
/// return value to compare /// return value to compare
operator const difference_type () const operator difference_type () const
{ {
return m_it; return m_it;
} }
@ -4862,21 +4848,28 @@ class basic_json
struct internal_iterator struct internal_iterator
{ {
/// iterator for JSON objects /// iterator for JSON objects
typename object_t::iterator object_iterator; typename object_t::iterator object_iterator = typename object_t::iterator();
/// iterator for JSON arrays /// iterator for JSON arrays
typename array_t::iterator array_iterator; typename array_t::iterator array_iterator = typename array_t::iterator();
/// generic iterator for all other types /// generic iterator for all other types
primitive_iterator_t primitive_iterator; primitive_iterator_t primitive_iterator = primitive_iterator_t();
// leave the union un-initialized
internal_iterator() {}
}; };
public: public:
/// a const random access iterator for the basic_json class /*!
@brief a const random access iterator for the @ref basic_json class
This class implements a const iterator for the @ref basic_json class. From
this class, the @ref iterator class is derived.
@requirement The class satisfies the following concept requirements:
- [RandomAccessIterator](http://en.cppreference.com/w/cpp/concept/RandomAccessIterator):
The iterator that can be moved to point (forward and backward) to any
element in constant time.
*/
class const_iterator : public std::iterator<std::random_access_iterator_tag, const basic_json> class const_iterator : public std::iterator<std::random_access_iterator_tag, const basic_json>
{ {
// allow basic_json class to access m_it /// allow basic_json to access private members
friend class basic_json; friend class basic_json;
public: public:
@ -5368,7 +5361,16 @@ class basic_json
internal_iterator m_it = internal_iterator(); internal_iterator m_it = internal_iterator();
}; };
/// a random access iterator for the basic_json class /*!
@brief a mutable random access iterator for the @ref basic_json class
@requirement The class satisfies the following concept requirements:
- [RandomAccessIterator](http://en.cppreference.com/w/cpp/concept/RandomAccessIterator):
The iterator that can be moved to point (forward and backward) to any
element in constant time.
- [OutputIterator](http://en.cppreference.com/w/cpp/concept/OutputIterator):
It is possible to write to the pointed-to element.
*/
class iterator : public const_iterator class iterator : public const_iterator
{ {
public: public:
@ -5490,13 +5492,28 @@ class basic_json
} }
}; };
/// a template for a reverse iterator class /*!
@brief a template for a reverse iterator class
@tparam Base the base iterator type to reverse. Valid types are @ref
iterator (to create @ref reverse_iterator) and @ref const_iterator (to
create @ref const_reverse_iterator).
@requirement The class satisfies the following concept requirements:
- [RandomAccessIterator](http://en.cppreference.com/w/cpp/concept/RandomAccessIterator):
The iterator that can be moved to point (forward and backward) to any
element in constant time.
- [OutputIterator](http://en.cppreference.com/w/cpp/concept/OutputIterator):
It is possible to write to the pointed-to element (only if @a Base is
@ref iterator).
*/
template<typename Base> template<typename Base>
class json_reverse_iterator : public std::reverse_iterator<Base> class json_reverse_iterator : public std::reverse_iterator<Base>
{ {
public: public:
/// shortcut to the reverse iterator adaptor /// shortcut to the reverse iterator adaptor
using base_iterator = std::reverse_iterator<Base>; using base_iterator = std::reverse_iterator<Base>;
/// the reference type for the pointed-to element
using reference = typename Base::reference; using reference = typename Base::reference;
/// create reverse iterator from iterator /// create reverse iterator from iterator
@ -6353,7 +6370,6 @@ namespace std
{ {
/*! /*!
@brief exchanges the values of two JSON objects @brief exchanges the values of two JSON objects
@ingroup container
*/ */
template <> template <>
inline void swap(nlohmann::json& j1, inline void swap(nlohmann::json& j1,