nlib
FileOutputStream.h
Go to the documentation of this file.
1 
2 #pragma once
3 #ifndef INCLUDE_NN_NLIB_FILEOUTPUTSTREAM_H_
4 #define INCLUDE_NN_NLIB_FILEOUTPUTSTREAM_H_
5 
6 #include "nn/nlib/OutputStream.h"
7 
8 NLIB_NAMESPACE_BEGIN
9 
11  void* buf;
12  size_t buffer_size;
13 
14  public:
15  NLIB_CEXPR FileOutputStreamSettings() NLIB_NOEXCEPT : buf(NULL), buffer_size(4096) {}
16  NLIB_CEXPR FileOutputStreamSettings(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 bool PushBuffer_(const void* p, size_t nBytes,
40  bool doFlush) NLIB_NOEXCEPT NLIB_OVERRIDE;
41  virtual bool Close_() NLIB_NOEXCEPT NLIB_OVERRIDE;
42  virtual bool WriteGather_(const nlib_fd_iovec* iov, int iovcnt) NLIB_NOEXCEPT NLIB_OVERRIDE;
43 
44  private:
45  nlib_fd m_Fd;
46  unsigned char* m_Buf;
47  size_t m_BufSize;
48  bool m_IsInternalBuffer;
50 };
51 
52 NLIB_NAMESPACE_END
53 
54 #endif // INCLUDE_NN_NLIB_FILEOUTPUTSTREAM_H_
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Platform.h:2151
constexpr FileOutputStreamSettings() noexcept
Instantiates the object with default parameters (default constructor). Sets the default values...
The structure that stores information about the file stream settings.
#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
The class for file output streams.
void * buf
A pointer to a buffer.
#define NLIB_OVERRIDE
Defines override if it is available for use. If not, holds an empty string.
nlib_fd GetFd() const noexcept
Returns the file descriptor.
#define NLIB_FD_INVALID
A macro defining invalid file descriptors.
Definition: Platform.h:1052
size_t buffer_size
The size of the buffer.
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.
FileOutputStream() noexcept
Instantiates the object with default parameters (default constructor). The buffer must be set and ini...
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:51
constexpr FileOutputStreamSettings(void *buf_, size_t buffer_size_) noexcept
Sets the individual data members.
Defines the base class for output streams.
The base class for output streams. This class cannot be instantiated.
Definition: OutputStream.h:17
#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