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  : fd_(NLIB_FD_INVALID), buf_(nullptr), buf_size_(0), is_internal_buffer_(false) {}
41  return this->Init(settings);
42  }
44  NLIB_CHECK_RESULT errno_t Open(const char* filename,
45  int flags, int mode) NLIB_NOEXCEPT NLIB_NONNULL;
46  NLIB_CHECK_RESULT errno_t Open(const char* filename) NLIB_NOEXCEPT {
47  return Open(filename, NLIB_FD_O_WRONLY | NLIB_FD_O_CREAT | NLIB_FD_O_TRUNC, 0644);
48  }
49  NLIB_CHECK_RESULT errno_t Open(const char* filename, int flags) NLIB_NOEXCEPT {
50  return Open(filename, flags, 0644);
51  }
52  NLIB_CHECK_RESULT errno_t Open(const wchar_t* filename,
53  int flags, int mode) NLIB_NOEXCEPT NLIB_NONNULL;
54  NLIB_CHECK_RESULT errno_t Open(const wchar_t* filename, int flags) NLIB_NOEXCEPT {
55  return Open(filename, flags, 0644);
56  }
57  NLIB_CHECK_RESULT errno_t Open(const wchar_t* filename) NLIB_NOEXCEPT {
58  return Open(filename, NLIB_FD_O_WRONLY | NLIB_FD_O_CREAT | NLIB_FD_O_TRUNC, 0644);
59  }
61  nlib_fd GetFd() const NLIB_NOEXCEPT { return fd_; }
62 
63  private:
64  virtual bool PushBuffer_(const void* p, size_t nbytes,
65  bool do_flush) NLIB_NOEXCEPT NLIB_OVERRIDE;
66  virtual bool Close_() NLIB_NOEXCEPT NLIB_OVERRIDE;
67  virtual bool WriteGather_(const nlib_fd_iovec* iov, int iovcnt) NLIB_NOEXCEPT NLIB_OVERRIDE;
68 
69  private:
70  nlib_fd fd_;
71  unsigned char* buf_;
72  size_t buf_size_;
73  bool is_internal_buffer_;
75 };
76 
77 NLIB_NAMESPACE_END
78 
79 #endif // INCLUDE_NN_NLIB_FILEOUTPUTSTREAM_H_
constexpr FileOutputStreamSettings() noexcept
Instantiates the object with default parameters (default constructor). Sets the default values...
#define NLIB_OVERRIDE
Defines override if it is available for use. If not, holds an empty string.
Definition: Config.h:244
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:179
#define NLIB_FD_O_CREAT
Used for the flags parameter of the nlib_fd_open function.
Definition: Platform.h:1501
The class for file output streams.
#define NLIB_CHECK_RESULT
Indicates that the caller of the function must check the returned value.
void * buf
A pointer to a buffer.
nlib_fd GetFd() const noexcept
Returns the file descriptor.
#define NLIB_FD_INVALID
A macro defining invalid file descriptors.
Definition: Platform.h:1537
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:89
size_t buffer_size
The size of the buffer.
errno_t Init() noexcept
Initializes the stream with the default settings.
#define NLIB_FD_O_WRONLY
Used for the flags parameter of the nlib_fd_open function.
Definition: Platform.h:1480
int nlib_fd
The original file descriptor of nlib (a 32-bit integer value).
Definition: Platform.h:1536
#define NLIB_FD_O_TRUNC
Used for the flags parameter of the nlib_fd_open function.
Definition: Platform.h:1508
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:105
#define NLIB_CEXPR
Defines constexpr if it is available for use. If not, holds an empty string.
Definition: Config.h:107
constexpr FileOutputStream() noexcept
Instantiates the object with default parameters (default constructor). The buffer must be set and ini...
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:245
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