aboutsummaryrefslogtreecommitdiff
path: root/libbutl
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2017-05-16 17:44:28 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2017-05-16 17:44:28 +0300
commitcf9d0332f6b4dcd7dc388133ffd8fd6edd07e1c1 (patch)
tree109d6ec69c93920d2db08f7ec072ba8de270a032 /libbutl
parented3f024f40771c90e0eb7ef5a51e7e01ab0247d4 (diff)
Add to_string(timestamp)
Diffstat (limited to 'libbutl')
-rw-r--r--libbutl/path.cxx4
-rw-r--r--libbutl/process.cxx2
-rw-r--r--libbutl/process.hxx4
-rw-r--r--libbutl/timestamp.cxx13
-rw-r--r--libbutl/timestamp.hxx9
5 files changed, 28 insertions, 4 deletions
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<char>::string_type path_traits<char>::
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 <sys/types.h> // pid_t
#endif
+#include <string>
#include <vector>
#include <iosfwd>
#include <cassert>
@@ -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 <ctime> // tm, time_t, mktime()
#include <cstdlib> // strtoull()
#include <cassert>
+#include <sstream>
#include <iomanip> // put_time(), setw(), dec, right
#include <cstring> // strlen(), memcpy()
#include <ostream>
@@ -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 <ctime> // tm
#include <locale>
#include <clocale>
-#include <sstream>
#include <iomanip>
#include <cstring> // 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)
{