nlib
FileInputStream.h
Go to the documentation of this file.
1 
2 #pragma once
3 #ifndef INCLUDE_NN_NLIB_FILEINPUTSTREAM_H_
4 #define INCLUDE_NN_NLIB_FILEINPUTSTREAM_H_
5 
6 #include "nn/nlib/InputStream.h"
7 
8 NLIB_NAMESPACE_BEGIN
9 
11  void* buf;
12  size_t buffer_size;
13 
14  public:
15  NLIB_CEXPR FileInputStreamSettings() NLIB_NOEXCEPT : buf(NULL), buffer_size(4096) {}
16  NLIB_CEXPR FileInputStreamSettings(void* buf_, size_t buffer_size_) NLIB_NOEXCEPT
17  : buf(buf_),
18  buffer_size(buffer_size_) {}
19 };
20 
22  public:
24  buf_(NULL),
25  buf_size_(0),
26  is_internal_buf_(false) {}
30  return this->Init(settings);
31  }
33  NLIB_CHECK_RESULT errno_t Open(const char* filename) NLIB_NOEXCEPT NLIB_NONNULL;
34  NLIB_CHECK_RESULT errno_t Open(const wchar_t* filename) NLIB_NOEXCEPT NLIB_NONNULL;
36  nlib_fd GetFd() const NLIB_NOEXCEPT { return fd_; }
37 
38  private:
39  virtual size_t FillBuffer_(void* p, size_t nbytes) NLIB_NOEXCEPT NLIB_OVERRIDE;
40  virtual bool Close_() NLIB_NOEXCEPT NLIB_OVERRIDE;
41  virtual void* GetWorkBuffer_(size_t* nbytes) NLIB_NOEXCEPT NLIB_OVERRIDE;
42 
43  private:
44  nlib_fd fd_;
45  unsigned char* buf_;
46  size_t buf_size_;
47  bool is_internal_buf_;
49 };
50 
51 NLIB_NAMESPACE_END
52 
53 #endif // INCLUDE_NN_NLIB_FILEINPUTSTREAM_H_
#define NLIB_OVERRIDE
Defines override if it is available for use. If not, holds an empty string.
Definition: Config.h:210
The structure that stores information about the file stream settings.
FileInputStream() noexcept
Instantiates the object with default parameters (default constructor). The buffer must be set and ini...
nlib_fd GetFd() const noexcept
Returns the file descriptor.
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
Definition: Config.h:145
Defines the base class for input streams.
#define NLIB_CHECK_RESULT
Indicates that the caller of the function must check the returned value.
Definition: Platform_unix.h:74
size_t buffer_size
The size of the buffer.
#define NLIB_FD_INVALID
A macro defining invalid file descriptors.
Definition: Platform.h:1729
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:61
errno_t Init() noexcept
Initializes the stream with the default settings.
int nlib_fd
The original file descriptor of nlib (a 32-bit integer value).
Definition: Platform.h:1728
The base class for input streams. This class cannot be instantiated.
Definition: InputStream.h:16
constexpr FileInputStreamSettings(void *buf_, size_t buffer_size_) noexcept
Sets the data members.
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:86
#define NLIB_CEXPR
Defines constexpr if it is available for use. If not, holds an empty string.
Definition: Config.h:80
The class for file input streams.
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:211
constexpr FileInputStreamSettings() noexcept
Instantiates the object with default parameters (default constructor). The members are set to the def...
void * buf
A pointer to a buffer.
#define NLIB_NONNULL
Indicates that you cannot specify NULL for all arguments.
Definition: Platform_unix.h:76
int errno_t
Indicates with an int-type typedef that a POSIX error value is returned as the return value...
Definition: NMalloc.h:24