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  m_Buf(NULL),
25  m_BufSize(0),
26  m_IsInternalBuffer(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 m_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 m_Fd;
45  unsigned char* m_Buf;
46  size_t m_BufSize;
47  bool m_IsInternalBuffer;
49 };
50 
51 NLIB_NAMESPACE_END
52 
53 #endif // INCLUDE_NN_NLIB_FILEINPUTSTREAM_H_
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Platform.h:2151
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...
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
#define NLIB_NONNULL
Indicates that you cannot specify NULL for all arguments.
Definition: Platform_unix.h:66
#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:126
Defines the base class for input streams.
#define NLIB_OVERRIDE
Defines override if it is available for use. If not, holds an empty string.
size_t buffer_size
The size of the buffer.
#define NLIB_FD_INVALID
A macro defining invalid file descriptors.
Definition: Platform.h:1052
nlib_fd GetFd() const noexcept
Returns the file descriptor.
int nlib_fd
The original file descriptor of nlib (a 32-bit integer value).
Definition: Platform.h:1051
#define NLIB_CEXPR
Defines constexpr if it is available for use. If not, holds an empty string.
The base class for input streams. This class cannot be instantiated.
Definition: InputStream.h:15
constexpr FileInputStreamSettings(void *buf_, size_t buffer_size_) noexcept
Sets the data members.
The class for file input streams.
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:51
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_CHECK_RESULT
Indicates that the caller of the function must check the returned value.
Definition: Platform_unix.h:64
int errno_t
Indicates with an int-type typedef that a POSIX error value is returned as the return value...
Definition: NMalloc.h:24