From adb436dd6612c5238537fe5889027a86c71c8c7b Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Sun, 16 Apr 2017 16:37:19 +0900 Subject: [PATCH] rename enum type -> value_t --- toml.hpp | 148 ++++++++++++++++++++++++++----------------------------- 1 file changed, 69 insertions(+), 79 deletions(-) diff --git a/toml.hpp b/toml.hpp index a69afff..e906d58 100644 --- a/toml.hpp +++ b/toml.hpp @@ -50,7 +50,7 @@ using Datetime = std::chrono::system_clock::time_point; using Array = std::vector; using Table = std::map; -enum class type +enum class value_t { Boolean, Integer, @@ -64,18 +64,18 @@ enum class type template inline std::basic_ostream& -operator<<(std::basic_ostream& os, type t) +operator<<(std::basic_ostream& os, value_t t) { switch(t) { - case toml::type::Boolean : os << "Boolean"; return os; - case toml::type::Integer : os << "Integer"; return os; - case toml::type::Float : os << "Float"; return os; - case toml::type::String : os << "String"; return os; - case toml::type::Datetime: os << "Datetime"; return os; - case toml::type::Array : os << "Array"; return os; - case toml::type::Table : os << "Table"; return os; - case toml::type::Unknown : os << "Unknown"; 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 << "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::Unknown : os << "Unknown"; return os; default : os << "Nothing"; return os; } } @@ -83,19 +83,19 @@ operator<<(std::basic_ostream& os, type t) template, typename alloc = std::allocator> inline std::basic_string -stringize(type t) +stringize(value_t t) { switch(t) { - case toml::type::Boolean : return "Boolean"; - case toml::type::Integer : return "Integer"; - case toml::type::Float : return "Float"; - case toml::type::String : return "String"; - case toml::type::Datetime: return "Datetime"; - case toml::type::Array : return "Array"; - case toml::type::Table : return "Table"; - case toml::type::Unknown : return "Unknown"; - default : return "Nothing"; + 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::Unknown : return "Unknown"; + default : return "Nothing"; } } @@ -125,36 +125,27 @@ template struct is_table> : std::true_type{}; template -constexpr inline type check_type() +constexpr inline value_t check_type() { - return std::is_same, bool>::value ? type::Boolean : - std::is_integral>::value ? type::Integer : - std::is_floating_point>::value ? type::Float : - std::is_same, std::string>::value ? type::String : - std::is_same, const char*>::value ? type::String : - toml::detail::is_array>::value ? type::Array : - toml::detail::is_table>::value ? type::Table : - type::Unknown; + return std::is_same, bool>::value ? value_t::Boolean : + std::is_integral>::value ? value_t::Integer : + std::is_floating_point>::value ? value_t::Float : + std::is_same, std::string>::value ? value_t::String : + std::is_same, const char*>::value ? value_t::String : + toml::detail::is_array>::value ? value_t::Array : + toml::detail::is_table>::value ? value_t::Table : + 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 Datetime 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{}; +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 Datetime 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;}; } // detail @@ -203,9 +194,9 @@ struct internal_error : public toml::exception template struct value_traits { - constexpr static type type_index = detail::check_type(); - constexpr static bool is_toml_value = (type_index != type::Unknown); - typedef typename detail::toml_default_type::type value_type; + constexpr static value_t type_index = detail::check_type(); + constexpr static bool is_toml_value = (type_index != value_t::Unknown); + typedef typename detail::toml_default_type::type type; }; class value @@ -220,7 +211,6 @@ class value switch_assign()>::invoke( *this, std::forward(v)); } - ~value() { switch_clean(this->type_); @@ -228,7 +218,7 @@ class value type t() const {return type_;} - template + template typename detail::toml_default_type::type const& cast() const { if(T != type_) @@ -238,7 +228,7 @@ class value return switch_cast::invoke(*this); } - template + template typename detail::toml_default_type::type& cast() { if(T != type_) @@ -259,28 +249,28 @@ class value private: - void switch_clean(type t) + void switch_clean(value_t t) { switch(t) { - case type::Boolean : boolean_.~Boolean(); return; - case type::Integer : integer_.~Integer(); return; - case type::Float : float_.~Float(); return; - case type::String : string_.~String(); return; - case type::Datetime: datetime_.~Datetime(); return; - case type::Array : array_.~Array(); return; - case type::Table : table_.~Table(); return; - case type::Unknown : return; + case value_t::Boolean : boolean_.~Boolean(); return; + case value_t::Integer : integer_.~Integer(); return; + case value_t::Float : float_.~Float(); return; + case value_t::String : string_.~String(); return; + case value_t::Datetime: datetime_.~Datetime(); return; + case value_t::Array : array_.~Array(); return; + case value_t::Table : table_.~Table(); return; + case value_t::Unknown : return; default: assert(false); } } - template struct switch_assign; - template struct switch_cast; + template struct switch_assign; + template struct switch_cast; private: - type type_; + value_t type_; union { Boolean boolean_; @@ -293,7 +283,7 @@ class value }; }; -template<> struct value::switch_assign +template<> struct value::switch_assign { template static void invoke(value& v, valT&& val) @@ -301,7 +291,7 @@ template<> struct value::switch_assign v.boolean_ = std::forward(val); } }; -template<> struct value::switch_assign +template<> struct value::switch_assign { template static void invoke(value& v, valT&& val) @@ -309,7 +299,7 @@ template<> struct value::switch_assign v.integer_ = std::forward(val); } }; -template<> struct value::switch_assign +template<> struct value::switch_assign { template static void invoke(value& v, valT&& val) @@ -317,7 +307,7 @@ template<> struct value::switch_assign v.float_ = std::forward(val); } }; -template<> struct value::switch_assign +template<> struct value::switch_assign { template static void invoke(value& v, valT&& val) @@ -325,7 +315,7 @@ template<> struct value::switch_assign new(&v.string_) String(val); } }; -template<> struct value::switch_assign +template<> struct value::switch_assign { template static void invoke(value& v, valT&& val) @@ -333,7 +323,7 @@ template<> struct value::switch_assign new(&v.datetime_) Datetime(val); } }; -template<> struct value::switch_assign +template<> struct value::switch_assign { template static void invoke(value& v, valT&& val) @@ -341,7 +331,7 @@ template<> struct value::switch_assign new(&v.array_) Array(val); } }; -template<> struct value::switch_assign +template<> struct value::switch_assign { template static void invoke(value& v, valT&& val) @@ -350,37 +340,37 @@ template<> struct value::switch_assign } }; -template<> struct value::switch_cast +template<> struct value::switch_cast { static Boolean& invoke(value& v) {return v.boolean_;} static Boolean const& invoke(value const& v) {return v.boolean_;} }; -template<> struct value::switch_cast +template<> struct value::switch_cast { static Integer& invoke(value& v) {return v.integer_;} static Integer const& invoke(value const& v) {return v.integer_;} }; -template<> struct value::switch_cast +template<> struct value::switch_cast { static Float& invoke(value& v) {return v.float_;} static Float const& invoke(value const& v) {return v.float_;} }; -template<> struct value::switch_cast +template<> struct value::switch_cast { static String& invoke(value& v) {return v.string_;} static String const& invoke(value const& v) {return v.string_;} }; -template<> struct value::switch_cast +template<> struct value::switch_cast { static Datetime& invoke(value& v) {return v.datetime_;} static Datetime const& invoke(value const& v) {return v.datetime_;} }; -template<> struct value::switch_cast +template<> struct value::switch_cast { static Array& invoke(value& v) {return v.array_;} static Array const& invoke(value const& v) {return v.array_;} }; -template<> struct value::switch_cast +template<> struct value::switch_cast { static Table& invoke(value& v) {return v.table_;} static Table const& invoke(value const& v) {return v.table_;}