nlib
FileOutputStream.h
Go to the documentation of this file.
1 
2 /*--------------------------------------------------------------------------------*
3  Project: CrossRoad
4  Copyright (C)Nintendo All rights reserved.
5 
6  These coded instructions, statements, and computer programs contain proprietary
7  information of Nintendo and/or its licensed developers and are protected by
8  national and international copyright laws. They may not be disclosed to third
9  parties or copied or duplicated in any form, in whole or in part, without the
10  prior written consent of Nintendo.
11 
12  The content herein is highly confidential and should be handled accordingly.
13  *--------------------------------------------------------------------------------*/
14 
15 #pragma once
16 #ifndef INCLUDE_NN_NLIB_FILEOUTPUTSTREAM_H_
17 #define INCLUDE_NN_NLIB_FILEOUTPUTSTREAM_H_
18 
19 #include "nn/nlib/OutputStream.h"
20 
21 NLIB_NAMESPACE_BEGIN
22 
24  void* buf;
25  size_t buffer_size;
26 
27  public:
28  NLIB_CEXPR FileOutputStreamSettings() NLIB_NOEXCEPT : buf(nullptr), buffer_size(4096) {}
29  NLIB_CEXPR FileOutputStreamSettings(void* buf_, size_t buffer_size_) NLIB_NOEXCEPT
30  : buf(buf_),
31  buffer_size(buffer_size_) {}
32 };
33 
35  public:
37  buf_(nullptr),
38  buf_size_(0),
39  is_internal_buffer_(false) {}
44  return this->Init(settings);
45  }
46  NLIB_CHECK_RESULT errno_t Open(const char* filename, int flags,
47  int mode) NLIB_NOEXCEPT NLIB_NONNULL;
48  NLIB_CHECK_RESULT errno_t Open(const char* filename, int flags) NLIB_NOEXCEPT {
49  return Open(filename, flags, 0644);
50  }
51  NLIB_CHECK_RESULT errno_t Open(const char* filename) NLIB_NOEXCEPT {
52  return Open(filename, NLIB_FD_O_WRONLY | NLIB_FD_O_CREAT | NLIB_FD_O_TRUNC, 0644);
53  }
54  NLIB_CHECK_RESULT errno_t Open(const wchar_t* filename, int flags,
55  int mode) NLIB_NOEXCEPT NLIB_NONNULL;
56  NLIB_CHECK_RESULT errno_t Open(const wchar_t* filename, int flags) NLIB_NOEXCEPT {
57  return Open(filename, flags, 0644);
58  }
59  NLIB_CHECK_RESULT errno_t Open(const wchar_t* filename) NLIB_NOEXCEPT {
60  return Open(filename, NLIB_FD_O_WRONLY | NLIB_FD_O_CREAT | NLIB_FD_O_TRUNC, 0644);
61  }
63  nlib_fd GetFd() const NLIB_NOEXCEPT { return fd_; }
64 
65  private:
66  virtual bool
67  PushBuffer_(const void* p, size_t nbytes, bool do_flush) NLIB_NOEXCEPT NLIB_OVERRIDE;
68  virtual bool Close_() NLIB_NOEXCEPT NLIB_OVERRIDE;
69  virtual bool WriteGather_(const nlib_fd_iovec* iov, int iovcnt) NLIB_NOEXCEPT NLIB_OVERRIDE;
70 
71  private:
72  nlib_fd fd_;
73  unsigned char* buf_;
74  size_t buf_size_;
75  bool is_internal_buffer_;
77 };
78 
79 NLIB_NAMESPACE_END
80 
81 #endif // INCLUDE_NN_NLIB_FILEOUTPUTSTREAM_H_
constexpr FileOutputStreamSettings() noexcept
Instantiates the object with default parameters (default constructor). The setting to allocate the Fi...
#define NLIB_OVERRIDE
Defines override if it is available for use. If not, holds an empty string.
Definition: Config.h:249
The structure that stores information about the file stream settings.
#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:183
#define NLIB_FD_O_CREAT
Used for the flags parameter of the nlib_fd_open function.
Definition: Platform.h:1478
The class for file output streams.
#define NLIB_CHECK_RESULT
Indicates that the caller of the function must check the returned value.
void * buf
The pointer to the buffer used by FileOutputStream. The default is NULL.
errno_t Open(const wchar_t *filename) noexcept
A parameter omitted version of the above function. Assigns NLIB_FD_O_WRONLY | NLIB_FD_O_CREAT | NLIB_...
nlib_fd GetFd() const noexcept
Returns the file descriptor.
#define NLIB_FD_INVALID
A macro defining invalid file descriptors.
Definition: Platform.h:1514
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:87
size_t buffer_size
The size of the buffer used by FileOutputStream. The default is 4096.
errno_t Open(const wchar_t *filename, int flags) noexcept
A parameter omitted version of the above function. Assigns 0644 to mode.
#define NLIB_FD_O_WRONLY
Used for the flags parameter of the nlib_fd_open function.
Definition: Platform.h:1457
int nlib_fd
The original file descriptor of nlib (a 32-bit integer value).
Definition: Platform.h:1513
#define NLIB_FD_O_TRUNC
Used for the flags parameter of the nlib_fd_open function.
Definition: Platform.h:1485
errno_t Open(const char *filename, int flags) noexcept
A parameter omitted version of the above function. Assigns 0644 to mode.
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:109
#define NLIB_CEXPR
Defines constexpr if it is available for use. If not, holds an empty string.
Definition: Config.h:111
constexpr FileOutputStream() noexcept
Instantiates the object with default parameters (default constructor). Requires initialization with I...
constexpr FileOutputStreamSettings(void *buf_, size_t buffer_size_) noexcept
Sets the individual data members.
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:250
errno_t Open(const char *filename) noexcept
A parameter omitted version of the above function. Assigns NLIB_FD_O_WRONLY | NLIB_FD_O_CREAT | NLIB_...
Defines the base class for output streams.
#define NLIB_NONNULL
Indicates that you cannot specify NULL for all arguments.
The base class for output streams. This class cannot be instantiated.
Definition: OutputStream.h:30
int errno_t
Indicates with an int-type typedef that a POSIX error value is returned as the return value...
Definition: NMalloc.h:37