Use an enum class for Marker.
[libdcp.git] / src / raw_convert.cc
index cb7807a3c1712f1218c258fc198b2647d110f744..b4dcb5be92ec41eac566e73a3b8caafbeb49987c 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2014-2016 Carl Hetherington <cth@carlh.net>
 
     This file is part of libdcp.
 
 #include <boost/algorithm/string.hpp>
 
 using std::string;
+using std::wstring;
 
+/** @param v Numeric value as an ASCII string */
 static
 string
 make_raw (string v)
 {
        struct lconv* lc = localeconv ();
-       boost::algorithm::replace_all (v, lc->decimal_point, ".");
+       /* thousands_sep may be . so remove them before changing decimal points */
        boost::algorithm::replace_all (v, lc->thousands_sep, "");
+       boost::algorithm::replace_all (v, lc->decimal_point, ".");
        return v;
 }
 
@@ -57,6 +60,20 @@ make_local (string v)
        return v;
 }
 
+template <>
+string
+dcp::raw_convert (unsigned char v, int precision, bool fixed)
+{
+       return make_raw (locale_convert<string> (v, precision, fixed));
+}
+
+template <>
+string
+dcp::raw_convert (unsigned short int v, int precision, bool fixed)
+{
+       return make_raw (locale_convert<string> (v, precision, fixed));
+}
+
 template <>
 string
 dcp::raw_convert (int v, int precision, bool fixed)
@@ -66,14 +83,35 @@ dcp::raw_convert (int v, int precision, bool fixed)
 
 template <>
 string
-dcp::raw_convert (int64_t v, int precision, bool fixed)
+dcp::raw_convert (unsigned int v, int precision, bool fixed)
 {
        return make_raw (locale_convert<string> (v, precision, fixed));
 }
 
 template <>
 string
-dcp::raw_convert (uint64_t v, int precision, bool fixed)
+dcp::raw_convert (long v, int precision, bool fixed)
+{
+       return make_raw (locale_convert<string> (v, precision, fixed));
+}
+
+template <>
+string
+dcp::raw_convert (unsigned long v, int precision, bool fixed)
+{
+       return make_raw (locale_convert<string> (v, precision, fixed));
+}
+
+template <>
+string
+dcp::raw_convert (long long v, int precision, bool fixed)
+{
+       return make_raw (locale_convert<string> (v, precision, fixed));
+}
+
+template <>
+string
+dcp::raw_convert (unsigned long long v, int precision, bool fixed)
 {
        return make_raw (locale_convert<string> (v, precision, fixed));
 }
@@ -113,6 +151,37 @@ dcp::raw_convert (string v, int, bool)
        return v;
 }
 
+template <>
+string
+dcp::raw_convert (char v, int, bool)
+{
+       string s;
+       s += v;
+       return s;
+}
+
+template <>
+string
+dcp::raw_convert (wchar_t const * v, int, bool)
+{
+       wstring w (v);
+       return string (w.begin(), w.end());
+}
+
+template <>
+unsigned char
+dcp::raw_convert (std::string v, int precision, bool fixed)
+{
+       return locale_convert<unsigned char> (make_local (v), precision, fixed);
+}
+
+template <>
+unsigned short int
+dcp::raw_convert (std::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)
@@ -120,6 +189,34 @@ 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 const * v, int precision, bool fixed)