nlib
MemoryOutputStream.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_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  NLIB_CEXPR MemoryOutputStream() NLIB_NOEXCEPT : mos_buf_(nullptr), mos_pos_(0), mos_size_(0) {}
27  : mos_buf_(static_cast<nlib_byte_t*>(buf)), mos_pos_(0), mos_size_(n) {}
28  template <class T, size_t N>
30  : mos_buf_(static_cast<nlib_byte_t*>(static_cast<void*>(&buf[0]))),
31  mos_pos_(0),
32  mos_size_(N * sizeof(T)) {}
34  const void* data() const NLIB_NOEXCEPT { return mos_buf_; }
35  errno_t Init(nlib_byte_t* buf, size_t n) NLIB_NOEXCEPT NLIB_NONNULL;
36  errno_t Init(void* buf, size_t n) NLIB_NOEXCEPT NLIB_NONNULL {
37  return Init(static_cast<nlib_byte_t*>(buf), n);
38  }
39  template <class T, size_t N>
40  errno_t Init(T (&buf)[N]) NLIB_NOEXCEPT {
41  return this->Init(&buf[0], N * sizeof(T));
42  }
43 
44  private:
45  virtual bool PushBuffer_(const void* p, size_t nbytes,
46  bool do_flush) NLIB_NOEXCEPT NLIB_OVERRIDE;
47  virtual bool Close_() NLIB_NOEXCEPT NLIB_OVERRIDE {
48  mos_buf_ = nullptr;
49  mos_pos_ = 0;
50  mos_size_ = 0;
51  return true;
52  }
53  virtual void* GetWorkBuffer_(size_t* nbytes) NLIB_NOEXCEPT NLIB_OVERRIDE;
54 
55  private:
56  nlib_byte_t* mos_buf_;
57  size_t mos_pos_;
58  size_t mos_size_;
60 };
61 
62 NLIB_NAMESPACE_END
63 
64 #endif // INCLUDE_NN_NLIB_MEMORYOUTPUTSTREAM_H_
#define NLIB_OVERRIDE
Defines override if it is available for use. If not, holds an empty string.
Definition: Config.h:244
constexpr MemoryOutputStream() noexcept
Instantiates the object with default parameters (default constructor). You must call the Init functio...
constexpr MemoryOutputStream(T(&buf)[N]) noexcept
Constructs and initializes MemoryOutputStream.
#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
constexpr MemoryOutputStream(void *buf, size_t n) noexcept
Constructs and initializes MemoryOutputStream.
The class for creating an output stream that makes use of memory.
errno_t Init(void *buf, size_t n) noexcept
Initializes MemoryOuputStream and makes it available for use.
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:89
const void * data() const noexcept
Gets a pointer to the start of the output data.
errno_t Init(T(&buf)[N]) noexcept
Initializes MemoryOuputStream and makes it available for use.
#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
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:245
unsigned char nlib_byte_t
This type will be defined as std::byte in a typedef of C++17 or later.
Definition: Platform.h:319
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