1 | // $Id: GetlineIterator.cc 3293 2014-07-25 03:42:58Z peter $ |
---|
2 | |
---|
3 | /* |
---|
4 | Copyright (C) 2009, 2012 Peter Johansson |
---|
5 | Copyright (C) 2014 Jari Häkkinen |
---|
6 | |
---|
7 | This file is part of the yat library, http://dev.thep.lu.se/yat |
---|
8 | |
---|
9 | The yat library is free software; you can redistribute it and/or |
---|
10 | modify it under the terms of the GNU General Public License as |
---|
11 | published by the Free Software Foundation; either version 3 of the |
---|
12 | License, or (at your option) any later version. |
---|
13 | |
---|
14 | The yat library is distributed in the hope that it will be useful, |
---|
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
17 | General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU General Public License |
---|
20 | along with yat. If not, see <http://www.gnu.org/licenses/>. |
---|
21 | */ |
---|
22 | |
---|
23 | |
---|
24 | #include <config.h> |
---|
25 | |
---|
26 | #include "GetlineIterator.h" |
---|
27 | |
---|
28 | #include <istream> |
---|
29 | #include <string> |
---|
30 | |
---|
31 | namespace theplu { |
---|
32 | namespace yat { |
---|
33 | namespace utility { |
---|
34 | |
---|
35 | |
---|
36 | GetlineIterator::GetlineIterator(void) |
---|
37 | : istream_(NULL) {} |
---|
38 | |
---|
39 | |
---|
40 | GetlineIterator::GetlineIterator(std::istream& is, char delimiter) |
---|
41 | : delimiter_(delimiter), istream_(&is) |
---|
42 | { |
---|
43 | increment(); // read the first line |
---|
44 | } |
---|
45 | |
---|
46 | |
---|
47 | GetlineIterator::reference GetlineIterator::dereference(void) const |
---|
48 | { |
---|
49 | return line_; |
---|
50 | } |
---|
51 | |
---|
52 | |
---|
53 | bool GetlineIterator::equal(const GetlineIterator& other) const |
---|
54 | { |
---|
55 | return istream_ == other.istream_; |
---|
56 | } |
---|
57 | |
---|
58 | |
---|
59 | void GetlineIterator::increment(void) |
---|
60 | { |
---|
61 | if (!istream_) |
---|
62 | return; |
---|
63 | if (!std::getline(*istream_, line_, delimiter_)) |
---|
64 | istream_ = NULL; |
---|
65 | } |
---|
66 | |
---|
67 | }}} // of namespace utility, yat, and theplu |
---|