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