nlib
FileInputStream.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_FILEINPUTSTREAM_H_
17 #define INCLUDE_NN_NLIB_FILEINPUTSTREAM_H_
18 
19 #include "nn/nlib/InputStream.h"
20 
21 NLIB_NAMESPACE_BEGIN
22 
24  void* buf;
25  size_t buffer_size;
26 
27  public:
28  NLIB_CEXPR FileInputStreamSettings() NLIB_NOEXCEPT : buf(nullptr), buffer_size(4096) {}
29  NLIB_CEXPR FileInputStreamSettings(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),
38  buf_(nullptr),
39  buf_size_(0),
40  is_internal_buf_(false) {}
45  return this->Init(settings);
46  }
47  NLIB_CHECK_RESULT errno_t Open(const char* filename) NLIB_NOEXCEPT NLIB_NONNULL;
48  NLIB_CHECK_RESULT errno_t Open(const wchar_t* filename) NLIB_NOEXCEPT NLIB_NONNULL;
50  nlib_fd GetFd() const NLIB_NOEXCEPT { return fd_; }
51 
52  private:
53  virtual size_t FillBuffer_(void* p, size_t nbytes) NLIB_NOEXCEPT NLIB_OVERRIDE;
54  virtual bool Close_() NLIB_NOEXCEPT NLIB_OVERRIDE;
55 
56  private:
57  nlib_fd fd_;
58  unsigned char* buf_;
59  size_t buf_size_;
60  bool is_internal_buf_;
62 };
63 
64 NLIB_NAMESPACE_END
65 
66 #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:249
The structure that stores information about the file stream settings.
constexpr FileInputStream() noexcept
Instantiates the object with default parameters (default constructor). Requires initialization with I...
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:183
Defines the base class for input streams.
#define NLIB_CHECK_RESULT
Indicates that the caller of the function must check the returned value.
size_t buffer_size
The size of the buffer used by FileInputStream. The default is 4096.
#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
int nlib_fd
The original file descriptor of nlib (a 32-bit integer value).
Definition: Platform.h:1513
The base class for input streams. This class cannot be instantiated.
Definition: InputStream.h:29
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:109
#define NLIB_CEXPR
Defines constexpr if it is available for use. If not, holds an empty string.
Definition: Config.h:111
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:250
constexpr FileInputStreamSettings() noexcept
Instantiates the object with default parameters (default constructor). The setting to allocate the Fi...
void * buf
The pointer to the buffer used by FileInputStream. The default is NULL.
#define NLIB_NONNULL
Indicates that you cannot specify NULL for all arguments.
int errno_t
Indicates with an int-type typedef that a POSIX error value is returned as the return value...
Definition: NMalloc.h:37