nlib
MemoryInputStream.h
Go to the documentation of this file.
1 
2 #pragma once
3 #ifndef INCLUDE_NN_NLIB_MEMORYINPUTSTREAM_H_
4 #define INCLUDE_NN_NLIB_MEMORYINPUTSTREAM_H_
5 
6 #include "nn/nlib/InputStream.h"
7 
8 NLIB_NAMESPACE_BEGIN
9 
11  public:
12  MemoryInputStream() NLIB_NOEXCEPT : m_Buf(NULL), m_Size(0) {}
14  template <class T, size_t N>
15  explicit MemoryInputStream(const T(&buf)[N]) NLIB_NOEXCEPT : m_Buf(buf),
16  m_Size(N * sizeof(T)) {}
17  MemoryInputStream(const void* buf, size_t n) NLIB_NOEXCEPT NLIB_NONNULL;
18  template <class T, size_t N>
19  void Init(const T(&buf)[N]) NLIB_NOEXCEPT {
20  this->Init(&buf[0], N * sizeof(T));
21  }
22  void Init(const void* buf, size_t n) NLIB_NOEXCEPT NLIB_NONNULL;
23 
24  private:
25  virtual size_t FillBuffer_(void* p, size_t nBytes) NLIB_NOEXCEPT NLIB_OVERRIDE;
26  virtual bool Close_() NLIB_NOEXCEPT NLIB_OVERRIDE {
27  m_Buf = NULL;
28  m_Size = 0;
29  return true;
30  }
31 
32  private:
33  const void* m_Buf;
34  size_t m_Size;
35  NLIB_DISALLOW_COPY_AND_ASSIGN(MemoryInputStream);
36 };
37 
38 NLIB_NAMESPACE_END
39 
40 #endif // INCLUDE_NN_NLIB_MEMORYINPUTSTREAM_H_
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Platform.h:2151
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
#define NLIB_NONNULL
Indicates that you cannot specify NULL for all arguments.
Definition: Platform_unix.h:66
#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:126
Defines the base class for input streams.
#define NLIB_OVERRIDE
Defines override if it is available for use. If not, holds an empty string.
MemoryInputStream() noexcept
Instantiates the object with default parameters (default constructor). You must call the Init functio...
The base class for input streams. This class cannot be instantiated.
Definition: InputStream.h:15
The class for creating an input stream that makes use of memory.
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:51
void Init(const T(&buf)[N]) noexcept
Initializes MemoryInputStream and makes it available for use.