nlib
MemoryInputStream.h
Go to the documentation of this file.
1 
2 /*---------------------------------------------------------------------------*
3 
4  Project: CrossRoad
5  Copyright (C)2012-2016 Nintendo. All rights reserved.
6 
7  These coded instructions, statements, and computer programs contain
8  proprietary information of Nintendo of America Inc. and/or Nintendo
9  Company Ltd., and are protected by Federal copyright law. They may
10  not be disclosed to third parties or copied or duplicated in any form,
11  in whole or in part, without the prior written consent of Nintendo.
12 
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  MemoryInputStream() NLIB_NOEXCEPT : mis_buf_(NULL), mis_size_(0) {}
27  template <class T, size_t N>
28  explicit MemoryInputStream(const T (&buf)[N]) NLIB_NOEXCEPT
29  : mis_buf_(reinterpret_cast<const uint8_t*>(&buf[0])), mis_size_(N * sizeof(T)) {}
30  MemoryInputStream(const void* buf, size_t n) NLIB_NOEXCEPT NLIB_NONNULL;
31  template <class T, size_t N>
32  errno_t Init(const T (&buf)[N]) NLIB_NOEXCEPT {
33  return this->Init(&buf[0], N * sizeof(T));
34  }
35  errno_t Init(const void* buf, size_t n) NLIB_NOEXCEPT NLIB_NONNULL;
36 
37  private:
38  virtual size_t FillBuffer_(void* p, size_t nbytes) NLIB_NOEXCEPT NLIB_OVERRIDE;
39  virtual bool Close_() NLIB_NOEXCEPT NLIB_OVERRIDE {
40  mis_buf_ = NULL;
41  mis_size_ = 0;
42  return true;
43  }
44 
45  private:
46  const uint8_t* mis_buf_;
47  size_t mis_size_;
49 };
50 
51 NLIB_NAMESPACE_END
52 
53 #endif // INCLUDE_NN_NLIB_MEMORYINPUTSTREAM_H_
#define NLIB_OVERRIDE
Defines override if it is available for use. If not, holds an empty string.
Definition: Config.h:223
#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:158
Defines the base class for input streams.
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:87
MemoryInputStream() noexcept
Instantiates the object with default parameters (default constructor). You must call the Init functio...
MemoryInputStream(const T(&buf)[N]) noexcept
Constructs and initializes MemoryInputStream.
The base class for input streams. This class cannot be instantiated.
Definition: InputStream.h:29
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:99
The class for creating an input stream that makes use of memory.
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:224
errno_t Init(const T(&buf)[N]) noexcept
Initializes MemoryInputStream and makes it available for use.
#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