This file is indexed.

/usr/include/jellyfish/stream_iterator.hpp is in libjellyfish-2.0-dev 2.2.8-3build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*  This file is part of Jellyfish.

    Jellyfish is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Jellyfish is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Jellyfish.  If not, see <http://www.gnu.org/licenses/>.
*/


#ifndef __STREAM_ITERATOR_HPP__
#define __STREAM_ITERATOR_HPP__

#include <assert.h>

#include <iostream>
#include <fstream>
#include <iterator>
#include <stdexcept>
#include <memory>

#include <jellyfish/err.hpp>

namespace jellyfish {
/// Transform an iterator of paths (c string: const char*) into an
/// iterator of std::ifstream. Every file is opened and closed in
/// turn. The object instantiated with no argument is the end marker.
template<typename PathIterator>
class stream_iterator : public std::iterator<std::forward_iterator_tag, std::ifstream> {
  PathIterator                 begin_, end_;
  std::ifstream*               stream_;
public:
  stream_iterator(PathIterator begin, PathIterator end) :
    begin_(begin), end_(end), stream_(0)
  {
    if(begin_ != end_) {
      stream_ = new std::ifstream;
      open_file();
    }
  }
  stream_iterator(const stream_iterator& rhs) :
  begin_(rhs.begin_), end_(rhs.end_), stream_(rhs.stream_)
  { }
  stream_iterator() : begin_(), end_(), stream_() { }

  bool operator==(const stream_iterator& rhs) const {
    return stream_ == rhs.stream_;
  }
  bool operator!=(const stream_iterator& rhs) const {
    return stream_ != rhs.stream_;
  }

  std::ifstream& operator*() { return *stream_; }
  std::ifstream* operator->() { return stream_; }

  stream_iterator& operator++() {
    stream_->close();
    if(++begin_ != end_) {
      open_file();
    } else {
      delete stream_;
      stream_ = 0;
    }

    return *this;
  }
  stream_iterator operator++(int) {
    stream_iterator res(*this);
    ++*this;
    return res;
  }

protected:
  void open_file() {
    stream_->open(*begin_);
    if(stream_->fail())
      throw std::runtime_error(err::msg() << "Failed to open file '" << *begin_ << "'");
  }
};

}

#endif /* __STREAM_ITERATOR_HPP__ */