MyGUI: MyGUI_DataStream.cpp Source File

MyGUI 3.2.2

MyGUI_DataStream.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_DataStream.h"
9
10 namespace MyGUI
11 {
12
13 DataStream::DataStream() :
14 mStream(nullptr),
15 mSize((size_t) - 1)
16 {
17 }
18
19 DataStream::DataStream(std::istream* _stream) :
20 mStream(_stream),
21 mSize((size_t) - 1)
22 {
23 }
24
25 DataStream::~DataStream()
26 {
27 }
28
29 size_t DataStream::size()
30 {
31 if (mStream == nullptr) return 0;
32 if (mSize == (size_t) - 1)
33 {
34 mStream->seekg (0, std::ios::end);
35 mSize = (size_t)mStream->tellg();
36 mStream->seekg (0, std::ios::beg);
37 }
38 return mSize;
39 }
40
41 bool DataStream::eof()
42 {
43 return mStream == nullptr ? true : mStream->eof();
44 }
45
46 void DataStream::readline(std::string& _source, Char _delim)
47 {
48 if (mStream == nullptr) return;
49 std::getline(*mStream, _source, (char)_delim);
50 }
51
52 size_t DataStream::read(void* _buf, size_t _count)
53 {
54 if (mStream == nullptr) return 0;
55 size_t count = std::min(size(), _count);
56 mStream->read((char*)_buf, count);
57 return count;
58 }
59
60 } // namespace MyGUI
MyGUI::DataStream::read
virtual size_t read(void *_buf, size_t _count)
Definition: MyGUI_DataStream.cpp:52
MyGUI::DataStream::size
virtual size_t size()
Definition: MyGUI_DataStream.cpp:29
MyGUI::DataStream::mStream
std::istream * mStream
Definition: MyGUI_DataStream.h:30
MyGUI_DataStream.h
MyGUI::DataStream::readline
virtual void readline(std::string &_source, Char _delim)
Definition: MyGUI_DataStream.cpp:46
MyGUI_Precompiled.h
MyGUI::DataStream::mSize
size_t mSize
Definition: MyGUI_DataStream.h:31
MyGUI::DataStream::DataStream
DataStream()
Definition: MyGUI_DataStream.cpp:13
MyGUI::DataStream::eof
virtual bool eof()
Definition: MyGUI_DataStream.cpp:41
MyGUI::DataStream::~DataStream
virtual ~DataStream()
Definition: MyGUI_DataStream.cpp:25
nullptr
#define nullptr
Definition: MyGUI_Prerequest.h:29
MyGUI::Char
unsigned int Char
Definition: MyGUI_Types.h:51
MyGUI
Definition: MyGUI_ActionController.h:14