nlib
MemoryInputStream.h
[詳解]
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_MEMORYINPUTSTREAM_H_
17 #define INCLUDE_NN_NLIB_MEMORYINPUTSTREAM_H_
18 
19 #include "nn/nlib/InputStream.h"
20 
21 NLIB_NAMESPACE_BEGIN
22 
24  public:
25  NLIB_CEXPR MemoryInputStream() NLIB_NOEXCEPT : mis_buf_(nullptr), mis_size_(0) {}
27  template <class T, size_t N>
28  NLIB_CEXPR explicit MemoryInputStream(const T (&buf)[N]) NLIB_NOEXCEPT
29  : mis_buf_(static_cast<const nlib_byte_t*>(static_cast<const void*>(&buf[0]))),
30  mis_size_(N * sizeof(T)) {
31  // T must be pod
32  }
33  NLIB_CEXPR MemoryInputStream(const void* buf, size_t n) NLIB_NOEXCEPT
34  : mis_buf_(static_cast<const nlib_byte_t*>(buf)), mis_size_(n) {}
35  template <class T, size_t N>
36  errno_t Init(const T (&buf)[N]) NLIB_NOEXCEPT {
37  return this->Init(&buf[0], N * sizeof(T));
38  }
39  errno_t Init(const nlib_byte_t* buf, size_t n) NLIB_NOEXCEPT NLIB_NONNULL;
40  errno_t Init(const void* buf, size_t n) NLIB_NOEXCEPT {
41  return Init(static_cast<const nlib_byte_t*>(buf), n);
42  }
43 
44  private:
45  virtual size_t FillBuffer_(void* p, size_t nbytes) NLIB_NOEXCEPT NLIB_OVERRIDE;
46  virtual bool Close_() NLIB_NOEXCEPT NLIB_OVERRIDE {
47  mis_buf_ = nullptr;
48  mis_size_ = 0;
49  return true;
50  }
51 
52  private:
53  const nlib_byte_t* mis_buf_;
54  size_t mis_size_;
56 };
57 
58 NLIB_NAMESPACE_END
59 
60 #endif // INCLUDE_NN_NLIB_MEMORYINPUTSTREAM_H_
errno_t Init(const void *buf, size_t n) noexcept
MemoryInputStreamを初期化して利用できるようにします。
#define NLIB_OVERRIDE
利用可能であればoverrideが定義されます。そうでない場合は空文字列です。
Definition: Config.h:244
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName で指定されたクラスのコピーコンストラクタと代入演算子を禁止します。
Definition: Config.h:179
入力ストリームの基底クラスを定義しています。
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:89
constexpr MemoryInputStream() noexcept
デフォルトコンストラクタです。利用前にInit()メンバ関数を呼び出す必要があります。
constexpr MemoryInputStream(const void *buf, size_t n) noexcept
MemoryInputStreamを構築して初期化します。
constexpr MemoryInputStream(const T(&buf)[N]) noexcept
MemoryInputStreamを構築して初期化します。
入力ストリームの基底クラスです。このクラスを実体化することはできません。
Definition: InputStream.h:29
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Config.h:105
#define NLIB_CEXPR
利用可能であればconstexprが定義されます。そうでない場合は空文字列です。
Definition: Config.h:107
メモリを使用する入力ストリームを作成します。
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
Definition: Config.h:245
errno_t Init(const T(&buf)[N]) noexcept
MemoryInputStreamを初期化して利用できるようにします。
unsigned char nlib_byte_t
C++17以降でstd::byteにtypedefされる型です。
Definition: Platform.h:319
#define NLIB_NONNULL
全ての引数にNULLを指定することができないことを示します。
int errno_t
intのtypedefで、戻り値としてPOSIXのエラー値を返すことを示します。
Definition: NMalloc.h:37