aboutsummaryrefslogtreecommitdiff
path: root/build/path-io.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-04-20 13:01:46 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-04-20 13:01:46 +0200
commita82cdb8fd9ba02034d296769772cdf81244da66a (patch)
tree2cd5fb0211984716780ce5fad18c19d7c4d9a794 /build/path-io.cxx
parentc775a7f28a56ef96f097e677434eceec9d8f2cdf (diff)
Automatically decide when to print relative/absolute paths
Diffstat (limited to 'build/path-io.cxx')
-rw-r--r--build/path-io.cxx38
1 files changed, 38 insertions, 0 deletions
diff --git a/build/path-io.cxx b/build/path-io.cxx
new file mode 100644
index 0000000..80a14e0
--- /dev/null
+++ b/build/path-io.cxx
@@ -0,0 +1,38 @@
+// file : build/path-io.cxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2015 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+#include <build/path-io>
+
+#include <ostream>
+
+#include <build/diagnostics>
+
+using namespace std;
+
+namespace build
+{
+ ostream&
+ operator<< (ostream& os, const path& p)
+ {
+ return os << (relative (os) ? diag_relative (p) : p.string ());
+ }
+
+ ostream&
+ operator<< (ostream& os, const dir_path& d)
+ {
+ if (relative (os))
+ os << diag_relative (d);
+ else
+ {
+ const string& s (d.string ());
+
+ // Print the directory with trailing '/'.
+ //
+ if (!s.empty ())
+ os << s << (dir_path::traits::is_separator (s.back ()) ? "" : "/");
+ }
+
+ return os;
+ }
+}