// Copyright Toru Niina 2017. // Distributed under the MIT License. #ifndef TOML11_TYPES_HPP #define TOML11_TYPES_HPP #include "datetime.hpp" #include "string.hpp" #include "traits.hpp" #include "comments.hpp" namespace toml { template Table, // map-like class template Array> // vector-like class class basic_value; using character = char; using key = std::string; using boolean = bool; using integer = std::int64_t; using floating = double; // "float" is a keyward, cannot use it here. // the following stuffs are structs defined here, so aliases are not needed. // - string // - offset_datetime // - offset_datetime // - local_datetime // - local_date // - local_time // default toml::value and default array/table using value = basic_value; enum class value_t : std::uint8_t { empty = 0, boolean = 1, integer = 2, floating = 3, string = 4, offset_datetime = 5, local_datetime = 6, local_date = 7, local_time = 8, array = 9, table = 10, }; template inline std::basic_ostream& operator<<(std::basic_ostream& os, value_t t) { switch(t) { case value_t::boolean : os << "boolean"; return os; case value_t::integer : os << "integer"; return os; case value_t::floating : os << "floating"; return os; case value_t::string : os << "string"; return os; case value_t::offset_datetime : os << "offset_datetime"; return os; case value_t::local_datetime : os << "local_datetime"; return os; case value_t::local_date : os << "local_date"; return os; case value_t::local_time : os << "local_time"; return os; case value_t::array : os << "array"; return os; case value_t::table : os << "table"; return os; case value_t::empty : os << "empty"; return os; default : os << "unknown"; return os; } } template, typename alloc = std::allocator> inline std::basic_string stringize(value_t t) { std::basic_ostringstream oss; oss << t; return oss.str(); } namespace detail { // helper to define a type that represents a value_t value. template using value_t_constant = std::integral_constant; // meta-function that convertes from value_t to the exact toml type that corresponds to. // It takes toml::basic_value type because array and table types depend on it. template struct enum_to_type {using type = void ;}; template struct enum_to_type{using type = void ;}; template struct enum_to_type{using type = boolean ;}; template struct enum_to_type{using type = integer ;}; template struct enum_to_type{using type = floating ;}; template struct enum_to_type{using type = string ;}; template struct enum_to_type{using type = offset_datetime ;}; template struct enum_to_type{using type = local_datetime ;}; template struct enum_to_type{using type = local_date ;}; template struct enum_to_type{using type = local_time ;}; template struct enum_to_type{using type = typename Value::array_type;}; template struct enum_to_type{using type = typename Value::table_type;}; // meta-function that converts from an exact toml type to the enum that corresponds to. template struct type_to_enum : typename std::conditional< std::is_same::value, // if T == array_type, value_t_constant, // then value_t::array typename std::conditional< // else... std::is_same::value, // if T == table_type value_t_constant, // then value_t::table value_t_constant // else value_t::empty >::type >::type {} template struct type_to_enum: value_t_constant {}; template struct type_to_enum: value_t_constant {}; template struct type_to_enum: value_t_constant {}; template struct type_to_enum: value_t_constant {}; template struct type_to_enum: value_t_constant {}; template struct type_to_enum: value_t_constant {}; template struct type_to_enum: value_t_constant {}; template struct type_to_enum: value_t_constant {}; // meta-function that checks the type T is the same as one of the toml::* types. template struct is_exact_toml_type : disjunction< std::is_same, std::is_same, std::is_same, std::is_same, std::is_same, std::is_same, std::is_same, std::is_same, std::is_same, std::is_same >{}; template struct is_exact_toml_type : is_exact_toml_type{}; template struct is_exact_toml_type : is_exact_toml_type{}; template struct is_exact_toml_type : is_exact_toml_type{}; template struct is_exact_toml_type: is_exact_toml_type{}; } // detail } // toml #endif// TOML11_TYPES_H