Easy3D 2.5.3
line_stream.h
1/********************************************************************
2 * Copyright (C) 2015 Liangliang Nan <liangliang.nan@gmail.com>
3 * https://3d.bk.tudelft.nl/liangliang/
4 *
5 * This file is part of Easy3D. If it is useful in your research/work,
6 * I would be grateful if you show your appreciation by citing it:
7 * ------------------------------------------------------------------
8 * Liangliang Nan.
9 * Easy3D: a lightweight, easy-to-use, and efficient C++ library
10 * for processing and rendering 3D data.
11 * Journal of Open Source Software, 6(64), 3255, 2021.
12 * ------------------------------------------------------------------
13 *
14 * Easy3D is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License Version 3
16 * as published by the Free Software Foundation.
17 *
18 * Easy3D is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 ********************************************************************/
26
27#ifndef EASY3D_UTIL_LINE_STREAM_H
28#define EASY3D_UTIL_LINE_STREAM_H
29
30#include <iostream>
31#include <sstream>
32
33
34namespace easy3d {
35
36
41 namespace io {
42
48 public:
49 explicit LineInputStream(std::istream &in) : in_(in), line_in_(nullptr) {}
50
52 delete line_in_;
53 line_in_ = nullptr;
54 }
55
56 bool eof() const { return in_.eof(); }
57
58 bool eol() const { return line_in_ == nullptr || line_in_->eof(); }
59
60 bool fail() const { return in_.fail() || line_in_->fail(); }
61
62 void get_line() {
63 getline(in_, buffer_);
64 delete line_in_;
65 line_in_ = new std::istringstream(buffer_);
66 }
67
68 std::istream &line() {
69 assert(line_in_ != nullptr);
70 return *line_in_;
71 }
72
73 const std::string &current_line() const {
74 return buffer_;
75 }
76
77 template<class T>
78 LineInputStream &operator>>(T &param) {
79 *line_in_ >> param;
80 return *this;
81 }
82
83 private:
84 std::istream &in_;
85 std::istringstream *line_in_;
86 std::string buffer_;
87 };
88
89
90 } // namespace io
91
92} // namespace easy3d
93
94
95#endif // EASY3D_UTIL_LINE_STREAM_H
Input stream class to operate on ASCII files.
Definition: line_stream.h:47
Definition: collider.cpp:182