MyGUI: MyGUI_DataStream.cpp Source File

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
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 size_t DataStream::size()
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
38 bool DataStream::eof()
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
MyGUI_DataStream.h
MyGUI_Precompiled.h
MyGUI::DataStream::size
size_t size() override
Definition MyGUI_DataStream.cpp:25
MyGUI::DataStream::read
size_t read(void *_buf, size_t _count) override
Definition MyGUI_DataStream.cpp:50
MyGUI::DataStream::readline
void readline(std::string &_source, Char _delim) override
Definition MyGUI_DataStream.cpp:43
MyGUI::DataStream::mSize
size_t mSize
Definition MyGUI_DataStream.h:29
MyGUI::DataStream::mStream
std::istream * mStream
Definition MyGUI_DataStream.h:28
MyGUI::DataStream::DataStream
DataStream()
Definition MyGUI_DataStream.cpp:13
MyGUI::DataStream::eof
bool eof() override
Definition MyGUI_DataStream.cpp:38
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::Char
unsigned int Char
Definition MyGUI_Types.h:50