/***
* ==++==
*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* ==--==
* =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
*
* HTTP Library: JSON parser and writer
*
* For the latest on this and related APIs, please see: https://github.com/Microsoft/cpprestsdk
*
* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
****/
#include "stdafx.h"
using namespace web;
bool json::details::g_keep_json_object_unsorted = false;
void json::keep_object_element_order(bool keep_order)
{
json::details::g_keep_json_object_unsorted = keep_order;
}
utility::ostream_t& web::json::operator << (utility::ostream_t &os, const web::json::value &val)
{
val.serialize(os);
return os;
}
utility::istream_t& web::json::operator >> (utility::istream_t &is, json::value &val)
{
val = json::value::parse(is);
return is;
}
web::json::value::value() :
m_value(utility::details::make_unique<:json::details::_null>())
#ifdef ENABLE_JSON_VALUE_VISUALIZER
,m_kind(value::Null)
#endif
{ }
web::json::value::value(int32_t value) :
m_value(utility::details::make_unique<:json::details::_number>(value))
#ifdef ENABLE_JSON_VALUE_VISUALIZER
,m_kind(value::Number)
#endif
{ }
web::json::value::value(uint32_t value) :
m_value(utility::details::make_unique<:json::details::_number>(value))
#ifdef ENABLE_JSON_VALUE_VISUALIZER
,m_kind(value::Number)
#endif
{ }
web::json::value::value(int64_t value) :
m_value(utility::details::make_unique<:json::details::_number>(value))
#ifdef ENABLE_JSON_VALUE_VISUALIZER
,m_kind(value::Number)
#endif
{ }
web::json::value::value(uint64_t value) :
m_value(utility::details::make_unique<:json::details::_number>(value))
#ifdef ENABLE_JSON_VALUE_VISUALIZER
,m_kind(value::Number)
#endif
{ }
web::json::value::value(double value) :
m_value(utility::details::make_unique<:json::details::_number>(value))
#ifdef ENABLE_JSON_VALUE_VISUALIZER
,m_kind(value::Number)
#endif
{ }
web::json::value::value(bool value) :
m_value(utility::details::make_unique<:json::details::_boolean>(value))
#ifdef ENABLE_JSON_VALUE_VISUALIZER
,m_kind(value::Boolean)
#endif
{ }
web::json::value::value(utility::string_t value) :
m_value(utility::details::make_unique<:json::details::_string>(std::move(value)))
#ifdef ENABLE_JSON_VALUE_VISUALIZER
,m_kind(value::String)
#endif
{ }
web::json::value::value(utility::string_t value, bool has_escape_chars) :
m_value(utility::details::make_unique<:json::details::_string>(std::move(value), has_escape_chars))
#ifdef ENABLE_JSON_VALUE_VISUALIZER
, m_kind(value::String)
#endif
{ }
web::json::value::value(const utility::char_t* value) :
m_value(utility::details::make_unique<:json::details::_string>(value))
#ifdef ENABLE_JSON_VALUE_VISUALIZER
,m_kind(value::String)
#endif
{ }
web::json::value::value(const utility::char_t* value, bool has_escape_chars) :
m_value(utility::details::make_unique<:json::details::_string>(utility::string_t(value), has_escape_chars))
#ifdef ENABLE_JSON_VALUE_VISUALIZER
, m_kind(value::String)
#endif
{ }
web::json::value::value(const value &other) :
m_value(other.m_value->_copy_value())
#ifdef ENABLE_JSON_VALUE_VISUALIZER
,m_kind(other.m_kind)
#endif
{ }
web::json::value &web::json::value::operator=(const value &other)
{
if(this != &other)
{
m_value = std::unique_ptr<:_value>(other.m_value->_copy_value());
#ifdef ENABLE_JSON_VALUE_VISUALIZER
m_kind = other.m_kind;
#endif
}
return *this;
}
web::json::value::value(value &&other) CPPREST_NOEXCEPT :
m_value(std::move(other.m_value))
#ifdef ENABLE_JSON_VALUE_VISUALIZER
,m_kind(other.m_kind)
#endif
{}
web::json::value &web::json::value::operator=(web::json::value &&other) CPPREST_NOEXCEPT
{
if(this != &other)
{
m_value.swap(other.m_value);
#ifdef ENABLE_JSON_VALUE_VISUALIZER
m_kind = other.m_kind;
#endif
}
return *this;
}
web::json::value web::json::value::null()
{
return web::json::value();
}
web::json::value web::json::value::number(double value)
{
return web::json::value(value);
}
web::json::value web::json::value::number(int32_t value)
{
return web::json::value(value);
}
web::json::value web::json::value::number(uint32_t value)
{
return web::json::value(value);
}
web::json::value web::json::value::number(int64_t value)
{
return web::json::value(value);
}
web::json::value web::json::value::number(uint64_t value)
{
return web::json::value(value);
}
web::json::value web::json::value::boolean(bool value)
{
return web::json::value(value);
}
web::json::value web::json::value::string(utility::string_t value)
{
std::unique_ptr<:_value> ptr = utility::details::make_unique<:_string>(std::move(value));
return web::json::value(std::move(ptr)
#ifdef ENABLE_JSON_VALUE_VISUALIZER
,value::String
#endif
);
}
web::json::value web::json::value::string(utility::string_t value, bool has_escape_chars)
{
std::unique_ptr<:_value> ptr = utility::details::make_unique<:_string>(std::move(value), has_escape_chars);
return web::json::value(std::move(ptr)
#ifdef ENABLE_JSON_VALUE_VISUALIZER
,value::String
#endif
);
}
#ifdef _WIN32
web::json::value web::json::value::string(const std::string &value)
{
std::unique_ptr<:_value> ptr = utility::details::make_unique<:_string>(utility::conversions::to_utf16string(value));
return web::json::value(std::move(ptr)
#ifdef ENABLE_JSON_VALUE_VISUALIZER
,value::String
#endif
);
}
#endif
web::json::value web::json::value::object(bool keep_order)
{
std::unique_ptr<:_value> ptr = utility::details::make_unique<:_object>(keep_order);
return web::json::value(std::move(ptr)
#ifdef ENABLE_JSON_VALUE_VISUALIZER
,value::Object
#endif
);
}
web::json::value web::json::value::object(std::vector<:pair value>> fields, bool keep_order)
{
std::unique_ptr<:_value> ptr = utility::details::make_unique<:_object>(std::move(fields), keep_order);
return web::json::value(std::move(ptr)
#ifdef ENABLE_JSON_VALUE_VISUALIZER
,value::Object
#endif
);
}
web::json::value web::json::value::array()
{
std::unique_ptr<:_value> ptr = utility::details::make_unique<:_array>();
return web::json::value(std::move(ptr)
#ifdef ENABLE_JSON_VALUE_VISUALIZER
,value::Array
#endif
);
}
web::json::value web::json::value::array(size_t size)
{
std::unique_ptr<:_value> ptr = utility::details::make_unique<:_array>(size);
return web::json::value(std::move(ptr)
#ifdef ENABLE_JSON_VALUE_VISUALIZER
,value::Array
#endif
);
}
web::json::value web::json::value::array(std::vector