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(NULL), 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  buf_(NULL),
38  buf_size_(0),
39  is_internal_buf_(false) {}
43  return this->Init(settings);
44  }
46  NLIB_CHECK_RESULT errno_t Open(const char* filename) NLIB_NOEXCEPT NLIB_NONNULL;
47  NLIB_CHECK_RESULT errno_t Open(const wchar_t* filename) NLIB_NOEXCEPT NLIB_NONNULL;
49  nlib_fd GetFd() const NLIB_NOEXCEPT { return fd_; }
50 
51  private:
52  virtual size_t FillBuffer_(void* p, size_t nbytes) NLIB_NOEXCEPT NLIB_OVERRIDE;
53  virtual bool Close_() NLIB_NOEXCEPT NLIB_OVERRIDE;
54  virtual void* GetWorkBuffer_(size_t* nbytes) 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:228
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...
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:163
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.
#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:89
errno_t Init() noexcept
Initializes the stream with the default settings.
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:99
#define NLIB_CEXPR
Defines constexpr if it is available for use. If not, holds an empty string.
Definition: Config.h:93
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:229
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_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