Use an enum class for Marker.
[libdcp.git] / src / locale_convert.cc
index 64b21274915f88c46516590a5bace8f0bb52ed06..915cac826bbe58387977ed1c355c1a5243ed8985 100644 (file)
 #include <inttypes.h>
 
 using std::string;
+using std::wstring;
+
+template<>
+string
+dcp::locale_convert (unsigned char x, int, bool)
+{
+       char buffer[64];
+       snprintf (buffer, sizeof(buffer), "%hhd", x);
+       return buffer;
+}
+
+template<>
+string
+dcp::locale_convert (unsigned short int x, int, bool)
+{
+       char buffer[64];
+       snprintf (buffer, sizeof(buffer), "%hd", x);
+       return buffer;
+}
 
 template<>
 string
@@ -60,7 +79,11 @@ string
 dcp::locale_convert (long int x, int, bool)
 {
        char buffer[64];
+#ifdef LIBDCP_WINDOWS
+       __mingw_snprintf (buffer, sizeof(buffer), "%ld", x);
+#else
        snprintf (buffer, sizeof(buffer), "%ld", x);
+#endif
        return buffer;
 }
 
@@ -150,6 +173,23 @@ dcp::locale_convert (char const * x, int, bool)
        return x;
 }
 
+template<>
+string
+dcp::locale_convert (wchar_t const * x, int, bool)
+{
+       wstring s (x);
+       return string (s.begin(), s.end());
+}
+
+template<>
+string
+dcp::locale_convert (char x, int, bool)
+{
+       string s;
+       s += x;
+       return s;
+}
+
 template<>
 string
 dcp::locale_convert (boost::filesystem::path x, int, bool)
@@ -157,6 +197,33 @@ dcp::locale_convert (boost::filesystem::path x, int, bool)
        return x.string();
 }
 
+template<>
+unsigned char
+dcp::locale_convert (string x, int, bool)
+{
+       unsigned char y = 0;
+       sscanf (x.c_str(), "%hhu", &y);
+       return y;
+}
+
+template<>
+unsigned short int
+dcp::locale_convert (string x, int, bool)
+{
+       unsigned short int y = 0;
+       sscanf (x.c_str(), "%hu", &y);
+       return y;
+}
+
+template<>
+unsigned int
+dcp::locale_convert (string x, int, bool)
+{
+       unsigned int y = 0;
+       sscanf (x.c_str(), "%u", &y);
+       return y;
+}
+
 template<>
 int
 dcp::locale_convert (string x, int, bool)
@@ -167,11 +234,50 @@ dcp::locale_convert (string x, int, bool)
 }
 
 template<>
-int64_t
+long
+dcp::locale_convert (string x, int, bool)
+{
+       long int y = 0;
+       sscanf (x.c_str(), "%ld", &y);
+       return y;
+}
+
+template<>
+unsigned long
+dcp::locale_convert (string x, int, bool)
+{
+       unsigned long y = 0;
+#ifdef LIBDCP_WINDOWS
+       __mingw_sscanf (x.c_str(), "%lud", &y);
+#else
+       sscanf (x.c_str(), "%lud", &y);
+#endif
+       return y;
+}
+
+template<>
+long long
+dcp::locale_convert (string x, int, bool)
+{
+       long long y = 0;
+#ifdef LIBDCP_WINDOWS
+       __mingw_sscanf (x.c_str(), "%lld", &y);
+#else
+       sscanf (x.c_str(), "%lld", &y);
+#endif
+       return y;
+}
+
+template<>
+unsigned long long
 dcp::locale_convert (string x, int, bool)
 {
-       int64_t y = 0;
-       sscanf (x.c_str(), "%" PRId64, &y);
+       unsigned long long y = 0;
+#ifdef LIBDCP_WINDOWS
+       __mingw_sscanf (x.c_str(), "%llud", &y);
+#else
+       sscanf (x.c_str(), "%llud", &y);
+#endif
        return y;
 }