aboutsummaryrefslogtreecommitdiff
path: root/cutl/fs/path.hxx
diff options
context:
space:
mode:
Diffstat (limited to 'cutl/fs/path.hxx')
-rw-r--r--cutl/fs/path.hxx97
1 files changed, 97 insertions, 0 deletions
diff --git a/cutl/fs/path.hxx b/cutl/fs/path.hxx
new file mode 100644
index 0000000..a79fc5c
--- /dev/null
+++ b/cutl/fs/path.hxx
@@ -0,0 +1,97 @@
+// file : cutl/fs/path.hxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2009 Code Synthesis Tools CC
+// license : MIT; see accompanying LICENSE file
+
+#ifndef CUTL_FS_PATH_HXX
+#define CUTL_FS_PATH_HXX
+
+#include <string>
+#include <iosfwd>
+
+namespace cutl
+{
+ namespace fs
+ {
+ struct invalid_path: std::exception
+ {
+ virtual char const*
+ what () const throw ();
+ };
+
+ template <typename C>
+ class basic_path;
+
+ typedef basic_path<char> path;
+ typedef basic_path<wchar_t> wpath;
+
+ template <typename C>
+ class basic_path
+ {
+ public:
+ typedef std::basic_string<C> string_type;
+ typedef typename string_type::size_type size_type;
+
+ explicit
+ basic_path (C const* s)
+ : path_ (s)
+ {
+ init (false);
+ }
+
+ explicit
+ basic_path (string_type const& s)
+ : path_ (s)
+ {
+ init (false);
+ }
+
+ public:
+ basic_path
+ leaf () const;
+
+ basic_path
+ directory () const;
+
+ basic_path
+ base () const;
+
+ public:
+ basic_path
+ operator/ (basic_path const&);
+
+ public:
+ string_type
+ string () const
+ {
+ return path_.empty () ? string_type (1, '/') : path_;
+ }
+
+ private:
+ void
+ init (bool internal);
+
+ // Assume internal format.
+ //
+ basic_path (C const* s, size_type n)
+ : path_ (s, n)
+ {
+ init (true);
+ }
+
+ private:
+ string_type path_;
+ };
+
+ template <typename C>
+ inline std::basic_ostream<C>&
+ operator<< (std::basic_ostream<C>& os, basic_path<C> const& p)
+ {
+ return os << p.string ();
+ }
+ }
+}
+
+#include <cutl/fs/path.txx>
+
+#endif // CUTL_FS_PATH_HXX