Add new write() method.
[libdcp.git] / src / compose.hpp
index 4ce60e336cae889381ce550e47bd6c1b9e923e1a..41a4075a86e4d3f5419d90bf5bb7034dc34f476d 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>
@@ -41,6 +42,8 @@
 #include <inttypes.h>
 #include <cstdio>
 
+namespace dcp {
+
 namespace StringPrivate
 {
   // the actual composition class - using string::compose is cleaner, so we
@@ -113,104 +116,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) {
@@ -480,5 +390,6 @@ namespace String
   }
 }
 
+}
 
 #endif // STRING_COMPOSE_H