[857] | 1 | // boost/filesystem/path.hpp -----------------------------------------------//
|
---|
| 2 |
|
---|
| 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)
|
---|
| 7 |
|
---|
| 8 | // See library home page at http://www.boost.org/libs/filesystem
|
---|
| 9 |
|
---|
| 10 | //----------------------------------------------------------------------------//
|
---|
| 11 |
|
---|
| 12 | #ifndef BOOST_FILESYSTEM_PATH_HPP
|
---|
| 13 | #define BOOST_FILESYSTEM_PATH_HPP
|
---|
| 14 |
|
---|
| 15 | #include <boost/filesystem/config.hpp>
|
---|
| 16 | #include <boost/iterator/iterator_facade.hpp>
|
---|
| 17 | #include <string>
|
---|
| 18 | #include <cassert>
|
---|
| 19 |
|
---|
| 20 | #include <boost/config/abi_prefix.hpp> // must be the last header
|
---|
| 21 |
|
---|
| 22 | //----------------------------------------------------------------------------//
|
---|
| 23 |
|
---|
| 24 | namespace boost
|
---|
| 25 | {
|
---|
| 26 | namespace filesystem
|
---|
| 27 | {
|
---|
| 28 | class directory_iterator;
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 | // path -------------------------------------------------------------------//
|
---|
| 32 |
|
---|
| 33 | class BOOST_FILESYSTEM_DECL path
|
---|
| 34 | {
|
---|
| 35 | public:
|
---|
| 36 | typedef bool (*name_check)( const std::string & name );
|
---|
| 37 |
|
---|
| 38 | // compiler generates copy constructor, copy assignment, and destructor
|
---|
| 39 |
|
---|
| 40 | path(){}
|
---|
| 41 |
|
---|
| 42 | path( const std::string & src );
|
---|
| 43 | path( const char * src );
|
---|
| 44 |
|
---|
| 45 | path( const std::string & src, name_check checker );
|
---|
| 46 | path( const char * src, name_check checker );
|
---|
| 47 |
|
---|
| 48 | // append operations:
|
---|
| 49 | path & operator /=( const path & rhs );
|
---|
| 50 | path operator /( const path & rhs ) const
|
---|
| 51 | { return path( *this ) /= rhs; }
|
---|
| 52 |
|
---|
| 53 | // modification functions:
|
---|
| 54 | path & normalize();
|
---|
| 55 |
|
---|
| 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;
|
---|
| 60 |
|
---|
| 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;
|
---|
| 68 |
|
---|
| 69 | // query functions:
|
---|
| 70 | bool empty() const { return m_path.empty(); } // name consistent with std containers
|
---|
| 71 |
|
---|
| 72 | bool is_complete() const;
|
---|
| 73 |
|
---|
| 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;
|
---|
| 80 |
|
---|
| 81 | // iteration over the names in the path:
|
---|
| 82 | class iterator : public boost::iterator_facade<
|
---|
| 83 | iterator,
|
---|
| 84 | std::string const,
|
---|
| 85 | boost::bidirectional_traversal_tag >
|
---|
| 86 | {
|
---|
| 87 | private:
|
---|
| 88 | friend class boost::iterator_core_access;
|
---|
| 89 | friend class boost::filesystem::path;
|
---|
| 90 |
|
---|
| 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; }
|
---|
| 94 | BOOST_FILESYSTEM_DECL void increment();
|
---|
| 95 | BOOST_FILESYSTEM_DECL void decrement();
|
---|
| 96 |
|
---|
| 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()
|
---|
| 103 | };
|
---|
| 104 |
|
---|
| 105 | iterator begin() const;
|
---|
| 106 | iterator end() const
|
---|
| 107 | {
|
---|
| 108 | iterator itr;
|
---|
| 109 | itr.m_path_ptr = this;
|
---|
| 110 | itr.m_pos = m_path.size();
|
---|
| 111 | return itr;
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 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();
|
---|
| 118 |
|
---|
| 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); }
|
---|
| 126 |
|
---|
| 127 | private:
|
---|
| 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.
|
---|
| 134 |
|
---|
| 135 | std::string m_path;
|
---|
| 136 |
|
---|
| 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;
|
---|
| 141 |
|
---|
| 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 );
|
---|
| 145 | };
|
---|
| 146 |
|
---|
| 147 | // path non-member functions ---------------------------------------------//
|
---|
| 148 |
|
---|
| 149 | inline path operator / ( const char * lhs, const path & rhs )
|
---|
| 150 | { return path( lhs ) /= rhs; }
|
---|
| 151 |
|
---|
| 152 | inline path operator / ( const std::string & lhs, const path & rhs )
|
---|
| 153 | { return path( lhs ) /= rhs; }
|
---|
| 154 |
|
---|
| 155 | // path::name_checks ---------------------------------------------------//
|
---|
| 156 |
|
---|
| 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.
|
---|
| 166 |
|
---|
| 167 | } // namespace filesystem
|
---|
| 168 | } // namespace boost
|
---|
| 169 |
|
---|
| 170 | #include <boost/config/abi_suffix.hpp> // pops abi_suffix.hpp pragmas
|
---|
| 171 | #endif // BOOST_FILESYSTEM_PATH_HPP
|
---|