MyGUI 3.4.1
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"
9
10namespace MyGUI
11{
12
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
28 {
29 delete mStream;
30 }
31
33 {
34 return mSize;
35 }
36
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
void readline(std::string &_source, Char _delim) override
size_t read(void *_buf, size_t _count) override
unsigned int Char
Definition: MyGUI_Types.h:49