MyGUI: MyGUI_DataMemoryStream.cpp Source File

MyGUI 3.4.2

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

MyGUI_DataMemoryStream.cpp
Go to the documentation of this file.
1/*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7#include "MyGUI_Precompiled.h"
8#include "MyGUI_DataMemoryStream.h"
9
10namespace MyGUI
11{
12
13 DataMemoryStream::DataMemoryStream() :
14 mData(nullptr),
15 mSize(0),
16 mStream(nullptr)
17 {
18 }
19
20 DataMemoryStream::DataMemoryStream(unsigned char* _data, size_t _size) :
21 mData(_data),
22 mSize(_size),
23 mStream(nullptr)
24 {
25 }
26
27 DataMemoryStream::~DataMemoryStream()
28 {
29 delete mStream;
30 }
31
32 size_t DataMemoryStream::size()
33 {
34 return mSize;
35 }
36
37 bool DataMemoryStream::eof()
38 {
39 if (mStream == nullptr)
40 prepareStream();
41
42 return mStream->eof();
43 }
44
45 void DataMemoryStream::readline(std::string& _source, Char _delim)
46 {
47 if (mStream == nullptr)
48 prepareStream();
49
50 std::getline(*mStream, _source, (char)_delim);
51 }
52
53 size_t DataMemoryStream::read(void* _buf, size_t _count)
54 {
55 if (mData == nullptr)
56 return 0;
57
58 size_t count = (std::min)(size(), _count);
59 ::memcpy(_buf, mData, count);
60 return count;
61 }
62
63 void DataMemoryStream::prepareStream()
64 {
65 if (mData == nullptr)
66 return;
67
68 mStream = new std::stringstream((const char*)mData);
69 }
70
71} // namespace MyGUI
MyGUI_DataMemoryStream.h
MyGUI_Precompiled.h
MyGUI::DataMemoryStream::readline
void readline(std::string &_source, Char _delim) override
Definition MyGUI_DataMemoryStream.cpp:45
MyGUI::DataMemoryStream::eof
bool eof() override
Definition MyGUI_DataMemoryStream.cpp:37
MyGUI::DataMemoryStream::mSize
size_t mSize
Definition MyGUI_DataMemoryStream.h:34
MyGUI::DataMemoryStream::size
size_t size() override
Definition MyGUI_DataMemoryStream.cpp:32
MyGUI::DataMemoryStream::~DataMemoryStream
~DataMemoryStream() override
Definition MyGUI_DataMemoryStream.cpp:27
MyGUI::DataMemoryStream::mStream
std::stringstream * mStream
Definition MyGUI_DataMemoryStream.h:35
MyGUI::DataMemoryStream::read
size_t read(void *_buf, size_t _count) override
Definition MyGUI_DataMemoryStream.cpp:53
MyGUI::DataMemoryStream::mData
unsigned char * mData
Definition MyGUI_DataMemoryStream.h:33
MyGUI::DataMemoryStream::DataMemoryStream
DataMemoryStream()
Definition MyGUI_DataMemoryStream.cpp:13
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::Char
unsigned int Char
Definition MyGUI_Types.h:50