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

SLIOStream implementation for reading to memory. More...

#include <SLIOMemory.h>

Inheritance diagram for SLIOWriterMemory:
[legend]

Public Member Functions

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

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 to memory.

Definition at line 42 of file SLIOMemory.h.

Constructor & Destructor Documentation

◆ SLIOWriterMemory()

SLIOWriterMemory::SLIOWriterMemory ( std::string  path)

Definition at line 81 of file SLIOMemory.cpp.

82  : _path(path),
83  _position(0)
84 {
85  memoryFiles[_path].clear();
86 }
std::unordered_map< std::string, std::vector< char > > memoryFiles
Definition: SLIOMemory.cpp:17
size_t _position
Definition: SLIOMemory.h:53
std::string _path
Definition: SLIOMemory.h:52

Member Function Documentation

◆ flush()

void SLIOWriterMemory::flush ( )
virtual

Reimplemented from SLIOStream.

Definition at line 121 of file SLIOMemory.cpp.

122 {
123 }

◆ seek()

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

Reimplemented from SLIOStream.

Definition at line 101 of file SLIOMemory.cpp.

102 {
103  std::vector<char>& memoryFile = memoryFiles[_path];
104  size_t size = (size_t)memoryFile.size();
105  size_t previousPos = _position;
106 
107  switch (origin)
108  {
109  case IOO_beg: _position = offset; break;
110  case IOO_cur: _position += offset; break;
111  case IOO_end: _position = size - 1 - offset; break;
112  }
113 
114  bool ok = _position >= 0 && _position < size;
115  if (!ok)
116  _position = previousPos;
117 
118  return ok;
119 }
virtual size_t size()
Definition: SLFileStorage.h:76

◆ tell()

size_t SLIOWriterMemory::tell ( )
virtual

Reimplemented from SLIOStream.

Definition at line 96 of file SLIOMemory.cpp.

97 {
98  return _position;
99 }

◆ write()

size_t SLIOWriterMemory::write ( const void buffer,
size_t  size 
)
virtual

Reimplemented from SLIOStream.

Definition at line 88 of file SLIOMemory.cpp.

89 {
90  std::vector<char>& memoryFile = memoryFiles[_path];
91  memoryFile.insert(memoryFile.end(), (char*)buffer, (char*)buffer + size);
92  _position += size;
93  return size;
94 }

Member Data Documentation

◆ _path

std::string SLIOWriterMemory::_path
protected

Definition at line 52 of file SLIOMemory.h.

◆ _position

size_t SLIOWriterMemory::_position
protected

Definition at line 53 of file SLIOMemory.h.


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