Easy3D 2.6.1
Loading...
Searching...
No Matches
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#include <cassert>
33
34
35namespace easy3d {
36
41 namespace io {
42
48 public:
53 explicit LineInputStream(std::istream &in) : in_(in), line_in_(nullptr) {}
58 delete line_in_;
59 line_in_ = nullptr;
60 }
61
65 bool eof() const { return in_.eof(); }
70 bool eol() const { return line_in_ == nullptr || line_in_->eof(); }
75 bool fail() const { return in_.fail() || line_in_->fail(); }
79 void get_line() {
80 getline(in_, buffer_);
81 delete line_in_;
82 line_in_ = new std::istringstream(buffer_);
83 }
84
88 std::istream &line() {
89 assert(line_in_ != nullptr);
90 return *line_in_;
91 }
92
96 const std::string &current_line() const {
97 return buffer_;
98 }
99
105 template<class T>
107 *line_in_ >> param;
108 return *this;
109 }
110
111 private:
112 std::istream &in_;
113 std::istringstream *line_in_;
114 std::string buffer_;
115 };
116
117
118 } // namespace io
119
120} // namespace easy3d
121
122
123#endif // EASY3D_UTIL_LINE_STREAM_H
bool eol() const
Check if the end of the line has been reached.
Definition line_stream.h:70
std::istream & line()
Get the current line as an input stream.
Definition line_stream.h:88
LineInputStream & operator>>(T &param)
Extract a value from the current line.
Definition line_stream.h:106
bool fail() const
Check if the stream has failed.
Definition line_stream.h:75
LineInputStream(std::istream &in)
Constructor.
Definition line_stream.h:53
~LineInputStream()
Destructor.
Definition line_stream.h:57
void get_line()
Read the next line from the input stream.
Definition line_stream.h:79
bool eof() const
Check if the end of the file has been reached.
Definition line_stream.h:65
const std::string & current_line() const
Get the current line as a string.
Definition line_stream.h:96
File input/output functionalities.
Definition graph_io.h:60
Definition collider.cpp:182