1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2010 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 #include "OSGOgreChunkReader.h"
40 #include "OSGOgreLog.h"
46 const Int32
OgreChunkReader::_chunkHeaderSize(sizeof(UInt16
) + sizeof(UInt32
));
49 OgreChunkReader::OgreChunkReader(std::istream
& is
)
56 OgreChunkReader::~OgreChunkReader(void)
61 OgreChunkReader::readChunkHeader(std::istream
& is
)
63 _header
.chunkId
= readUInt16(is
);
64 _header
.chunkSize
= readUInt32(is
);
68 OgreChunkReader::skip(std::istream
& is
, Int32 offset
)
70 is
.seekg(offset
, std::ios_base::cur
);
74 OgreChunkReader::readString(std::istream
& is
)
77 std::ostringstream oss
;
79 is
.get(*oss
.rdbuf(), '\n');
80 is
.get(); // remove '\n'
84 if(result
.empty() == false && result
[result
.length() - 1] == '\r')
86 result
.erase(result
.length() - 1);
93 OgreChunkReader::readBool(std::istream
& is
)
97 readBool(is
, &retVal
, 1);
103 OgreChunkReader::readBool(std::istream
& is
, bool* values
, UInt32 count
)
105 for(; count
> 0; --count
)
107 *values
= is
.get() != 0 ? true : false;
113 OgreChunkReader::readInt16(std::istream
& is
)
117 readInt16(is
, &retVal
, 1);
123 OgreChunkReader::readInt16(std::istream
& is
, Int16
* values
, UInt32 count
)
125 is
.read(reinterpret_cast<Char8
*>(values
), count
* sizeof(Int16
));
129 OgreChunkReader::readUInt16(std::istream
& is
)
133 readUInt16(is
, &retVal
, 1);
139 OgreChunkReader::readUInt16(std::istream
& is
, UInt16
* values
, UInt32 count
)
141 is
.read(reinterpret_cast<Char8
*>(values
), count
* sizeof(UInt16
));
145 OgreChunkReader::readUInt32(std::istream
& is
)
149 readUInt32(is
, &retVal
, 1);
155 OgreChunkReader::readUInt32(std::istream
& is
, UInt32
* values
, UInt32 count
)
157 is
.read(reinterpret_cast<Char8
*>(values
), count
* sizeof(UInt32
));
161 OgreChunkReader::readReal32(std::istream
& is
)
165 readReal32(is
, &retVal
, 1);
171 OgreChunkReader::readReal32(std::istream
& is
, Real32
* values
, UInt32 count
)
173 is
.read(reinterpret_cast<Char8
*>(values
), count
* sizeof(Real32
));