aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-12-17 09:13:30 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-12-17 09:13:30 +0200
commitb1cd193f1bd28837a00cbe6629f9a562f99d961f (patch)
tree4b8a8e1ed3923a7b81c85038d99d002a2b246cd3
parentc90760488f8a11886d2bb2baee4cc2714ac2fc83 (diff)
Add to_string(process_exit) in addition to operator<<(ostream,process_exit)
-rw-r--r--libbutl/process.cxx18
-rw-r--r--libbutl/process.mxx14
2 files changed, 22 insertions, 10 deletions
diff --git a/libbutl/process.cxx b/libbutl/process.cxx
index f6c498e..5505fde 100644
--- a/libbutl/process.cxx
+++ b/libbutl/process.cxx
@@ -106,19 +106,25 @@ namespace butl
{
// process_exit
//
- ostream&
- operator<< (ostream& os, process_exit pe)
+ LIBBUTL_SYMEXPORT string
+ to_string (process_exit pe)
{
+ string r;
+
if (pe.normal ())
- os << "exited with code " << static_cast<uint16_t> (pe.code ());
+ {
+ r = "exited with code ";
+ r += std::to_string (pe.code ());
+ }
else
{
- os << "terminated abnormally: " << pe.description ();
+ r = "terminated abnormally: ";
+ r += pe.description ();
if (pe.core ())
- os << " (core dumped)";
+ r += " (core dumped)";
}
- return os;
+ return r;
}
// process
diff --git a/libbutl/process.mxx b/libbutl/process.mxx
index 27c13fa..199273b 100644
--- a/libbutl/process.mxx
+++ b/libbutl/process.mxx
@@ -15,7 +15,7 @@
#ifndef __cpp_lib_modules
#include <string>
#include <vector>
-#include <iosfwd>
+#include <ostream>
#include <cstddef> // size_t
#include <cstdint> // uint32_t
#include <system_error>
@@ -200,7 +200,7 @@ LIBBUTL_MODEXPORT namespace butl
description () const;
};
- // Print canonical exit status diagnostics:
+ // Canonical exit status description:
//
// "terminated abnormally: <...> (core dumped)"
// "exited with code <...>"
@@ -209,8 +209,14 @@ LIBBUTL_MODEXPORT namespace butl
//
// cerr << "process " << args[0] << " " << *pr.exit << endl;
//
- LIBBUTL_SYMEXPORT std::ostream&
- operator<< (std::ostream&, process_exit);
+ LIBBUTL_SYMEXPORT std::string
+ to_string (process_exit);
+
+ inline std::ostream&
+ operator<< (std::ostream& os, process_exit pe)
+ {
+ return os << to_string (pe);
+ }
class LIBBUTL_SYMEXPORT process
{