+ removed data() function
This commit is contained in:
parent
515d731fd4
commit
a8c4f84fb8
4 changed files with 21 additions and 42 deletions
21
Reference.md
Normal file
21
Reference.md
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
# Reference
|
||||||
|
|
||||||
|
## Types and default values
|
||||||
|
|
||||||
|
| JSON type | value_type | C++ type | type alias | default value |
|
||||||
|
| ----------------------- | -------------------------- | ----------------------------- | ---------------------- | --------------
|
||||||
|
| null | `value_type::null` | `nullptr_t` | - | `nullptr` |
|
||||||
|
| string | `value_type::string` | `std::string` | `JSON::string_t` | `""` |
|
||||||
|
| number (integer) | `value_type::number` | `int` | `JSON::number_t` | `0` |
|
||||||
|
| number (floating point) | `value_type::number_float` | `double` | `JSON::number_float_t` | `0.0` |
|
||||||
|
| array | `value_type::array ` | `std::array<JSON>` | `JSON::array_t` | `{}` |
|
||||||
|
| object | `value_type::object` | `std::map<std::string, JSON>` | `JSON::object_t` | `{}` |
|
||||||
|
|
||||||
|
## Conversions
|
||||||
|
|
||||||
|
There are only a few type conversions possible:
|
||||||
|
|
||||||
|
- An integer number can be translated to a floating point number (e.g., by calling `get<double>()`).
|
||||||
|
- A floating pointnnumber can be translated to an integer number (e.g., by calling `get<int>()`). Note the number is truncated and not rounded, ceiled or floored.
|
||||||
|
- Any value but JSON objects can be translated into an array. The result is a singleton array that consists of the value before.
|
||||||
|
- Any other conversion will throw a `std::logic_error` exception.
|
13
src/JSON.cc
13
src/JSON.cc
|
@ -1224,19 +1224,6 @@ JSON::const_iterator JSON::find(const char* key) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
@return the payload of the JSON object.
|
|
||||||
*/
|
|
||||||
JSON::value JSON::data() noexcept
|
|
||||||
{
|
|
||||||
return _value;
|
|
||||||
}
|
|
||||||
|
|
||||||
const JSON::value JSON::data() const noexcept
|
|
||||||
{
|
|
||||||
return _value;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool JSON::operator==(const JSON& o) const noexcept
|
bool JSON::operator==(const JSON& o) const noexcept
|
||||||
{
|
{
|
||||||
switch (_type)
|
switch (_type)
|
||||||
|
|
|
@ -279,11 +279,6 @@ class JSON
|
||||||
/// find an element in an object (returns end() iterator otherwise)
|
/// find an element in an object (returns end() iterator otherwise)
|
||||||
const_iterator find(const char*) const;
|
const_iterator find(const char*) const;
|
||||||
|
|
||||||
/// direct access to the underlying payload
|
|
||||||
value data() noexcept;
|
|
||||||
/// direct access to the underlying payload
|
|
||||||
const value data() const noexcept;
|
|
||||||
|
|
||||||
/// lexicographically compares the values
|
/// lexicographically compares the values
|
||||||
bool operator==(const JSON&) const noexcept;
|
bool operator==(const JSON&) const noexcept;
|
||||||
/// lexicographically compares the values
|
/// lexicographically compares the values
|
||||||
|
|
|
@ -21,10 +21,6 @@ TEST_CASE("array")
|
||||||
CHECK(j.begin() != j.end());
|
CHECK(j.begin() != j.end());
|
||||||
CHECK(j.cbegin() != j.cend());
|
CHECK(j.cbegin() != j.cend());
|
||||||
|
|
||||||
// check payload
|
|
||||||
//CHECK(*(j.data().array) == JSON::array_t());
|
|
||||||
//CHECK(*(j_const.data().array) == JSON::array_t());
|
|
||||||
|
|
||||||
// container members
|
// container members
|
||||||
CHECK(j.size() == 0);
|
CHECK(j.size() == 0);
|
||||||
CHECK(j.empty() == true);
|
CHECK(j.empty() == true);
|
||||||
|
@ -306,10 +302,6 @@ TEST_CASE("object")
|
||||||
CHECK(j.begin() != j.end());
|
CHECK(j.begin() != j.end());
|
||||||
CHECK(j.cbegin() != j.cend());
|
CHECK(j.cbegin() != j.cend());
|
||||||
|
|
||||||
// check payload
|
|
||||||
//CHECK(*(j.data().object) == JSON::object_t());
|
|
||||||
//CHECK(*(j_const.data().object) == JSON::object_t());
|
|
||||||
|
|
||||||
// container members
|
// container members
|
||||||
CHECK(j.size() == 0);
|
CHECK(j.size() == 0);
|
||||||
CHECK(j.empty() == true);
|
CHECK(j.empty() == true);
|
||||||
|
@ -756,10 +748,6 @@ TEST_CASE("string")
|
||||||
// string representation of default value
|
// string representation of default value
|
||||||
CHECK(j.toString() == "\"\"");
|
CHECK(j.toString() == "\"\"");
|
||||||
|
|
||||||
// check payload
|
|
||||||
CHECK(*(j.data().string) == JSON::string_t());
|
|
||||||
CHECK(*(j_const.data().string) == JSON::string_t());
|
|
||||||
|
|
||||||
// container members
|
// container members
|
||||||
CHECK(j.size() == 1);
|
CHECK(j.size() == 1);
|
||||||
CHECK(j.empty() == false);
|
CHECK(j.empty() == false);
|
||||||
|
@ -842,10 +830,6 @@ TEST_CASE("boolean")
|
||||||
// string representation of default value
|
// string representation of default value
|
||||||
CHECK(j.toString() == "false");
|
CHECK(j.toString() == "false");
|
||||||
|
|
||||||
// check payload
|
|
||||||
CHECK(j.data().boolean == JSON::boolean_t());
|
|
||||||
CHECK(j_const.data().boolean == JSON::boolean_t());
|
|
||||||
|
|
||||||
// container members
|
// container members
|
||||||
CHECK(j.size() == 1);
|
CHECK(j.size() == 1);
|
||||||
CHECK(j.empty() == false);
|
CHECK(j.empty() == false);
|
||||||
|
@ -925,10 +909,6 @@ TEST_CASE("number (int)")
|
||||||
// string representation of default value
|
// string representation of default value
|
||||||
CHECK(j.toString() == "0");
|
CHECK(j.toString() == "0");
|
||||||
|
|
||||||
// check payload
|
|
||||||
CHECK(j.data().number == JSON::number_t());
|
|
||||||
CHECK(j_const.data().number == JSON::number_t());
|
|
||||||
|
|
||||||
// container members
|
// container members
|
||||||
CHECK(j.size() == 1);
|
CHECK(j.size() == 1);
|
||||||
CHECK(j.empty() == false);
|
CHECK(j.empty() == false);
|
||||||
|
@ -1015,10 +995,6 @@ TEST_CASE("number (float)")
|
||||||
// string representation of default value
|
// string representation of default value
|
||||||
CHECK(j.toString() == "0.000000");
|
CHECK(j.toString() == "0.000000");
|
||||||
|
|
||||||
// check payload
|
|
||||||
CHECK(j.data().number_float == JSON::number_float_t());
|
|
||||||
CHECK(j_const.data().number_float == JSON::number_float_t());
|
|
||||||
|
|
||||||
// container members
|
// container members
|
||||||
CHECK(j.size() == 1);
|
CHECK(j.size() == 1);
|
||||||
CHECK(j.empty() == false);
|
CHECK(j.empty() == false);
|
||||||
|
|
Loading…
Reference in a new issue