MyGUI 3.4.3
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
10namespace MyGUI
11{
12
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
26 {
27 if (mStream == nullptr)
28 return 0;
29 if (mSize == (size_t)-1)
30 {
31 mStream->seekg(0, std::ios::end);
32 mSize = (size_t)mStream->tellg();
33 mStream->seekg(0, std::ios::beg);
34 }
35 return mSize;
36 }
37
39 {
40 return mStream == nullptr ? true : mStream->eof();
41 }
42
43 void DataStream::readline(std::string& _source, Char _delim)
44 {
45 if (mStream == nullptr)
46 return;
47 std::getline(*mStream, _source, (char)_delim);
48 }
49
50 size_t DataStream::read(void* _buf, size_t _count)
51 {
52 if (mStream == nullptr)
53 return 0;
54 size_t count = std::min(size(), _count);
55 mStream->read((char*)_buf, count);
56 return count;
57 }
58
59} // namespace MyGUI
size_t size() override
size_t read(void *_buf, size_t _count) override
void readline(std::string &_source, Char _delim) override
std::istream * mStream
bool eof() override
unsigned int Char
Definition MyGUI_Types.h:50