From cf9d0332f6b4dcd7dc388133ffd8fd6edd07e1c1 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Tue, 16 May 2017 17:44:28 +0300 Subject: Add to_string(timestamp) --- libbutl/path.cxx | 4 ++++ libbutl/process.cxx | 2 +- libbutl/process.hxx | 4 ++-- libbutl/timestamp.cxx | 13 ++++++++++++- libbutl/timestamp.hxx | 9 +++++++++ 5 files changed, 28 insertions(+), 4 deletions(-) (limited to 'libbutl') diff --git a/libbutl/path.cxx b/libbutl/path.cxx index 61088bf..be8bd61 100644 --- a/libbutl/path.cxx +++ b/libbutl/path.cxx @@ -174,6 +174,10 @@ namespace butl LIBBUTL_EXPORT path_traits::string_type path_traits:: temp_name (string_type const& prefix) { + // Otherwise compiler get confused with butl::to_string(timestamp). + // + using std::to_string; + return prefix + "-" + to_string (process::current_id ()) + "-" + to_string (temp_name_count++); diff --git a/libbutl/process.cxx b/libbutl/process.cxx index af5cc73..53dd282 100644 --- a/libbutl/process.cxx +++ b/libbutl/process.cxx @@ -577,7 +577,7 @@ namespace butl case SIGXFSZ: return "file size limit exceeded (SIGXFSZ)"; case 0: return "status unknown"; - default: return "unknown signal " + to_string (signal ()); + default: return "unknown signal " + std::to_string (signal ()); } } diff --git a/libbutl/process.hxx b/libbutl/process.hxx index 799313e..1f82af0 100644 --- a/libbutl/process.hxx +++ b/libbutl/process.hxx @@ -9,6 +9,7 @@ # include // pid_t #endif +#include #include #include #include @@ -477,8 +478,7 @@ namespace butl inline const char* process_arg_as (const T& x, std::string& storage) { - using namespace std; - return (storage = to_string (x)).c_str (); + return (storage = std::to_string (x)).c_str (); } inline const char* diff --git a/libbutl/timestamp.cxx b/libbutl/timestamp.cxx index 1f12f41..cf84dd5 100644 --- a/libbutl/timestamp.cxx +++ b/libbutl/timestamp.cxx @@ -10,6 +10,7 @@ #include // tm, time_t, mktime() #include // strtoull() #include +#include #include // put_time(), setw(), dec, right #include // strlen(), memcpy() #include @@ -219,6 +220,17 @@ namespace butl return os; } + string + to_string (const timestamp& ts, + const char* format, + bool special, + bool local) + { + ostringstream o; + to_stream (o, ts, format, special, local); + return o.str (); + } + ostream& operator<< (ostream& os, const duration& d) { @@ -338,7 +350,6 @@ extern "C" #include // tm #include #include -#include #include #include // strlen() diff --git a/libbutl/timestamp.hxx b/libbutl/timestamp.hxx index 1a960b7..9fb0f59 100644 --- a/libbutl/timestamp.hxx +++ b/libbutl/timestamp.hxx @@ -88,6 +88,15 @@ namespace butl bool special, bool local); + // Same as above, but provide the result as string. Note that it is + // implemented via to_stream() and std::ostringstream. + // + LIBBUTL_EXPORT std::string + to_string (const timestamp&, + const char* format, + bool special, + bool local); + inline std::ostream& operator<< (std::ostream& os, const timestamp& ts) { -- cgit v1.1