MyGUI
3.0.3
|
00001 00007 /* 00008 This file is part of MyGUI. 00009 00010 MyGUI is free software: you can redistribute it and/or modify 00011 it under the terms of the GNU Lesser General Public License as published by 00012 the Free Software Foundation, either version 3 of the License, or 00013 (at your option) any later version. 00014 00015 MyGUI is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU Lesser General Public License for more details. 00019 00020 You should have received a copy of the GNU Lesser General Public License 00021 along with MyGUI. If not, see <http://www.gnu.org/licenses/>. 00022 */ 00023 #include "MyGUI_Precompiled.h" 00024 #include "MyGUI_DataStream.h" 00025 00026 namespace MyGUI 00027 { 00028 00029 DataStream::DataStream() : 00030 mStream(nullptr), 00031 mSize((size_t)-1) 00032 { 00033 } 00034 00035 DataStream::DataStream(std::istream* _stream) : 00036 mStream(_stream), 00037 mSize((size_t)-1) 00038 { 00039 } 00040 00041 DataStream::~DataStream() 00042 { 00043 } 00044 00045 size_t DataStream::size() 00046 { 00047 if (mStream == nullptr) return 0; 00048 if (mSize == (size_t)-1) 00049 { 00050 mStream->seekg (0, std::ios::end); 00051 mSize = mStream->tellg(); 00052 mStream->seekg (0, std::ios::beg); 00053 } 00054 return mSize; 00055 } 00056 00057 bool DataStream::eof() 00058 { 00059 return mStream == nullptr ? true : mStream->eof(); 00060 } 00061 00062 void DataStream::readline(std::string& _source, Char _delim) 00063 { 00064 if (mStream == nullptr) return; 00065 std::getline(*mStream, _source, (char)_delim); 00066 } 00067 00068 size_t DataStream::read(void* _buf, size_t _count) 00069 { 00070 if (mStream == nullptr) return 0; 00071 size_t count = std::min(size(), _count); 00072 mStream->read((char*)_buf, count); 00073 return count; 00074 } 00075 00076 } // namespace MyGUI