diff --git a/toml/types.hpp b/toml/types.hpp index ef413df..315f0e5 100644 --- a/toml/types.hpp +++ b/toml/types.hpp @@ -1,11 +1,10 @@ #ifndef TOML11_TYPES_H #define TOML11_TYPES_H #include "datetime.hpp" +#include "string.hpp" #include "traits.hpp" -#include #include #include -#include namespace toml { @@ -13,26 +12,24 @@ namespace toml using character = char; class value; -using key = std::basic_string; +using key = std::string; -using Boolean = bool; -using Integer = std::int64_t; -using Float = double; -using String = std::basic_string; -using Datetime = offset_datetime; -using Array = std::vector; -using Table = std::unordered_map; +using Boolean = bool; +using Integer = std::int64_t; +using Float = double; +using String = ::toml::string; +using Datetime = offset_datetime; +using OffsetDatetime = offset_datetime; +using LocalDatetime = local_datetime; +using LocalDate = local_date; +using LocalTime = local_time; +using Array = std::vector; +using Table = std::unordered_map; // alias for snake_case, consistency with STL/Boost, toml::key, toml::value using boolean = Boolean; using integer = Integer; -using floating = Float; // XXX float is keyword -using string = String; -// these are defined in datetime.hpp -// offset_datetime -// local_datetime -// local_date -// local_time +using floating = Float; // XXX `float` is keyword. we can't use it here using array = Array; using table = Table; @@ -52,30 +49,25 @@ enum class value_t : std::uint8_t Unknown = 255, }; -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 << "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; + 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::OffsetDatetime: 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; } } @@ -90,33 +82,50 @@ inline std::basic_string stringize(value_t t) namespace detail { +template struct is_chrono_duration: std::false_type{}; +template +struct is_chrono_duration>: std::true_type{}; template constexpr inline value_t check_type() { - return std::is_same, toml::Boolean >::value ? value_t::Boolean : - std::is_integral>::value ? value_t::Integer : - std::is_floating_point>::value ? value_t::Float : - std::is_convertible, toml::String >::value ? value_t::String : - std::is_convertible, toml::Datetime>::value ? value_t::Datetime: - std::is_convertible, toml::Array >::value ? value_t::Array : - std::is_convertible, toml::Table >::value ? value_t::Table : + using type = typename std::remove_cv< + typename std::remove_reference::type + >::type; + return std::is_same::value ? value_t::Boolean : + std::is_integral::value ? value_t::Integer : + std::is_floating_point::value ? value_t::Float : + std::is_same::value ? value_t::String : + std::is_same::value ? value_t::String : + std::is_same::value ? value_t::LocalDate : + std::is_same::value ? value_t::LocalTime : + is_chrono_duration::value ? value_t::LocalTime : + std::is_same::value ? value_t::LocalDatetime : + std::is_same::value ? value_t::OffsetDatetime : + std::is_same::value ? value_t::OffsetDatetime : + std::is_convertible::value ? value_t::Array : + std::is_convertible::value ? value_t::Table : 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;}; -template<> struct toml_default_type {typedef Float type;}; -template<> struct toml_default_type {typedef String type;}; -template<> struct toml_default_type {typedef offset_datetime type;}; -template<> struct toml_default_type{typedef local_datetime type;}; -template<> struct toml_default_type {typedef local_date type;}; -template<> struct toml_default_type {typedef local_time type;}; -template<> struct toml_default_type {typedef Array type;}; -template<> struct toml_default_type {typedef Table type;}; -template<> struct toml_default_type {typedef void type;}; -template<> struct toml_default_type {typedef void type;}; +template<> struct toml_default_type {typedef boolean type;}; +template<> struct toml_default_type {typedef integer type;}; +template<> struct toml_default_type {typedef floating type;}; +template<> struct toml_default_type {typedef string type;}; +template<> struct toml_default_type{typedef offset_datetime type;}; +template<> struct toml_default_type {typedef local_datetime type;}; +template<> struct toml_default_type {typedef local_date type;}; +template<> struct toml_default_type {typedef local_time type;}; +template<> struct toml_default_type {typedef array type;}; +template<> struct toml_default_type {typedef table type;}; +template<> struct toml_default_type {typedef void type;}; +template<> struct toml_default_type {typedef void type;}; template struct is_exact_toml_type : disjunction<