From 25789d1450d376fe4617402231fda08f2b02733b Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Sat, 8 Dec 2018 19:23:09 +0900 Subject: [PATCH] set Datetime as offset_datetime prepare for TOML v0.5.0 --- toml/types.hpp | 84 +++++++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/toml/types.hpp b/toml/types.hpp index 78fb149..a1b94e6 100644 --- a/toml/types.hpp +++ b/toml/types.hpp @@ -1,6 +1,7 @@ #ifndef TOML11_TYPES_H #define TOML11_TYPES_H #include "datetime.hpp" +#include "traits.hpp" #include #include #include @@ -18,7 +19,7 @@ using Boolean = bool; using Integer = std::int64_t; using Float = double; using String = std::basic_string; -using Datetime = basic_datetime; +using Datetime = offset_datetime; using Array = std::vector; using Table = std::unordered_map; @@ -27,60 +28,64 @@ using boolean = Boolean; using integer = Integer; using floating = Float; // XXX float is keyword using string = String; -using datetime = Datetime; +// these are defined in datetime.hpp +// offset_datetime +// local_datetime +// local_date +// local_time using array = Array; using table = Table; enum class value_t : std::uint8_t { - Boolean = 1, - Integer = 2, - Float = 3, - String = 4, - Datetime = 5, - Array = 6, - Table = 7, - Empty = 0, - Unknown = 255, + Boolean = 1, + Integer = 2, + Float = 3, + String = 4, + Datetime = 5, + LocalDatetime = 6, + LocalDate = 7, + LocalTime = 8, + Array = 9, + Table = 10, + Empty = 0, + Unknown = 255, }; -template> +constexpr inline bool is_valid(value_t vt) +{ + return vt != value_t::Unknown; +} + +template inline std::basic_ostream& operator<<(std::basic_ostream& os, value_t t) { switch(t) { - case toml::value_t::Boolean : os << "Boolean"; return os; - case toml::value_t::Integer : os << "Integer"; return os; - case toml::value_t::Float : os << "Float"; return os; - case toml::value_t::String : os << "String"; return os; - case toml::value_t::Datetime: os << "Datetime"; return os; - case toml::value_t::Array : os << "Array"; return os; - case toml::value_t::Table : os << "Table"; return os; - case toml::value_t::Empty : os << "Empty"; return os; - case toml::value_t::Unknown : os << "Unknown"; return os; - default : os << "Nothing"; return os; + case toml::value_t::Boolean : os << "boolean"; return os; + case toml::value_t::Integer : os << "integer"; return os; + case toml::value_t::Float : os << "float"; return os; + case toml::value_t::String : os << "string"; return os; + case toml::value_t::Datetime : os << "offset_datetime"; return os; + case toml::value_t::LocalDatetime: os << "local_datetime"; return os; + case toml::value_t::LocalDate : os << "local_date"; return os; + case toml::value_t::LocalTime : os << "local_time"; return os; + case toml::value_t::Array : os << "array"; return os; + case toml::value_t::Table : os << "table"; return os; + case toml::value_t::Empty : os << "empty"; return os; + case toml::value_t::Unknown : os << "unknown"; return os; + default : os << "nothing"; return os; } } template, typename alloc = std::allocator> -inline std::basic_string -stringize(value_t t) +inline std::basic_string stringize(value_t t) { - switch(t) - { - case toml::value_t::Boolean : return "Boolean"; - case toml::value_t::Integer : return "Integer"; - case toml::value_t::Float : return "Float"; - case toml::value_t::String : return "String"; - case toml::value_t::Datetime: return "Datetime"; - case toml::value_t::Array : return "Array"; - case toml::value_t::Table : return "Table"; - case toml::value_t::Empty : return "Empty"; - case toml::value_t::Unknown : return "Unknown"; - default : return "Nothing"; - } + std::ostringstream oss; + oss << t; + return oss.str(); } namespace detail @@ -99,11 +104,6 @@ constexpr inline value_t check_type() value_t::Unknown; } -constexpr inline bool is_valid(value_t vt) -{ - return vt != value_t::Unknown; -} - template struct toml_default_type{}; template<> struct toml_default_type{typedef Boolean type;}; template<> struct toml_default_type{typedef Integer type;};