MyGUI  3.4.1
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 
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) 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 
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
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:49