diff options
| -rw-r--r-- | src/raw_convert.cc | 155 | ||||
| -rw-r--r-- | src/raw_convert.h | 72 | ||||
| -rw-r--r-- | src/wscript | 1 |
3 files changed, 8 insertions, 220 deletions
diff --git a/src/raw_convert.cc b/src/raw_convert.cc deleted file mode 100644 index 720be6f3..00000000 --- a/src/raw_convert.cc +++ /dev/null @@ -1,155 +0,0 @@ -/* - Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net> - - This file is part of libdcp. - - libdcp is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - libdcp is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with libdcp. If not, see <http://www.gnu.org/licenses/>. - - In addition, as a special exception, the copyright holders give - permission to link the code of portions of this program with the - OpenSSL library under certain conditions as described in each - individual source file, and distribute linked combinations - including the two. - - You must obey the GNU General Public License in all respects - for all of the code used other than OpenSSL. If you modify - file(s) with this exception, you may extend this exception to your - version of the file(s), but you are not obligated to do so. If you - do not wish to do so, delete this exception statement from your - version. If you delete this exception statement from all source - files in the program, then also delete it here. -*/ - - -#include "raw_convert.h" -#include "locale_convert.h" -#include <boost/algorithm/string.hpp> - - -using std::string; -static -string -make_local (string v) -{ - struct lconv* lc = localeconv (); - boost::algorithm::replace_all (v, ".", lc->decimal_point); - /* We hope it's ok not to add in thousands separators here */ - return v; -} - - - - -template <> -unsigned char -dcp::raw_convert(string v, int precision, bool fixed) -{ - return locale_convert<unsigned char> (make_local (v), precision, fixed); -} - - -template <> -unsigned short int -dcp::raw_convert(string v, int precision, bool fixed) -{ - return locale_convert<unsigned short int> (make_local (v), precision, fixed); -} - - -template <> -int -dcp::raw_convert (string v, int precision, bool fixed) -{ - return locale_convert<int> (make_local (v), precision, fixed); -} - - -template <> -long -dcp::raw_convert (string v, int precision, bool fixed) -{ - return locale_convert<long> (make_local (v), precision, fixed); -} - - -template <> -unsigned long -dcp::raw_convert (string v, int precision, bool fixed) -{ - return locale_convert<unsigned long> (make_local (v), precision, fixed); -} - - -template <> -long long -dcp::raw_convert (string v, int precision, bool fixed) -{ - return locale_convert<long long> (make_local (v), precision, fixed); -} - - -template <> -unsigned long long -dcp::raw_convert (string v, int precision, bool fixed) -{ - return locale_convert<unsigned long long> (make_local (v), precision, fixed); -} - - -template <> -int -dcp::raw_convert(char* v, int precision, bool fixed) -{ - return locale_convert<int>(make_local (v), precision, fixed); -} - - -template <> -int -dcp::raw_convert (char const * v, int precision, bool fixed) -{ - return locale_convert<int> (make_local (v), precision, fixed); -} - - -template <> -float -dcp::raw_convert (string v, int precision, bool fixed) -{ - return locale_convert<float> (make_local (v), precision, fixed); -} - - -template <> -float -dcp::raw_convert (char const * v, int precision, bool fixed) -{ - return locale_convert<float> (make_local (v), precision, fixed); -} - - -template <> -double -dcp::raw_convert (string v, int precision, bool fixed) -{ - return locale_convert<double> (make_local (v), precision, fixed); -} - - -template <> -double -dcp::raw_convert (char const * v, int precision, bool fixed) -{ - return locale_convert<double> (make_local (v), precision, fixed); -} diff --git a/src/raw_convert.h b/src/raw_convert.h index 8dde240d..98eff4e0 100644 --- a/src/raw_convert.h +++ b/src/raw_convert.h @@ -42,80 +42,24 @@ #include "util.h" -#include <boost/static_assert.hpp> -#include <iomanip> +#include <fast_float/fast_float.h> namespace dcp { -/** A sort-of version of boost::lexical_cast that does uses the "C" - * locale (i.e. no thousands separators and a . for the decimal separator). +/** Wrapper for fast_float::from_chars, which converts strings to numbers using + * the "C" locale (i.e. no thousands separators, . is the decimal separator). */ -template <typename P, typename Q> +template <typename P> P -raw_convert (Q, int precision = 16, bool fixed = false) +raw_convert(std::string v) { - /* We can't write a generic version of raw_convert; all required - versions must be specialised. - */ - BOOST_STATIC_ASSERT (sizeof (Q) == 0); - LIBDCP_UNUSED(precision); - LIBDCP_UNUSED(fixed); + P result = 0; + fast_float::from_chars(v.data(), v.data() + v.size(), result); + return result; } -template <> -unsigned char -raw_convert (std::string v, int, bool); - -template <> -unsigned short int -raw_convert (std::string v, int, bool); - -template <> -int -raw_convert (std::string v, int, bool); - -template <> -long -raw_convert (std::string v, int, bool); - -template <> -unsigned long -raw_convert (std::string v, int, bool); - -template <> -long long -raw_convert (std::string v, int, bool); - -template <> -unsigned long long -raw_convert (std::string v, int, bool); - -template <> -int -raw_convert (char* v, int, bool); - -template <> -int -raw_convert (char const * v, int, bool); - -template <> -float -raw_convert (std::string v, int, bool); - -template <> -float -raw_convert (char const * v, int, bool); - -template <> -double -raw_convert (std::string v, int, bool); - -template <> -double -raw_convert (char const * v, int, bool); - } diff --git a/src/wscript b/src/wscript index dd1d546e..d5dd6d32 100644 --- a/src/wscript +++ b/src/wscript @@ -91,7 +91,6 @@ def build(bld): picture_asset.cc pkl.cc rating.cc - raw_convert.cc reel.cc reel_asset.cc reel_atmos_asset.cc |
