MyGUI  3.2.0
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 
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 
41  {
42  }
43 
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 
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