fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / FileIO / Ogre / OSGOgreChunkReader.cpp
blob26c22f2527187d9f5f75d0d7ec970a40ad6bddd1
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2010 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
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. *
18 * *
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. *
23 * *
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. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 #include "OSGOgreChunkReader.h"
40 #include "OSGOgreLog.h"
42 #include <sstream>
44 OSG_BEGIN_NAMESPACE
46 const Int32 OgreChunkReader::_chunkHeaderSize(sizeof(UInt16) + sizeof(UInt32));
48 /* explicit */
49 OgreChunkReader::OgreChunkReader(std::istream& is)
50 : _header(),
51 _is (is)
55 /* virtual */
56 OgreChunkReader::~OgreChunkReader(void)
60 void
61 OgreChunkReader::readChunkHeader(std::istream& is)
63 _header.chunkId = readUInt16(is);
64 _header.chunkSize = readUInt32(is);
67 void
68 OgreChunkReader::skip(std::istream& is, Int32 offset)
70 is.seekg(offset, std::ios_base::cur);
73 std::string
74 OgreChunkReader::readString(std::istream& is)
76 std::string result;
77 std::ostringstream oss;
79 is.get(*oss.rdbuf(), '\n');
80 is.get(); // remove '\n'
82 result = oss.str();
84 if(result.empty() == false && result[result.length() - 1] == '\r')
86 result.erase(result.length() - 1);
89 return result;
92 bool
93 OgreChunkReader::readBool(std::istream& is)
95 bool retVal;
97 readBool(is, &retVal, 1);
99 return retVal;
102 void
103 OgreChunkReader::readBool(std::istream& is, bool* values, UInt32 count)
105 for(; count > 0; --count)
107 *values = is.get() != 0 ? true : false;
108 ++values;
112 Int16
113 OgreChunkReader::readInt16(std::istream& is)
115 Int16 retVal;
117 readInt16(is, &retVal, 1);
119 return retVal;
122 void
123 OgreChunkReader::readInt16(std::istream& is, Int16* values, UInt32 count)
125 is.read(reinterpret_cast<Char8 *>(values), count * sizeof(Int16));
128 UInt16
129 OgreChunkReader::readUInt16(std::istream& is)
131 UInt16 retVal;
133 readUInt16(is, &retVal, 1);
135 return retVal;
138 void
139 OgreChunkReader::readUInt16(std::istream& is, UInt16* values, UInt32 count)
141 is.read(reinterpret_cast<Char8 *>(values), count * sizeof(UInt16));
144 UInt32
145 OgreChunkReader::readUInt32(std::istream& is)
147 UInt32 retVal;
149 readUInt32(is, &retVal, 1);
151 return retVal;
154 void
155 OgreChunkReader::readUInt32(std::istream& is, UInt32* values, UInt32 count)
157 is.read(reinterpret_cast<Char8 *>(values), count * sizeof(UInt32));
160 Real32
161 OgreChunkReader::readReal32(std::istream& is)
163 Real32 retVal;
165 readReal32(is, &retVal, 1);
167 return retVal;
170 void
171 OgreChunkReader::readReal32(std::istream& is, Real32* values, UInt32 count)
173 is.read(reinterpret_cast<Char8 *>(values), count * sizeof(Real32));
176 OSG_END_NAMESPACE