diff options
author | Manoj Srivastava <srivasta@debian.org> | 2020-05-22 19:57:41 -0700 |
---|---|---|
committer | Manoj Srivastava <srivasta@debian.org> | 2020-05-22 20:02:19 -0700 |
commit | c3d2579ad8d7eb33059aa8fdbaf5b564411a57f2 (patch) | |
tree | 1570cda0676fdcf4171a69a7fe313c1b89a52b0c /vendor/jsoncons-0.99.2/jsoncons_ext/boost/type_extensions.hpp | |
parent | 986b7742bf244b4073ecca0723615f70be8a1ab6 (diff) | |
parent | 4e9b9c402ed95bf9a17fd6d795bc49bb4128a6fa (diff) |
Merge branch 'upstream' into debian-cmake-fixes
Diffstat (limited to 'vendor/jsoncons-0.99.2/jsoncons_ext/boost/type_extensions.hpp')
-rw-r--r-- | vendor/jsoncons-0.99.2/jsoncons_ext/boost/type_extensions.hpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/vendor/jsoncons-0.99.2/jsoncons_ext/boost/type_extensions.hpp b/vendor/jsoncons-0.99.2/jsoncons_ext/boost/type_extensions.hpp new file mode 100644 index 00000000..59936cd7 --- /dev/null +++ b/vendor/jsoncons-0.99.2/jsoncons_ext/boost/type_extensions.hpp @@ -0,0 +1,59 @@ +// Copyright 2013 Daniel Parker +// Distributed under the Boost license, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See https://github.com/danielaparker/jsoncons for latest version + +#ifndef JSONCONS_EXT_TYPE_EXTENSIONS_HPP +#define JSONCONS_EXT_TYPE_EXTENSIONS_HPP + +#include "jsoncons/json.hpp" +#include "boost/date_time/gregorian/gregorian.hpp" + +#if defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wswitch" +#endif + +namespace jsoncons +{ + template <typename JsonT> + class json_type_traits<JsonT,boost::gregorian::date> + { + public: + static bool is(const JsonT& val) JSONCONS_NOEXCEPT + { + if (!val.is_string()) + { + return false; + } + std::string s = val.template as<std::string>(); + try + { + boost::gregorian::date_from_iso_string(s); + return true; + } + catch (...) + { + return false; + } + } + + static boost::gregorian::date as(const JsonT& val) + { + std::string s = val.template as<std::string>(); + return boost::gregorian::from_simple_string(s); + } + + static void assign(JsonT& lhs, boost::gregorian::date val) + { + lhs = to_iso_extended_string(val); + } + }; +} + +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + +#endif |