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 : mis_buf_(NULL), mis_size_(0) {}
14  template <class T, size_t N>
15  explicit MemoryInputStream(const T (&buf)[N]) NLIB_NOEXCEPT
16  : mis_buf_(reinterpret_cast<const uint8_t*>(&buf[0])), mis_size_(N * sizeof(T)) {}
17  MemoryInputStream(const void* buf, size_t n) NLIB_NOEXCEPT NLIB_NONNULL;
18  template <class T, size_t N>
19  errno_t Init(const T (&buf)[N]) NLIB_NOEXCEPT {
20  return this->Init(&buf[0], N * sizeof(T));
21  }
22  errno_t 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  mis_buf_ = NULL;
28  mis_size_ = 0;
29  return true;
30  }
31 
32  private:
33  const uint8_t* mis_buf_;
34  size_t mis_size_;
36 };
37 
38 NLIB_NAMESPACE_END
39 
40 #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:210
#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:145
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:61
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:16
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:86
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:211
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.
Definition: Platform_unix.h:76
int errno_t
Indicates with an int-type typedef that a POSIX error value is returned as the return value...
Definition: NMalloc.h:24