/
FileReader.hpp
111 lines (83 loc) · 2.31 KB
/
FileReader.hpp
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* NPG-explorer, Nucleotide PanGenome explorer
* Copyright (C) 2012-2015 Boris Nagaev
*
* See the LICENSE file for terms of use.
*/
#ifndef NPGE_FILE_READER_HPP_
#define NPGE_FILE_READER_HPP_
#include <iterator>
#include <iosfwd>
#include <string>
#include <vector>
#include <boost/shared_ptr.hpp>
#include "global.hpp"
namespace npge {
/** Tag for iterator */
class frci_tag;
/** Base class for file readers.
Example:
\code
FileReader reader;
BOOST_FOREACH (std::istream& in, reader) {
// do smth with in
}
std::istream& in = reader.input(); // get first stream
\endcode
*/
class FileReader {
public:
/** Iterator class manages file open/close */
class const_iterator : public std::iterator<frci_tag, std::istream> {
public:
typedef std::istream value_type;
typedef int difference_type;
typedef std::istream* pointer;
typedef std::istream& reference;
typedef std::forward_iterator_tag iterator_category;
public:
/** Go to next element */
const_iterator& operator++();
/** Go to next element */
const_iterator& operator++(int);
/** Comparison operator */
bool operator==(const const_iterator& other);
/** Comparison operator */
bool operator!=(const const_iterator& other);
/** Dereference */
std::istream& operator*();
private:
const FileReader* reader_;
int index_;
boost::shared_ptr<std::istream> stream_;
const_iterator(const FileReader* reader, int index);
friend class FileReader;
};
/** Constructor */
FileReader(Processor* processor, const std::string& opt,
const std::string& descr);
/** Iterator */
const_iterator begin() const;
/** Iterator */
const_iterator end() const;
/** Return if no files */
bool empty() const;
/** Files list */
typedef Strings Files;
/** Get files list */
Files input_files() const;
/** Set files list */
void set_input_files(const Files& input_files);
/** Set file (list of one file) */
void set_input_file(const std::string& input_file);
/** First stream.
If no files, throws Exception.
*/
std::istream& input() const;
private:
Processor* processor_;
std::string opt_;
mutable boost::shared_ptr<std::istream> stream_;
};
}
#endif