Skip to content

Commit

Permalink
~ Corrected code as mentionned in review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas David committed Aug 11, 2021
1 parent 8f10f92 commit 1e52b01
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 28 deletions.
8 changes: 4 additions & 4 deletions examples/example_json_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ CROW_ROUTE(app, "/json")
CROW_ROUTE(app, "/json-initializer-list-constructor")
([] {
return crow::json::wvalue({
{"first", "Hello world!"}, /* stores a char const* hence a type::String */
{"second", "How are you today?"}, /* stores a char const* hence a std::int64_t. */
{"first", "Hello world!"}, /* stores a char const* hence a json::type::String */
{"second", std::string("How are you today?")}, /* stores a std::string hence a json::type::String. */
{"third", 54}, /* stores an int (as 54 is an int literal) hence a std::int64_t. */
{"fourth", 54l}, /* stores a long (as 54l is a long literal) hence a std::int64_t. */
{"fifth", 54u}, /* stores an unsigned int (as 54u is a unsigned int literal) hence a std::uint64_t. */
{"sixth", 54ul}, /* stores an unsigned long (as 54ul is an unsigned long literal) hence a std::uint64_t. */
{"seventh", 2.f}, /* stores a float (as 2.f is a float literal) hence a double. */
{"eighth", 2.}, /* stores a double (as 2. is a double literal) hence a double. */
{"ninth", nullptr}, /* stores a std::nullptr hence type::Null . */
{"tenth", true} /* stores a bool hence type::True . */
{"ninth", nullptr}, /* stores a std::nullptr hence json::type::Null . */
{"tenth", true} /* stores a bool hence json::type::True . */
});
});

Expand Down
41 changes: 17 additions & 24 deletions include/crow/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -1245,18 +1245,8 @@ namespace crow

public:
constexpr number() noexcept : ui() {} /* default constructor initializes unsigned integer. */

constexpr number(std::uint8_t value) noexcept : ui(static_cast<std::uint64_t>(value)) {}
constexpr number(std::uint16_t value) noexcept : ui(static_cast<std::uint64_t>(value)) {}
constexpr number(std::uint32_t value) noexcept : ui(static_cast<std::uint64_t>(value)) {}
constexpr number(std::uint64_t value) noexcept : ui(value) {}

constexpr number(std::int8_t value) noexcept : si(static_cast<std::int64_t>(value)) {}
constexpr number(std::int16_t value) noexcept : si(static_cast<std::int64_t>(value)) {}
constexpr number(std::int32_t value) noexcept : si(static_cast<std::int64_t>(value)) {}
constexpr number(std::int64_t value) noexcept : si(value) {}

constexpr number(float value) noexcept : d(static_cast<double>(value)) {}
constexpr number(double value) noexcept : d(value) {}
} num; ///< Value if type is a number.
std::string s; ///< Value if type is a string.
Expand All @@ -1274,18 +1264,18 @@ namespace crow

wvalue(bool value) : returnable("application/json"), t_(value ? type::True : type::False) {}

wvalue(std::uint8_t value) : returnable("application/json"), t_(type::Number), nt(num_type::Unsigned_integer), num(value) {}
wvalue(std::uint16_t value) : returnable("application/json"), t_(type::Number), nt(num_type::Unsigned_integer), num(value) {}
wvalue(std::uint32_t value) : returnable("application/json"), t_(type::Number), nt(num_type::Unsigned_integer), num(value) {}
wvalue(std::uint64_t value) : returnable("application/json"), t_(type::Number), nt(num_type::Unsigned_integer), num(value) {}
wvalue(std::uint8_t value) : returnable("application/json"), t_(type::Number), nt(num_type::Unsigned_integer), num(static_cast<std::uint64_t>(value)) {}
wvalue(std::uint16_t value) : returnable("application/json"), t_(type::Number), nt(num_type::Unsigned_integer), num(static_cast<std::uint64_t>(value)) {}
wvalue(std::uint32_t value) : returnable("application/json"), t_(type::Number), nt(num_type::Unsigned_integer), num(static_cast<std::uint64_t>(value)) {}
wvalue(std::uint64_t value) : returnable("application/json"), t_(type::Number), nt(num_type::Unsigned_integer), num(static_cast<std::uint64_t>(value)) {}

wvalue(std::int8_t value) : returnable("application/json"), t_(type::Number), nt(num_type::Signed_integer), num(value) {}
wvalue(std::int16_t value) : returnable("application/json"), t_(type::Number), nt(num_type::Signed_integer), num(value) {}
wvalue(std::int32_t value) : returnable("application/json"), t_(type::Number), nt(num_type::Signed_integer), num(value) {}
wvalue(std::int64_t value) : returnable("application/json"), t_(type::Number), nt(num_type::Signed_integer), num(value) {}
wvalue(std::int8_t value) : returnable("application/json"), t_(type::Number), nt(num_type::Signed_integer), num(static_cast<std::int64_t>(value)) {}
wvalue(std::int16_t value) : returnable("application/json"), t_(type::Number), nt(num_type::Signed_integer), num(static_cast<std::int64_t>(value)) {}
wvalue(std::int32_t value) : returnable("application/json"), t_(type::Number), nt(num_type::Signed_integer), num(static_cast<std::int64_t>(value)) {}
wvalue(std::int64_t value) : returnable("application/json"), t_(type::Number), nt(num_type::Signed_integer), num(static_cast<std::int64_t>(value)) {}

wvalue(float value) : returnable("application/json"), t_(type::Number), nt(num_type::Floating_point), num(value) {}
wvalue(double value) : returnable("application/json"), t_(type::Number), nt(num_type::Floating_point), num(value) {}
wvalue(float value) : returnable("application/json"), t_(type::Number), nt(num_type::Floating_point), num(static_cast<double>(value)) {}
wvalue(double value) : returnable("application/json"), t_(type::Number), nt(num_type::Floating_point), num(static_cast<double>(value)) {}

wvalue(char const* value) : returnable("application/json"), t_(type::String), s(value) {}

Expand Down Expand Up @@ -1565,8 +1555,9 @@ namespace crow
reset();
t_ = type::Object;
o = std::unique_ptr<object_type>(new object_type(initializer_list));
} else
} else {
(*o) = initializer_list;
}
return *this;
}

Expand All @@ -1576,8 +1567,9 @@ namespace crow
reset();
t_ = type::Object;
o = std::unique_ptr<object_type>(new object_type(value));
} else
} else {
(*o) = value;
}
return *this;
}

Expand All @@ -1587,8 +1579,9 @@ namespace crow
reset();
t_ = type::Object;
o = std::unique_ptr<object_type>(new object_type(std::move(value)));
} else
(*o) = value;
} else {
(*o) = std::move(value);
}
return *this;
}

Expand Down

0 comments on commit 1e52b01

Please sign in to comment.