Rationalise raw/locale_convert stuff and fix build on OS X.
authorCarl Hetherington <cth@carlh.net>
Mon, 15 Aug 2016 09:09:45 +0000 (10:09 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 15 Aug 2016 13:08:03 +0000 (14:08 +0100)
src/compose.hpp
src/locale_convert.cc
src/locale_convert.h
src/raw_convert.cc
src/raw_convert.h

index 4ce60e336cae889381ce550e47bd6c1b9e923e1a..faffc41c2a42cfcc36f1281a6a24fded01831cbc 100644 (file)
@@ -34,6 +34,7 @@
 #ifndef STRING_COMPOSE_H
 #define STRING_COMPOSE_H
 
+#include "locale_convert.h"
 #include <boost/filesystem.hpp>
 #include <string>
 #include <list>
@@ -113,104 +114,11 @@ namespace StringPrivate
     }
   }
 
-  template <typename T>
-  inline void write(std::string& s, const T& obj)
-  {
-    /* Assume anything not specialized has a to_string() method */
-    s += to_string (obj);
-  }
-
-  template <>
-  inline void write(std::string& s, const int64_t& obj)
-  {
-    char buffer[64];
-#ifdef LIBDCP_WINDOWS
-    __mingw_snprintf(buffer, 64, "%" PRId64, obj);
-#else
-    snprintf(buffer, 64, "%" PRId64, obj);
-#endif
-    s += buffer;
-  }
-
-  template <>
-  inline void write(std::string& s, const uint64_t& obj)
-  {
-    char buffer[64];
-#ifdef LIBDCP_WINDOWS
-    __mingw_snprintf(buffer, 64, "%" PRIu64, obj);
-#else
-    snprintf(buffer, 64, "%" PRIu64, obj);
-#endif
-    s += buffer;
-  }
-
-  template <>
-  inline void write(std::string& s, const int& obj)
-  {
-    char buffer[64];
-    snprintf(buffer, 64, "%d", obj);
-    s += buffer;
-  }
-
-  template <>
-  inline void write(std::string& s, const unsigned int& obj)
-  {
-    char buffer[64];
-    snprintf(buffer, 64, "%ud", obj);
-    s += buffer;
-  }
-
-  template <>
-  inline void write(std::string& s, const float& obj)
-  {
-    char buffer[64];
-    snprintf(buffer, 64, "%f", obj);
-    s += buffer;
-  }
-
-  template <>
-  inline void write(std::string& s, const char& obj)
-  {
-    s += obj;
-  }
-
-  template <>
-  inline void write(std::string& s, const double& obj)
-  {
-    char buffer[64];
-    snprintf(buffer, 64, "%f", obj);
-    s += buffer;
-  }
-
-  template <>
-  inline void write(std::string& s, char const * const & obj)
-  {
-    s += obj;
-  }
-
-  template <>
-  inline void write(std::string& s, char* const & obj)
-  {
-    s += obj;
-  }
-
-  template <>
-  inline void write(std::string& s, const std::string& obj)
-  {
-    s += obj;
-  }
-
-  template <>
-  inline void write(std::string& s, const boost::filesystem::path & obj)
-  {
-    s += obj.string();
-  }
-
   // implementation of class Composition
   template <typename T>
   inline Composition &Composition::arg(const T &obj)
   {
-    write(os, obj);
+    os += dcp::locale_convert<std::string> (obj);
 
     if (!os.empty()) {         // manipulators don't produce output
       for (specification_map::const_iterator i = specs.lower_bound(arg_no), end = specs.upper_bound(arg_no); i != end; ++i) {
index 3858006ef6fe78f71498bce8321724af6cebabe8..64b21274915f88c46516590a5bace8f0bb52ed06 100644 (file)
@@ -51,25 +51,51 @@ string
 dcp::locale_convert (unsigned int x, int, bool)
 {
        char buffer[64];
-       snprintf (buffer, sizeof(buffer), "%ud", x);
+       snprintf (buffer, sizeof(buffer), "%u", x);
        return buffer;
 }
 
 template<>
 string
-dcp::locale_convert (int64_t x, int, bool)
+dcp::locale_convert (long int x, int, bool)
 {
        char buffer[64];
-       snprintf (buffer, sizeof(buffer), "%" PRId64, x);
+       snprintf (buffer, sizeof(buffer), "%ld", x);
        return buffer;
 }
 
 template<>
 string
-dcp::locale_convert (uint64_t x, int, bool)
+dcp::locale_convert (unsigned long int x, int, bool)
 {
        char buffer[64];
-       snprintf (buffer, sizeof(buffer), "%" PRIu64, x);
+       snprintf (buffer, sizeof(buffer), "%lu", x);
+       return buffer;
+}
+
+template<>
+string
+dcp::locale_convert (long long int x, int, bool)
+{
+       char buffer[64];
+#ifdef LIBDCP_WINDOWS
+       __mingw_snprintf (buffer, sizeof(buffer), "%lld", x);
+#else
+       snprintf (buffer, sizeof(buffer), "%lld", x);
+#endif
+       return buffer;
+}
+
+template<>
+string
+dcp::locale_convert (unsigned long long int x, int, bool)
+{
+       char buffer[64];
+#ifdef LIBDCP_WINDOWS
+       __mingw_snprintf (buffer, sizeof(buffer), "%llu", x);
+#else
+       snprintf (buffer, sizeof(buffer), "%llu", x);
+#endif
        return buffer;
 }
 
@@ -124,6 +150,13 @@ dcp::locale_convert (char const * x, int, bool)
        return x;
 }
 
+template<>
+string
+dcp::locale_convert (boost::filesystem::path x, int, bool)
+{
+       return x.string();
+}
+
 template<>
 int
 dcp::locale_convert (string x, int, bool)
index f7552f68d267074049efda601366804f727d5bb0..3d55a00ea6835ee12c91a239e423bd95f1d55310 100644 (file)
@@ -34,9 +34,9 @@
 #ifndef LIBDCP_LOCALE_CONVERT_H
 #define LIBDCP_LOCALE_CONVERT_H
 
+#include <boost/filesystem.hpp>
 #include <boost/static_assert.hpp>
 #include <string>
-#include <stdint.h>
 #include <cstdio>
 
 namespace dcp {
@@ -61,11 +61,19 @@ locale_convert (unsigned int x, int, bool);
 
 template <>
 std::string
-locale_convert (int64_t x, int, bool);
+locale_convert (long int x, int, bool);
 
 template <>
 std::string
-locale_convert (uint64_t x, int, bool);
+locale_convert (unsigned long int x, int, bool);
+
+template <>
+std::string
+locale_convert (long long int x, int, bool);
+
+template <>
+std::string
+locale_convert (unsigned long long int x, int, bool);
 
 template <>
 std::string
@@ -87,6 +95,10 @@ template <>
 std::string
 locale_convert (char const * x, int, bool);
 
+template <>
+std::string
+locale_convert (boost::filesystem::path x, int, bool);
+
 template <>
 int
 locale_convert (std::string x, int, bool);
index 5f8c1e41d04c47ea5ba313cb912971e91e5a3bb0..b7685ab8d89b26dc0e10ff50af19361fe60d8843 100644 (file)
@@ -73,14 +73,28 @@ dcp::raw_convert (unsigned int v, int precision, bool fixed)
 
 template <>
 string
-dcp::raw_convert (int64_t v, int precision, bool fixed)
+dcp::raw_convert (long 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 (unsigned long int v, int precision, bool fixed)
+{
+       return make_raw (locale_convert<string> (v, precision, fixed));
+}
+
+template <>
+string
+dcp::raw_convert (long long int 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));
 }
index 585c18fc2910717b4d85e9aecbcf3d8010caf88f..901e99ddf3c034ded9c32155d6248b54b1f4d03d 100644 (file)
@@ -36,7 +36,6 @@
 
 #include <boost/static_assert.hpp>
 #include <iomanip>
-#include <stdint.h>
 
 namespace dcp {
 
@@ -63,11 +62,19 @@ raw_convert (unsigned int v, int, bool);
 
 template <>
 std::string
-raw_convert (int64_t v, int, bool);
+raw_convert (long int v, int, bool);
 
 template <>
 std::string
-raw_convert (uint64_t v, int, bool);
+raw_convert (unsigned long int v, int, bool);
+
+template <>
+std::string
+raw_convert (long long int v, int, bool);
+
+template <>
+std::string
+raw_convert (unsigned long long int v, int, bool);
 
 template <>
 std::string