MyGUI 3.2.0

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

- File List
- Globals

MyGUI_DataStream.cpp
Go to the documentation of this file.
1
6 /*
7 This file is part of MyGUI.
8
9 MyGUI is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 MyGUI is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #include "MyGUI_Precompiled.h"
23 #include "MyGUI_DataStream.h"
24
25 namespace MyGUI
26 {
27
28 DataStream::DataStream() :
29 mStream(nullptr),
30 mSize((size_t) - 1)
31 {
32 }
33
34 DataStream::DataStream(std::istream* _stream) :
35 mStream(_stream),
36 mSize((size_t) - 1)
37 {
38 }
39
40 DataStream::~DataStream()
41 {
42 }
43
44 size_t DataStream::size()
45 {
46 if (mStream == nullptr) return 0;
47 if (mSize == (size_t) - 1)
48 {
49 mStream->seekg (0, std::ios::end);
50 mSize = (size_t)mStream->tellg();
51 mStream->seekg (0, std::ios::beg);
52 }
53 return mSize;
54 }
55
56 bool DataStream::eof()
57 {
58 return mStream == nullptr ? true : mStream->eof();
59 }
60
61 void DataStream::readline(std::string& _source, Char _delim)
62 {
63 if (mStream == nullptr) return;
64 std::getline(*mStream, _source, (char)_delim);
65 }
66
67 size_t DataStream::read(void* _buf, size_t _count)
68 {
69 if (mStream == nullptr) return 0;
70 size_t count = std::min(size(), _count);
71 mStream->read((char*)_buf, count);
72 return count;
73 }
74
75 } // namespace MyGUI
MyGUI_Precompiled.h
MyGUI::DataStream::DataStream
DataStream()
Definition: MyGUI_DataStream.cpp:28
MyGUI::DataStream::eof
virtual bool eof()
Definition: MyGUI_DataStream.cpp:56
MyGUI::DataStream::read
virtual size_t read(void *_buf, size_t _count)
Definition: MyGUI_DataStream.cpp:67
nullptr
#define nullptr
Definition: MyGUI_Prerequest.h:47
MyGUI::DataStream::size
virtual size_t size()
Definition: MyGUI_DataStream.cpp:44
MyGUI::DataStream::mStream
std::istream * mStream
Definition: MyGUI_DataStream.h:45
MyGUI::Char
unsigned int Char
Definition: MyGUI_Types.h:66
MyGUI_DataStream.h
MyGUI::DataStream::readline
virtual void readline(std::string &_source, Char _delim)
Definition: MyGUI_DataStream.cpp:61
MyGUI::DataStream::mSize
size_t mSize
Definition: MyGUI_DataStream.h:46
MyGUI::DataStream::~DataStream
virtual ~DataStream()
Definition: MyGUI_DataStream.cpp:40