imgtools/imglib/boostlibrary/boost/filesystem/convenience.hpp
author marvin shi <marvin.shi@nokia.com>
Wed, 17 Nov 2010 14:05:07 +0800
changeset 691 9eeecb73a5d4
parent 600 6d08f4a05d93
permissions -rw-r--r--
fix ou1cimx1#651819
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     1
//  boost/filesystem/convenience.hpp  ----------------------------------------//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     2
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     3
//  Copyright Beman Dawes, 2002-2005
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     4
//  Copyright Vladimir Prus, 2002
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     5
//  Use, modification, and distribution is subject to the Boost Software
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     6
//  License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     7
//  http://www.boost.org/LICENSE_1_0.txt)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     8
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     9
//  See library home page at http://www.boost.org/libs/filesystem
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    10
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    11
//----------------------------------------------------------------------------// 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    12
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    13
#ifndef BOOST_FILESYSTEM_CONVENIENCE_HPP
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    14
#define BOOST_FILESYSTEM_CONVENIENCE_HPP
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    15
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    16
#include <boost/filesystem/operations.hpp>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    17
#include <boost/system/error_code.hpp>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    18
#include <vector>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    19
#include <stack>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    20
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    21
#include <boost/config/abi_prefix.hpp> // must be the last #include
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    22
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    23
# ifndef BOOST_FILESYSTEM_NARROW_ONLY
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    24
#   define BOOST_FS_FUNC(BOOST_FS_TYPE) \
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    25
      template<class Path> typename boost::enable_if<is_basic_path<Path>, \
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    26
      BOOST_FS_TYPE>::type
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    27
#   define BOOST_FS_FUNC_STRING BOOST_FS_FUNC(typename Path::string_type)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    28
#   define BOOST_FS_TYPENAME typename
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    29
# else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    30
#   define BOOST_FS_FUNC(BOOST_FS_TYPE) inline BOOST_FS_TYPE 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    31
    typedef boost::filesystem::path Path;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    32
