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::bidirectional_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();
119 // relational operators
120 bool operator<( const path & that ) const;
121 bool operator==( const path & that ) const { return !(*this < that) && !(that < *this); }
122 bool operator!=( const path & that ) const { return !(*this == that); }
123 bool operator>( const path & that ) const { return that < *this; }
124 bool operator<=( const path & that ) const { return !(that < *this); }
125 bool operator>=( const path & that ) const { return !(*this < that); }
128 // Note: This is an implementation for POSIX and Windows, where there
129 // are only minor differences between generic and system-specific
130 // constructor input formats. Private members might be quite different
131 // in other implementations, particularly where there were wide
132 // differences between generic and system-specific argument formats,
133 // or between native_file_string() and native_directory_string() formats.
137 friend class directory_iterator;
138 // Was qualified; como433beta8 reports:
139 // warning #427-D: qualified name is not allowed in member declaration
140 friend class iterator;
142 public: // should be private, but friend functions don't work for me
143 void m_path_append( const std::string & src, name_check checker );
144 void m_replace_leaf( const char * new_leaf );
147 // path non-member functions ---------------------------------------------//
149 inline path operator / ( const char * lhs, const path & rhs )
150 { return path( lhs ) /= rhs; }
152 inline path operator / ( const std::string & lhs, const path & rhs )
153 { return path( lhs ) /= rhs; }
155 // path::name_checks ---------------------------------------------------//
157 BOOST_FILESYSTEM_DECL bool portable_posix_name( const std::string & name );
158 BOOST_FILESYSTEM_DECL bool windows_name( const std::string & name );
159 BOOST_FILESYSTEM_DECL bool portable_name( const std::string & name );
160 BOOST_FILESYSTEM_DECL bool portable_directory_name( const std::string & name );
161 BOOST_FILESYSTEM_DECL bool portable_file_name( const std::string & name );
162 BOOST_FILESYSTEM_DECL bool no_check( const std::string & name ); // always returns true
163 BOOST_FILESYSTEM_DECL bool native( const std::string & name );
164 // native(name) must return true for any name which MIGHT be valid
165 // on the native platform.
167 } // namespace filesystem
170 #include <boost/config/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
171 #endif // BOOST_FILESYSTEM_PATH_HPP