LifeV
cvs_iterator.hpp
Go to the documentation of this file.
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 
19 namespace 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 
31  {
32  if ( !!entries_file )
33  {
34  entries_file.close();
35  }
36  }
37 
38  cvs_iterator ( const boost::filesystem::path& dir_path ) : dir_path (dir_path)
39  {
40  boost::filesystem::path entries_file_path ( dir_path / "CVS/Entries" );
41  entries_file.open ( entries_file_path );
42  if ( !entries_file )
43  {
44  throw std::string ( "could not open: " ) + entries_file_path.string();
45  }
46  ++*this;
47  }
48 
49  const boost::filesystem::path& operator*() const
50  {
51  return value_path;
52  }
53 
55  {
56  assert ( !!entries_file );
57  std::string contents;
58  do
59  {
60  do
61  {
62  std::getline ( entries_file, contents );
63  if ( entries_file.eof() )
64  {
65  entries_file.close();
66  value_path = "";
67  return *this;
68  }
69  }
70  while ( contents == "D" );
71  if ( contents[0] == 'D' )
72  {
73  contents.erase ( 0, 1 );
74  }
75  value_path = dir_path
76  / boost::filesystem::path ( contents.substr ( 1, contents.find ( '/', 1 ) ), boost::filesystem::no_check );
77 
78  // in case entries file is mistaken, do until value_path actually found
79  }
80  while ( !boost::filesystem::exists ( value_path ) );
81  return *this;
82  }
83 
84  bool operator== ( const cvs_iterator& rhs )
85  {
86  return value_path.string() == rhs.value_path.string();
87  }
88 
89  bool operator!= ( const cvs_iterator& rhs )
90  {
91  return value_path.string() != rhs.value_path.string();
92  }
93 
94 };
95 }
cvs_iterator(const boost::filesystem::path &dir_path)
boost::filesystem::path value_path
boost::filesystem::path dir_path
bool operator!=(const cvs_iterator &rhs)
cvs_iterator & operator++()
const boost::filesystem::path & operator*() const
bool operator==(const cvs_iterator &rhs)
boost::filesystem::ifstream entries_file