#   define BOOST_FS_FUNC_STRING inline std::string
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    33
#   define BOOST_FS_TYPENAME
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    34
# endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    35
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    36
namespace boost
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    37
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    38
  namespace filesystem
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    39
  {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    40
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    41
    BOOST_FS_FUNC(bool) create_directories(const Path& ph)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    42
    {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    43
         if (ph.empty() || exists(ph))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    44
         {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    45
           if ( !ph.empty() && !is_directory(ph) )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    46
               boost::throw_exception( basic_filesystem_error<Path>(
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    47
                 "boost::filesystem::create_directories", ph,
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    48
                 make_error_code( boost::system::posix::file_exists ) ) );
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    49
           return false;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    50
         }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    51
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    52
         // First create branch, by calling ourself recursively
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    53
         create_directories(ph.parent_path());
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    54
         // Now that parent's path exists, create the directory
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    55
         create_directory(ph);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    56
         return true;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    57
     }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    58
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    59
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    60
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    61
    BOOST_FS_FUNC_STRING extension(const Path& ph)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    62
    {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    63
      typedef BOOST_FS_TYPENAME Path::string_type string_type;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    64
      string_type filename = ph.filename();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    65
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    66
      BOOST_FS_TYPENAME string_type::size_type n = filename.rfind('.');
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    67
      if (n != string_type::npos)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    68
        return filename.substr(n);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    69
      else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    70
        return string_type();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    71
    }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    72
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    73
    BOOST_FS_FUNC_STRING basename(const Path& ph)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    74
    {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    75
      typedef BOOST_FS_TYPENAME Path::string_type string_type;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    76
      string_type filename = ph.filename();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    77
      BOOST_FS_TYPENAME string_type::size_type n = filename.rfind('.');
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    78
      return filename.substr(0, n);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    79
    }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    80
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    81
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    82
    BOOST_FS_FUNC(Path) change_extension( const Path & ph,
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    83
      const BOOST_FS_TYPENAME Path::string_type & new_extension )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    84
      { return ph.parent_path() / (basename(ph) + new_extension); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    85
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    86
# endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    87
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    88
# ifndef BOOST_FILESYSTEM_NARROW_ONLY
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    89
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    90
    // "do-the-right-thing" overloads  ---------------------------------------//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    91
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    92
    inline bool create_directories(const path& ph)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    93
      { return create_directories<path>(ph); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    94
    inline bool create_directories(const wpath& ph)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    95
      { return create_directories<wpath>(ph); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    96
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    97
# ifndef BOOST_FILESYSTEM_NO_DEPRECATED
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    98
    inline std::string extension(const path& ph)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    99
      { return extension<path>(ph); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   100
    inline std::wstring extension(const wpath& ph)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   101
      { return extension<wpath>(ph); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   102
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   103
    inline std::string basename(const path& ph)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   104
      { return basename<path>( ph ); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   105
    inline std::wstring basename(const wpath& ph)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   106
      { return basename<wpath>( ph ); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   107
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   108
    inline path change_extension( const path & ph, const std::string& new_ex )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   109
      { return change_extension<path>( ph, new_ex ); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   110
    inline wpath change_extension( const wpath & ph, const std::wstring& new_ex )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   111
      { return change_extension<wpath>( ph, new_ex ); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   112
# endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   113
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   114
# endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   115
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   116
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   117
    //  basic_recursive_directory_iterator helpers  --------------------------//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   118
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   119
    namespace detail
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   120
    {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   121
      template< class Path >
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   122
      struct recur_dir_itr_imp
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   123
      {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   124
        typedef basic_directory_iterator< Path > element_type;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   125
        std::stack< element_type, std::vector< element_type > > m_stack;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   126
        int  m_level;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   127
        bool m_no_push;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   128
        bool m_no_throw;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   129
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   130
        recur_dir_itr_imp() : m_level(0), m_no_push(false), m_no_throw(false) {}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   131
      };
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   132
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   133
    } // namespace detail
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   134
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   135
    //  basic_recursive_directory_iterator  ----------------------------------//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   136
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   137
    template< class Path >
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   138
    class basic_recursive_directory_iterator
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   139
      : public boost::iterator_facade<
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   140
          basic_recursive_directory_iterator<Path>,
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   141
          basic_directory_entry<Path>,
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   142
          boost::single_pass_traversal_tag >
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   143
    {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   144
    public:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   145
      typedef Path path_type;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   146
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   147
      basic_recursive_directory_iterator(){}  // creates the "end" iterator
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   148
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   149
      explicit basic_recursive_directory_iterator( const Path & dir_path );
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   150
      basic_recursive_directory_iterator( const Path & dir_path,
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   151
        system::error_code & ec );
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   152
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   153
      int level() const { return m_imp->m_level; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   154
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   155
      void pop();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   156
      void no_push()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   157
      {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   158
        BOOST_ASSERT( m_imp.get() && "attempt to no_push() on end iterator" );
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   159
        m_imp->m_no_push = true;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   160
      }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   161
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   162
      file_status status() const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   163
      {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   164
        BOOST_ASSERT( m_imp.get()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   165
          && "attempt to call status() on end recursive_iterator" );
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   166
        return m_imp->m_stack.top()->status();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   167
      }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   168
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   169
      file_status symlink_status() const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   170
      {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   171
        BOOST_ASSERT( m_imp.get()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   172
          && "attempt to call symlink_status() on end recursive_iterator" );
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   173
        return m_imp->m_stack.top()->symlink_status();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   174
      }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   175
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   176
    private:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   177
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   178
      // shared_ptr provides shallow-copy semantics required for InputIterators.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   179
      // m_imp.get()==0 indicates the end iterator.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   180
      boost::shared_ptr< detail::recur_dir_itr_imp< Path > >  m_imp;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   181
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   182
      friend class boost::iterator_core_access;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   183
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   184
      typename boost::iterator_facade< 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   185
        basic_recursive_directory_iterator<Path>,
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   186
        basic_directory_entry<Path>,
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   187
        boost::single_pass_traversal_tag >::reference
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   188
      dereference() const 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   189
      {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   190
        BOOST_ASSERT( m_imp.get() && "attempt to dereference end iterator" );
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   191
        return *m_imp->m_stack.top();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   192
      }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   193
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   194
      void increment();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   195
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   196
      bool equal( const basic_recursive_directory_iterator & rhs ) const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   197
        { return m_imp == rhs.m_imp; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   198
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   199
    };
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   200
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   201
    typedef basic_recursive_directory_iterator<path> recursive_directory_iterator;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   202
# ifndef BOOST_FILESYSTEM_NARROW_ONLY
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   203
    typedef basic_recursive_directory_iterator<wpath> wrecursive_directory_iterator;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   204
# endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   205
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   206
    //  basic_recursive_directory_iterator implementation  -------------------//
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   207
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   208
    //  constructors
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   209
    template<class Path>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   210
    basic_recursive_directory_iterator<Path>::
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   211
      basic_recursive_directory_iterator( const Path & dir_path )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   212
      : m_imp( new detail::recur_dir_itr_imp<Path> )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   213
    {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   214
      m_imp->m_stack.push( basic_directory_iterator<Path>( dir_path ) );
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   215
      if ( m_imp->m_stack.top () == basic_directory_iterator<Path>() )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   216
        { m_imp.reset (); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   217
    }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   218
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   219
    template<class Path>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   220
    basic_recursive_directory_iterator<Path>::
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   221
      basic_recursive_directory_iterator( const Path & dir_path,
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   222
        system::error_code & ec )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   223
      : m_imp( new detail::recur_dir_itr_imp<Path> )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   224
    {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   225
      m_imp->m_no_throw = true;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   226
      m_imp->m_stack.push( basic_directory_iterator<Path>( dir_path, ec ) );
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   227
      if ( m_imp->m_stack.top () == basic_directory_iterator<Path>() )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   228
        { m_imp.reset (); }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   229
    }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   230
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   231
    //  increment
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   232
    template<class Path>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   233
    void basic_recursive_directory_iterator<Path>::increment()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   234
    {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   235
      BOOST_ASSERT( m_imp.get() && "increment on end iterator" );
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   236
      
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   237
      static const basic_directory_iterator<Path> end_itr;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   238
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   239
      if ( m_imp->m_no_push )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   240
        { m_imp->m_no_push = false; }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   241
      else if ( is_directory( m_imp->m_stack.top()->status() ) )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   242
      {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   243
        system::error_code ec;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   244
#if BOOST_WORKAROUND(__CODEGEARC__, BOOST_TESTED_AT(0x610))
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   245
        if( m_imp->m_no_throw ) {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   246
            m_imp->m_stack.push(
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   247
                basic_directory_iterator<Path>( *m_imp->m_stack.top(), ec )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   248
            );
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   249
        }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   250
        else {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   251
            m_imp->m_stack.push(
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   252
                basic_directory_iterator<Path>( *m_imp->m_stack.top() )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   253
            );
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   254
        }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   255
#else
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   256
        m_imp->m_stack.push(
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   257
          m_imp->m_no_throw
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   258
            ? basic_directory_iterator<Path>( *m_imp->m_stack.top(), ec )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   259
            : basic_directory_iterator<Path>( *m_imp->m_stack.top() ) );
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   260
#endif
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   261
        if ( m_imp->m_stack.top() != end_itr )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   262
        {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   263
          ++m_imp->m_level;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   264
          return;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   265
        }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   266
        m_imp->m_stack.pop();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   267
      }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   268
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   269
      while ( !m_imp->m_stack.empty()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   270
        && ++m_imp->m_stack.top() == end_itr )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   271
      {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   272
        m_imp->m_stack.pop();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   273
        --m_imp->m_level;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   274
      }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   275
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   276
      if ( m_imp->m_stack.empty() ) m_imp.reset(); // done, so make end iterator
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   277
    }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   278
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   279
    //  pop
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   280
    template<class Path>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   281
    void basic_recursive_directory_iterator<Path>::pop()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   282
    {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   283
      BOOST_ASSERT( m_imp.get() && "pop on end iterator" );
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   284
      BOOST_ASSERT( m_imp->m_level > 0 && "pop with level < 1" );
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   285
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   286
      static const basic_directory_iterator<Path> end_itr;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   287
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   288
      do
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   289
      {
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   290
        m_imp->m_stack.pop();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   291
        --m_imp->m_level;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   292
      }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   293
      while ( !m_imp->m_stack.empty()
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   294
        && ++m_imp->m_stack.top() == end_itr );
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   295
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   296
      if ( m_imp->m_stack.empty() ) m_imp.reset(); // done, so make end iterator
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   297
    }
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   298
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   299
  } // namespace filesystem
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   300
} // namespace boost
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   301
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   302
#undef BOOST_FS_FUNC_STRING
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   303
#undef BOOST_FS_FUNC
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   304
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   305
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   306
#endif // BOOST_FILESYSTEM_CONVENIENCE_HPP