SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLIOReaderMemory Class Reference

SLIOStream implementation for reading from memory. More...

#include <SLIOMemory.h>

Inheritance diagram for SLIOReaderMemory:
[legend]

Public Member Functions

 SLIOReaderMemory (std::string path)
 
size_t read (void *buffer, size_t size)
 
size_t tell ()
 
bool seek (size_t offset, Origin origin)
 
size_t size ()
 
- Public Member Functions inherited from SLIOStream
virtual ~SLIOStream ()=default
 
virtual size_t write (const void *buffer, size_t size)
 
virtual void flush ()
 

Protected Attributes

std::string _path
 
size_t _position
 

Additional Inherited Members

- Public Types inherited from SLIOStream
enum  Origin { IOO_beg , IOO_cur , IOO_end }
 

Detailed Description

SLIOStream implementation for reading from memory.

Definition at line 27 of file SLIOMemory.h.

Constructor & Destructor Documentation

◆ SLIOReaderMemory()

SLIOReaderMemory::SLIOReaderMemory ( std::string  path)

Definition at line 39 of file SLIOMemory.cpp.

40  : _path(path)
41 {
42 }
std::string _path
Definition: SLIOMemory.h:37

Member Function Documentation

◆ read()

size_t SLIOReaderMemory::read ( void buffer,
size_t  size 
)
virtual

Reimplemented from SLIOStream.

Definition at line 44 of file SLIOMemory.cpp.

45 {
46  std::vector<char>& memoryFile = memoryFiles[_path];
47  std::memcpy(buffer, memoryFile.data(), size);
48  return size;
49 }
std::unordered_map< std::string, std::vector< char > > memoryFiles
Definition: SLIOMemory.cpp:17

◆ seek()

bool SLIOReaderMemory::seek ( size_t  offset,
Origin  origin 
)
virtual

Reimplemented from SLIOStream.

Definition at line 56 of file SLIOMemory.cpp.

57 {
58  std::vector<char>& memoryFile = memoryFiles[_path];
59  size_t size = (size_t)memoryFile.size();
60  size_t previousPos = _position;
61 
62  switch (origin)
63  {
64  case IOO_beg: _position = offset; break;
65  case IOO_cur: _position += offset; break;
66  case IOO_end: _position = size - 1 - offset; break;
67  }
68 
69  bool ok = _position >= 0 && _position < size;
70  if (!ok)
71  _position = previousPos;
72 
73  return ok;
74 }
size_t _position
Definition: SLIOMemory.h:38

◆ size()

size_t SLIOReaderMemory::size ( )
virtual

Reimplemented from SLIOStream.

Definition at line 76 of file SLIOMemory.cpp.

77 {
78  return memoryFiles[_path].size();
79 }

◆ tell()

size_t SLIOReaderMemory::tell ( )
virtual

Reimplemented from SLIOStream.

Definition at line 51 of file SLIOMemory.cpp.

52 {
53  return _position;
54 }

Member Data Documentation

◆ _path

std::string SLIOReaderMemory::_path
protected

Definition at line 37 of file SLIOMemory.h.

◆ _position

size_t SLIOReaderMemory::_position
protected

Definition at line 38 of file SLIOMemory.h.


The documentation for this class was generated from the following files: