From f06d6df4df26a87e586ce65bfdf97b74cf5083cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20=C3=81vila=20de=20Esp=C3=ADndola?= Date: Wed, 20 Nov 2019 10:12:12 -0800 Subject: [PATCH] types: Simplify casts to string MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These now just use the to_string member functions, which makes it possible to move the code to another file. Signed-off-by: Rafael Ávila de Espíndola Message-Id: <20191120181213.111758-8-espindola@scylladb.com> --- types.cc | 64 ++++++++++++++------------------------------------------ 1 file changed, 16 insertions(+), 48 deletions(-) diff --git a/types.cc b/types.cc index a0bc39775b..2d2d06be9c 100644 --- a/types.cc +++ b/types.cc @@ -3133,40 +3133,9 @@ std::function make_castas_fctn_from_timeuuid_to_date() { }; } -std::function make_castas_fctn_from_timestamp_to_string() { +static std::function make_castas_fctn_from_dv_to_string() { return [](data_value from) -> data_value { - const auto val_from = value_cast(from); - return time_point_to_string(val_from); - }; -} - -std::function make_castas_fctn_from_simple_date_to_string() { - return [](data_value from) -> data_value { - return simple_date_to_string(value_cast(from)); - }; -} - -std::function make_castas_fctn_from_time_to_string() { - return [](data_value from) -> data_value { - return time_to_string(value_cast(from)); - }; -} - -std::function make_castas_fctn_from_uuid_to_string() { - return [](data_value from) -> data_value { - return value_cast(from).to_sstring(); - }; -} - -std::function make_castas_fctn_from_boolean_to_string() { - return [](data_value from) -> data_value { - return boolean_to_string(value_cast(from)); - }; -} - -std::function make_castas_fctn_from_inet_to_string() { - return [](data_value from) -> data_value { - return inet_addr_type_impl::to_sstring(value_cast(from)); + return from.type()->to_string_impl(from); }; } @@ -3279,23 +3248,22 @@ thread_local castas_fctns_map castas_fctns { { {timestamp_type, simple_date_type}, make_castas_fctn_from_date_to_timestamp() }, { {timestamp_type, timeuuid_type}, make_castas_fctn_from_timeuuid_to_timestamp() }, - { {ascii_type, timestamp_type}, make_castas_fctn_from_timestamp_to_string() }, - { {ascii_type, simple_date_type}, make_castas_fctn_from_simple_date_to_string() }, - { {ascii_type, time_type}, make_castas_fctn_from_time_to_string() }, - { {ascii_type, timeuuid_type}, make_castas_fctn_from_uuid_to_string() }, - { {ascii_type, uuid_type}, make_castas_fctn_from_uuid_to_string() }, - { {ascii_type, boolean_type}, make_castas_fctn_from_boolean_to_string() }, - { {ascii_type, inet_addr_type}, make_castas_fctn_from_inet_to_string() }, + { {ascii_type, timestamp_type}, make_castas_fctn_from_dv_to_string() }, + { {ascii_type, simple_date_type}, make_castas_fctn_from_dv_to_string() }, + { {ascii_type, time_type}, make_castas_fctn_from_dv_to_string() }, + { {ascii_type, timeuuid_type}, make_castas_fctn_from_dv_to_string() }, + { {ascii_type, uuid_type}, make_castas_fctn_from_dv_to_string() }, + { {ascii_type, boolean_type}, make_castas_fctn_from_dv_to_string() }, + { {ascii_type, inet_addr_type}, make_castas_fctn_from_dv_to_string() }, { {ascii_type, ascii_type}, make_castas_fctn_simple() }, - { {utf8_type, timestamp_type}, make_castas_fctn_from_timestamp_to_string() }, - { {utf8_type, simple_date_type}, make_castas_fctn_from_simple_date_to_string() }, - { {utf8_type, time_type}, make_castas_fctn_from_time_to_string() }, - { {utf8_type, timeuuid_type}, make_castas_fctn_from_uuid_to_string() }, - { {utf8_type, uuid_type}, make_castas_fctn_from_uuid_to_string() }, - { {utf8_type, boolean_type}, make_castas_fctn_from_boolean_to_string() }, - { {utf8_type, boolean_type}, make_castas_fctn_from_boolean_to_string() }, - { {utf8_type, inet_addr_type}, make_castas_fctn_from_inet_to_string() }, + { {utf8_type, timestamp_type}, make_castas_fctn_from_dv_to_string() }, + { {utf8_type, simple_date_type}, make_castas_fctn_from_dv_to_string() }, + { {utf8_type, time_type}, make_castas_fctn_from_dv_to_string() }, + { {utf8_type, timeuuid_type}, make_castas_fctn_from_dv_to_string() }, + { {utf8_type, uuid_type}, make_castas_fctn_from_dv_to_string() }, + { {utf8_type, boolean_type}, make_castas_fctn_from_dv_to_string() }, + { {utf8_type, inet_addr_type}, make_castas_fctn_from_dv_to_string() }, { {utf8_type, ascii_type}, make_castas_fctn_simple() }, { {utf8_type, utf8_type}, make_castas_fctn_simple() }, };