strusBase  0.17
inputStream.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Patrick P. Frey
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
8 #ifndef _STRUS_BASE_INPUT_STREAM_HPP_INCLUDED
9 #define _STRUS_BASE_INPUT_STREAM_HPP_INCLUDED
10 #include <string>
11 #include <fstream>
12 #include <cstdio>
13 
14 namespace strus {
15 
19 {
20 public:
23  explicit InputStream( const std::string& docpath);
24 
26  ~InputStream();
27 
32  std::size_t read( char* buf, std::size_t bufsize);
33 
39  const char* readLine( char* buf, std::size_t bufsize, bool failOnNoLine=false);
40 
45  std::size_t readAhead( char* buf, std::size_t bufsize);
46 
49  unsigned int error() const;
50 
52  bool eof();
53 
54 private:
55  FILE* m_fh;
56  std::string m_docpath;
57  std::ifstream m_stream;
58  std::string m_buffer;
59  std::size_t m_bufferidx;
60  unsigned int m_errno;
61 };
62 
63 }
64 #endif
65 
66 
std::size_t read(char *buf, std::size_t bufsize)
Read some data.
~InputStream()
Destructor.
unsigned int error() const
Get the last error (system errno) occurred.
const char * readLine(char *buf, std::size_t bufsize, bool failOnNoLine=false)
Read a line.
bool eof()
Check if there is more data to read.
Abstraction of input stream.
Definition: inputStream.hpp:18
InputStream(const std::string &docpath)
Constructor.
std::size_t readAhead(char *buf, std::size_t bufsize)
Read some data and keep it in a buffer for the next read.