minor changes

This commit is contained in:
Niels 2015-02-24 23:19:19 +01:00
parent ec42245951
commit 63c70fa07e
3 changed files with 145 additions and 56 deletions

View file

@ -274,6 +274,7 @@ class basic_json
{
return true;
}
default:
{
return false;
@ -291,6 +292,7 @@ class basic_json
{
return true;
}
default:
{
return false;
@ -317,7 +319,12 @@ class basic_json
// constructors //
//////////////////
/// create an empty value with a given type
/*!
@brief create an empty value with a given type
@param value the type to create an value of
@exception std::bad_alloc if allocation for object, array, or string fails.
*/
inline basic_json(const value_t value)
: m_type(value)
{
@ -578,6 +585,9 @@ class basic_json
/*!
@brief copy constructor
@exception std::bad_alloc if allocation for object, array, or string fails.
@ingroup container
*/
inline basic_json(const basic_json& other)
@ -589,6 +599,7 @@ class basic_json
{
break;
}
case (value_t::object):
{
Allocator<object_t> alloc;
@ -596,6 +607,7 @@ class basic_json
alloc.construct(m_value.object, *other.m_value.object);
break;
}
case (value_t::array):
{
Allocator<array_t> alloc;
@ -603,6 +615,7 @@ class basic_json
alloc.construct(m_value.array, *other.m_value.array);
break;
}
case (value_t::string):
{
Allocator<string_t> alloc;
@ -610,16 +623,19 @@ class basic_json
alloc.construct(m_value.string, *other.m_value.string);
break;
}
case (value_t::boolean):
{
m_value.boolean = other.m_value.boolean;
break;
}
case (value_t::number_integer):
{
m_value.number_integer = other.m_value.number_integer;
break;
}
case (value_t::number_float):
{
m_value.number_float = other.m_value.number_float;
@ -706,8 +722,9 @@ class basic_json
/*!
@brief serialization
Serialization function for JSON objects. The function tries to mimick Python's
@p json.dumps() function, and currently supports its @p indent parameter.
Serialization function for JSON objects. The function tries to mimick
Python's @p json.dumps() function, and currently supports its @p indent
parameter.
@param indent sif indent is nonnegative, then array elements and object
members will be pretty-printed with that indent level. An indent level of 0
@ -771,7 +788,7 @@ class basic_json
}
/// return the type of the object (implicit)
operator value_t() const noexcept
inline operator value_t() const noexcept
{
return m_type;
}
@ -1487,7 +1504,7 @@ class basic_json
@brief comparison: equal
@ingroup container
*/
friend bool operator==(const_reference lhs, const_reference rhs)
friend bool operator==(const_reference lhs, const_reference rhs) noexcept
{
switch (lhs.type())
{
@ -1564,13 +1581,13 @@ class basic_json
@brief comparison: not equal
@ingroup container
*/
friend bool operator!=(const_reference lhs, const_reference rhs)
friend bool operator!=(const_reference lhs, const_reference rhs) noexcept
{
return not (lhs == rhs);
}
/// comparison: less than
friend bool operator<(const_reference lhs, const_reference rhs)
friend bool operator<(const_reference lhs, const_reference rhs) noexcept
{
switch (lhs.type())
{
@ -1646,19 +1663,19 @@ class basic_json
}
/// comparison: less than or equal
friend bool operator<=(const_reference lhs, const_reference rhs)
friend bool operator<=(const_reference lhs, const_reference rhs) noexcept
{
return not (rhs < lhs);
}
/// comparison: greater than
friend bool operator>(const_reference lhs, const_reference rhs)
friend bool operator>(const_reference lhs, const_reference rhs) noexcept
{
return not (lhs <= rhs);
}
/// comparison: greater than or equal
friend bool operator>=(const_reference lhs, const_reference rhs)
friend bool operator>=(const_reference lhs, const_reference rhs) noexcept
{
return not (lhs < rhs);
}
@ -1783,36 +1800,42 @@ class basic_json
result += "\\\"";
break;
}
// reverse solidus (0x5c)
case '\\':
{
result += "\\\\";
break;
}
// backspace (0x08)
case '\b':
{
result += "\\b";
break;
}
// formfeed (0x0c)
case '\f':
{
result += "\\f";
break;
}
// newline (0x0a)
case '\n':
{
result += "\\n";
break;
}
// carriage return (0x0d)
case '\r':
{
result += "\\r";
break;
}
// horizontal tab (0x09)
case '\t':
{
@ -2027,7 +2050,7 @@ class basic_json
inline iterator() = default;
/// constructor for a given JSON instance
inline iterator(pointer object) : m_object(object)
inline iterator(pointer object) noexcept : m_object(object)
{
switch (m_object->m_type)
{
@ -2505,7 +2528,7 @@ class basic_json
inline const_iterator() = default;
/// constructor for a given JSON instance
inline const_iterator(pointer object) : m_object(object)
inline const_iterator(pointer object) noexcept : m_object(object)
{
switch (m_object->m_type)
{
@ -2528,7 +2551,7 @@ class basic_json
}
/// copy constructor given a nonconst iterator
inline const_iterator(const iterator& other) : m_object(other.m_object)
inline const_iterator(const iterator& other) noexcept : m_object(other.m_object)
{
switch (m_object->m_type)
{
@ -4268,7 +4291,6 @@ basic_json_parser_59:
/// default JSON class
using json = basic_json<>;
}

View file

@ -274,6 +274,7 @@ class basic_json
{
return true;
}
default:
{
return false;
@ -291,6 +292,7 @@ class basic_json
{
return true;
}
default:
{
return false;
@ -317,7 +319,12 @@ class basic_json
// constructors //
//////////////////
/// create an empty value with a given type
/*!
@brief create an empty value with a given type
@param value the type to create an value of
@exception std::bad_alloc if allocation for object, array, or string fails.
*/
inline basic_json(const value_t value)
: m_type(value)
{
@ -578,6 +585,9 @@ class basic_json
/*!
@brief copy constructor
@exception std::bad_alloc if allocation for object, array, or string fails.
@ingroup container
*/
inline basic_json(const basic_json& other)
@ -589,6 +599,7 @@ class basic_json
{
break;
}
case (value_t::object):
{
Allocator<object_t> alloc;
@ -596,6 +607,7 @@ class basic_json
alloc.construct(m_value.object, *other.m_value.object);
break;
}
case (value_t::array):
{
Allocator<array_t> alloc;
@ -603,6 +615,7 @@ class basic_json
alloc.construct(m_value.array, *other.m_value.array);
break;
}
case (value_t::string):
{
Allocator<string_t> alloc;
@ -610,16 +623,19 @@ class basic_json
alloc.construct(m_value.string, *other.m_value.string);
break;
}
case (value_t::boolean):
{
m_value.boolean = other.m_value.boolean;
break;
}
case (value_t::number_integer):
{
m_value.number_integer = other.m_value.number_integer;
break;
}
case (value_t::number_float):
{
m_value.number_float = other.m_value.number_float;
@ -706,8 +722,9 @@ class basic_json
/*!
@brief serialization
Serialization function for JSON objects. The function tries to mimick Python's
@p json.dumps() function, and currently supports its @p indent parameter.
Serialization function for JSON objects. The function tries to mimick
Python's @p json.dumps() function, and currently supports its @p indent
parameter.
@param indent sif indent is nonnegative, then array elements and object
members will be pretty-printed with that indent level. An indent level of 0
@ -771,7 +788,7 @@ class basic_json
}
/// return the type of the object (implicit)
operator value_t() const noexcept
inline operator value_t() const noexcept
{
return m_type;
}
@ -1487,7 +1504,7 @@ class basic_json
@brief comparison: equal
@ingroup container
*/
friend bool operator==(const_reference lhs, const_reference rhs)
friend bool operator==(const_reference lhs, const_reference rhs) noexcept
{
switch (lhs.type())
{
@ -1564,13 +1581,13 @@ class basic_json
@brief comparison: not equal
@ingroup container
*/
friend bool operator!=(const_reference lhs, const_reference rhs)
friend bool operator!=(const_reference lhs, const_reference rhs) noexcept
{
return not (lhs == rhs);
}
/// comparison: less than
friend bool operator<(const_reference lhs, const_reference rhs)
friend bool operator<(const_reference lhs, const_reference rhs) noexcept
{
switch (lhs.type())
{
@ -1646,19 +1663,19 @@ class basic_json
}
/// comparison: less than or equal
friend bool operator<=(const_reference lhs, const_reference rhs)
friend bool operator<=(const_reference lhs, const_reference rhs) noexcept
{
return not (rhs < lhs);
}
/// comparison: greater than
friend bool operator>(const_reference lhs, const_reference rhs)
friend bool operator>(const_reference lhs, const_reference rhs) noexcept
{
return not (lhs <= rhs);
}
/// comparison: greater than or equal
friend bool operator>=(const_reference lhs, const_reference rhs)
friend bool operator>=(const_reference lhs, const_reference rhs) noexcept
{
return not (lhs < rhs);
}
@ -1783,36 +1800,42 @@ class basic_json
result += "\\\"";
break;
}
// reverse solidus (0x5c)
case '\\':
{
result += "\\\\";
break;
}
// backspace (0x08)
case '\b':
{
result += "\\b";
break;
}
// formfeed (0x0c)
case '\f':
{
result += "\\f";
break;
}
// newline (0x0a)
case '\n':
{
result += "\\n";
break;
}
// carriage return (0x0d)
case '\r':
{
result += "\\r";
break;
}
// horizontal tab (0x09)
case '\t':
{
@ -2027,7 +2050,7 @@ class basic_json
inline iterator() = default;
/// constructor for a given JSON instance
inline iterator(pointer object) : m_object(object)
inline iterator(pointer object) noexcept : m_object(object)
{
switch (m_object->m_type)
{
@ -2505,7 +2528,7 @@ class basic_json
inline const_iterator() = default;
/// constructor for a given JSON instance
inline const_iterator(pointer object) : m_object(object)
inline const_iterator(pointer object) noexcept : m_object(object)
{
switch (m_object->m_type)
{
@ -2528,7 +2551,7 @@ class basic_json
}
/// copy constructor given a nonconst iterator
inline const_iterator(const iterator& other) : m_object(other.m_object)
inline const_iterator(const iterator& other) noexcept : m_object(other.m_object)
{
switch (m_object->m_type)
{
@ -3044,7 +3067,8 @@ class basic_json
@see <http://en.wikipedia.org/wiki/UTF-8#Sample_code>
*/
inline static string_t to_unicode(const size_t codepoint1, const size_t codepoint2 = 0)
inline static string_t to_unicode(const size_t codepoint1,
const size_t codepoint2 = 0)
{
string_t result;
@ -3072,7 +3096,7 @@ class basic_json
if (codepoint <= 0x7f)
{
// 1-byte characters: 0xxxxxxx (ASCI)
// 1-byte characters: 0xxxxxxx (ASCII)
result.append(1, static_cast<typename string_t::value_type>(codepoint));
}
else if (codepoint <= 0x7ff)
@ -3617,7 +3641,6 @@ class basic_json
/// default JSON class
using json = basic_json<>;
}

View file

@ -6796,6 +6796,8 @@ TEST_CASE("algorithms")
}
TEST_CASE("concepts")
{
SECTION("class json")
{
SECTION("DefaultConstructible")
{
@ -6832,3 +6834,45 @@ TEST_CASE("concepts")
CHECK(std::is_standard_layout<json>::value);
}
}
SECTION("class iterator")
{
SECTION("CopyConstructible")
{
CHECK(std::is_nothrow_copy_constructible<json::iterator>::value);
CHECK(std::is_nothrow_copy_constructible<json::const_iterator>::value);
}
SECTION("CopyAssignable")
{
CHECK(std::is_nothrow_copy_assignable<json::iterator>::value);
CHECK(std::is_nothrow_copy_assignable<json::const_iterator>::value);
}
SECTION("Destructible")
{
CHECK(std::is_nothrow_destructible<json::iterator>::value);
CHECK(std::is_nothrow_destructible<json::const_iterator>::value);
}
SECTION("Swappable")
{
{
json j {1, 2, 3};
json::iterator it1 = j.begin();
json::iterator it2 = j.end();
std::swap(it1, it2);
CHECK(it1 == j.end());
CHECK(it2 == j.begin());
}
{
json j {1, 2, 3};
json::const_iterator it1 = j.cbegin();
json::const_iterator it2 = j.cend();
std::swap(it1, it2);
CHECK(it1 == j.end());
CHECK(it2 == j.begin());
}
}
}
}