MyGUI: MyGUI_DataStream.cpp Source File

MyGUI 3.4.2

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

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