1 // boost/filesystem/path.hpp -----------------------------------------------//
3 // © Copyright Beman Dawes 2002-2003
4 // Use, modification, and distribution is subject to the Boost Software
5 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 // See library home page at http://www.boost.org/libs/filesystem
10 //----------------------------------------------------------------------------//
12 #ifndef BOOST_FILESYSTEM_PATH_HPP
13 #define BOOST_FILESYSTEM_PATH_HPP
15 #include <boost/filesystem/config.hpp>
16 #include <boost/iterator/iterator_facade.hpp>
20 #include <boost/config/abi_prefix.hpp> // must be the last header
22 //----------------------------------------------------------------------------//
28 class directory_iterator;
31 // path -------------------------------------------------------------------//
33 class BOOST_FILESYSTEM_DECL path
36 typedef bool (*name_check)( const std::string & name );
38 // compiler generates copy constructor, copy assignment, and destructor
42 path( const std::string & src );
43 path( const char * src );
45 path( const std::string & src, name_check checker );
46 path( const char * src, name_check checker );
49 path & operator /=( const path & rhs );
50 path operator /( const path & rhs ) const
51 { return path( *this ) /= rhs; }
53 // modification functions:
56 // conversion functions:
57 const std::string & string() const { return m_path; }
58 std::string native_file_string() const;
59 std::string native_directory_string() const;
61 // decomposition functions:
62 path root_path() const;
63 std::string root_name() const;
64 std::string root_directory() const;
65 path relative_path() const;
66 std::string leaf() const;
67 path branch_path() const;
70 bool empty() const { return m_path.empty(); } // name consistent with std containers
72 bool is_complete() const;
74 bool has_root_path() const;
75 bool has_root_name() const;
76 bool has_root_directory() const;
77 bool has_relative_path() const;
78 bool has_leaf() const { return !m_path.empty(); }
79 bool has_branch_path() const;
81 // iteration over the names in the path:
82 class iterator : public boost::iterator_facade<
85 boost::single_pass_traversal_tag >
88 friend class boost::iterator_core_access;
89 friend class boost::filesystem::path;
91 reference dereference() const { return m_name; }
92 bool equal( const iterator & rhs ) const
93 { return m_path_ptr == rhs.m_path_ptr && m_pos == rhs.m_pos; }
97 std::string m_name; // cache current element.
98 const path * m_path_ptr; // path being iterated over.
99 std::string::size_type m_pos; // position of name in
100 // path_ptr->string(). The
101 // end() iterator is indicated by
102 // pos == path_ptr->string().size()
105 iterator begin() const;
109 itr.m_path_ptr = this;
110 itr.m_pos = m_path.size();
114 // default name_check mechanism:
115 static bool default_name_check_writable();
116 static void default_name_check( name_check new_check );
117 static name_check default_name_check();
120 // Note: This is an implementation for POSIX and Windows, where there
121 // are only minor differences between generic and system-specific
122 // constructor input formats. Private members might be quite different
123 // in other implementations, particularly where there were wide
124 // differences between generic and system-specific argument formats,
125 // or between native_file_string() and native_directory_string() formats.
129 friend class directory_iterator;
130 // Was qualified; como433beta8 reports:
131 // warning #427-D: qualified name is not allowed in member declaration
132 friend class iterator;
134 public: // should be private, but friend functions don't work for me
135 void m_path_append( const std::string & src, name_check checker );
136 void m_replace_leaf( const char * new_leaf );
139 // path non-member functions ---------------------------------------------//
141 inline path operator / ( const char * lhs, const path & rhs )
142 { return path( lhs ) /= rhs; }
144 inline path operator / ( const std::string & lhs, const path & rhs )
145 { return path( lhs ) /= rhs; }
147 // path::name_checks ---------------------------------------------------//
149 BOOST_FILESYSTEM_DECL bool portable_posix_name( const std::string & name );
150 BOOST_FILESYSTEM_DECL bool windows_name( const std::string & name );
151 BOOST_FILESYSTEM_DECL bool portable_name( const std::string & name );
152 BOOST_FILESYSTEM_DECL bool portable_directory_name( const std::string & name );
153 BOOST_FILESYSTEM_DECL bool portable_file_name( const std::string & name );
154 BOOST_FILESYSTEM_DECL bool no_check( const std::string & name ); // always returns true
155 BOOST_FILESYSTEM_DECL bool native( const std::string & name );
156 // native(name) must return true for any name which MIGHT be valid
157 // on the native platform.
159 } // namespace filesystem
162 #include <boost/config/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
163 #endif // BOOST_FILESYSTEM_PATH_HPP