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