MyGUI 3.2.2

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
10 namespace MyGUI
11 {
12
13 DataMemoryStream::DataMemoryStream() :
14 mData(nullptr),
15 mSize(0),
16 mStream(0)
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_Precompiled.h
MyGUI::DataMemoryStream::readline
virtual void readline(std::string &_source, Char _delim)
Definition: MyGUI_DataMemoryStream.cpp:45
MyGUI::DataMemoryStream::DataMemoryStream
DataMemoryStream()
Definition: MyGUI_DataMemoryStream.cpp:13
MyGUI::DataMemoryStream::mData
unsigned char * mData
Definition: MyGUI_DataMemoryStream.h:33
MyGUI::DataMemoryStream::mStream
std::stringstream * mStream
Definition: MyGUI_DataMemoryStream.h:35
nullptr
#define nullptr
Definition: MyGUI_Prerequest.h:29
MyGUI_DataMemoryStream.h
MyGUI::DataMemoryStream::size
virtual size_t size()
Definition: MyGUI_DataMemoryStream.cpp:32
MyGUI::DataMemoryStream::~DataMemoryStream
virtual ~DataMemoryStream()
Definition: MyGUI_DataMemoryStream.cpp:27
MyGUI
Definition: MyGUI_ActionController.h:14
MyGUI::DataMemoryStream::mSize
size_t mSize
Definition: MyGUI_DataMemoryStream.h:34
MyGUI::Char
unsigned int Char
Definition: MyGUI_Types.h:51
MyGUI::DataMemoryStream::eof
virtual bool eof()
Definition: MyGUI_DataMemoryStream.cpp:37
MyGUI::DataMemoryStream::read
virtual size_t read(void *_buf, size_t _count)
Definition: MyGUI_DataMemoryStream.cpp:53