Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/tools/inspect/cvs_iterator.hpp @ 12

Last change on this file since 12 was 12, checked in by landauf, 18 years ago

added boost

File size: 2.3 KB
Line 
1//  cvs_iterator  ------------------------------------------------------------//
2
3//  Copyright Beman Dawes 2003.
4//  Distributed under the Boost Software License, Version 1.0.
5//  (See accompanying file LICENSE_1_0.txt or copy at
6//  http://www.boost.org/LICENSE_1_0.txt)
7
8//  WARNING: This is just a quick hack. It doesn't conform to C++ Standard
9//  Library iterator requirements.
10
11#include <boost/filesystem/path.hpp>
12#include <boost/filesystem/exception.hpp>
13#include <boost/filesystem/operations.hpp>
14#include <boost/filesystem/fstream.hpp>
15#include <boost/noncopyable.hpp>
16#include <string>
17#include <cassert>
18
19namespace hack
20{
21  class cvs_iterator : boost::noncopyable
22  {
23    boost::filesystem::ifstream  entries_file;
24    boost::filesystem::path      dir_path;
25    boost::filesystem::path      value_path;
26  public:
27
28    cvs_iterator(){} // end iterator
29
30    ~cvs_iterator() { if ( !!entries_file ) entries_file.close(); }
31
32    cvs_iterator( const boost::filesystem::path & dir_path ) : dir_path(dir_path)
33    {
34      boost::filesystem::path entries_file_path( dir_path / "CVS/Entries" ); 
35      entries_file.open( entries_file_path );
36      if ( !entries_file )
37        throw std::string( "could not open: " ) + entries_file_path.string();
38      ++*this;
39    }
40
41    const boost::filesystem::path & operator*() const { return value_path; }
42
43    cvs_iterator & operator++()
44    {
45      assert( !!entries_file );
46      std::string contents;
47      do
48      {
49        do
50        {
51          std::getline( entries_file, contents );
52          if ( entries_file.eof() )
53          { 
54            entries_file.close(); 
55            value_path = "";
56            return *this;
57          }
58        } while ( contents == "D" );
59        if ( contents[0] == 'D' ) contents.erase( 0, 1 );
60        value_path = dir_path
61          / boost::filesystem::path( contents.substr( 1, contents.find( '/', 1 ) ), boost::filesystem::no_check );
62
63      // in case entries file is mistaken, do until value_path actually found
64      } while ( !boost::filesystem::exists( value_path ) ); 
65      return *this;
66    }
67
68    bool operator==( const cvs_iterator & rhs )
69      { return value_path.string() == rhs.value_path.string(); }
70
71    bool operator!=( const cvs_iterator & rhs )
72      { return value_path.string() != rhs.value_path.string(); }
73
74  };
75}
Note: See TracBrowser for help on using the repository browser.