Try to get rid of std::variant in json_container.hpp
This commit is contained in:
parent
dbc52728c3
commit
150c792f76
@ -117,9 +117,10 @@ struct Array
|
|||||||
std::vector<Value> values;
|
std::vector<Value> values;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Value
|
||||||
struct Value {
|
{
|
||||||
enum class Type {
|
enum class Type
|
||||||
|
{
|
||||||
Invalid,
|
Invalid,
|
||||||
String,
|
String,
|
||||||
Number,
|
Number,
|
||||||
@ -136,9 +137,9 @@ struct Value {
|
|||||||
Type type;
|
Type type;
|
||||||
|
|
||||||
Value() noexcept : type(Type::Invalid) {}
|
Value() noexcept : type(Type::Invalid) {}
|
||||||
Value(const Null&) noexcept : type(Type::Null) {}
|
Value(const Null &) noexcept : type(Type::Null) {}
|
||||||
Value(const True&) noexcept : type(Type::True) {}
|
Value(const True &) noexcept : type(Type::True) {}
|
||||||
Value(const False&) noexcept : type(Type::False) {}
|
Value(const False &) noexcept : type(Type::False) {}
|
||||||
Value(String &&string_) noexcept : string(std::move(string_)), type(Type::String) {}
|
Value(String &&string_) noexcept : string(std::move(string_)), type(Type::String) {}
|
||||||
Value(const Number &number_) noexcept : number(number_), type(Type::Number) {}
|
Value(const Number &number_) noexcept : number(number_), type(Type::Number) {}
|
||||||
Value(const Object &object_) noexcept : object(object_), type(Type::Object) {}
|
Value(const Object &object_) noexcept : object(object_), type(Type::Object) {}
|
||||||
@ -146,62 +147,68 @@ struct Value {
|
|||||||
|
|
||||||
Value(double number) noexcept : number(number), type(Type::Number) {}
|
Value(double number) noexcept : number(number), type(Type::Number) {}
|
||||||
Value(std::string string) noexcept : string(std::move(string)), type(Type::String) {}
|
Value(std::string string) noexcept : string(std::move(string)), type(Type::String) {}
|
||||||
Value(const char* string) noexcept : string(string), type(Type::String) {}
|
Value(const char *string) noexcept : string(string), type(Type::String) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace osrm::util::json
|
} // namespace osrm::util::json
|
||||||
|
|
||||||
namespace std {
|
namespace std
|
||||||
template <typename T>
|
{
|
||||||
inline T& get(osrm::util::json::Value& value) noexcept;
|
template <typename T> inline T &get(osrm::util::json::Value &value) noexcept;
|
||||||
|
|
||||||
template<>
|
template <>
|
||||||
inline osrm::util::json::String& get<osrm::util::json::String>(osrm::util::json::Value& value) noexcept
|
inline osrm::util::json::String &
|
||||||
|
get<osrm::util::json::String>(osrm::util::json::Value &value) noexcept
|
||||||
{
|
{
|
||||||
return value.string;
|
return value.string;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template <>
|
||||||
inline osrm::util::json::Number& get<osrm::util::json::Number>(osrm::util::json::Value& value) noexcept
|
inline osrm::util::json::Number &
|
||||||
|
get<osrm::util::json::Number>(osrm::util::json::Value &value) noexcept
|
||||||
{
|
{
|
||||||
return value.number;
|
return value.number;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template <>
|
||||||
inline osrm::util::json::Object& get<osrm::util::json::Object>(osrm::util::json::Value& value) noexcept
|
inline osrm::util::json::Object &
|
||||||
|
get<osrm::util::json::Object>(osrm::util::json::Value &value) noexcept
|
||||||
{
|
{
|
||||||
return value.object;
|
return value.object;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template <>
|
||||||
inline osrm::util::json::Array& get<osrm::util::json::Array>(osrm::util::json::Value& value) noexcept
|
inline osrm::util::json::Array &
|
||||||
|
get<osrm::util::json::Array>(osrm::util::json::Value &value) noexcept
|
||||||
{
|
{
|
||||||
return value.array;
|
return value.array;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T> inline const T &get(const osrm::util::json::Value &value) noexcept;
|
||||||
inline const T& get(const osrm::util::json::Value& value) noexcept;
|
|
||||||
|
|
||||||
template<>
|
template <>
|
||||||
inline const osrm::util::json::String& get<osrm::util::json::String>(const osrm::util::json::Value& value) noexcept
|
inline const osrm::util::json::String &
|
||||||
|
get<osrm::util::json::String>(const osrm::util::json::Value &value) noexcept
|
||||||
{
|
{
|
||||||
return value.string;
|
return value.string;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template <>
|
||||||
inline const osrm::util::json::Number& get<osrm::util::json::Number>(const osrm::util::json::Value& value) noexcept
|
inline const osrm::util::json::Number &
|
||||||
|
get<osrm::util::json::Number>(const osrm::util::json::Value &value) noexcept
|
||||||
{
|
{
|
||||||
return value.number;
|
return value.number;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template <>
|
||||||
inline const osrm::util::json::Object& get<osrm::util::json::Object>(const osrm::util::json::Value& value) noexcept
|
inline const osrm::util::json::Object &
|
||||||
|
get<osrm::util::json::Object>(const osrm::util::json::Value &value) noexcept
|
||||||
{
|
{
|
||||||
return value.object;
|
return value.object;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Visitor>
|
template <typename Visitor>
|
||||||
inline void visit(Visitor&& visitor, const osrm::util::json::Value& value)
|
inline void visit(Visitor &&visitor, const osrm::util::json::Value &value)
|
||||||
{
|
{
|
||||||
switch (value.type)
|
switch (value.type)
|
||||||
{
|
{
|
||||||
@ -231,5 +238,5 @@ inline void visit(Visitor&& visitor, const osrm::util::json::Value& value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}// namespace std
|
} // namespace std
|
||||||
#endif // JSON_CONTAINER_HPP
|
#endif // JSON_CONTAINER_HPP
|
||||||
|
Loading…
Reference in New Issue
Block a user