2 Copyright (C) 2001-2006, William Joseph.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #if !defined(INCLUDED_BYTESTREAMUTILS_H)
23 #define INCLUDED_BYTESTREAMUTILS_H
29 typedef signed short int16_t;
30 typedef unsigned short uint16_t;
31 typedef signed int int32_t;
32 typedef unsigned int uint32_t;
36 #define _ISOC9X_SOURCE 1
37 #define _ISOC99_SOURCE 1
39 #define __USE_ISOC9X 1
40 #define __USE_ISOC99 1
47 template<typename InputStreamType, typename Type>
48 inline void istream_read_little_endian(InputStreamType& istream, Type& value)
50 istream.read(reinterpret_cast<typename InputStreamType::byte_type*>(&value), sizeof(Type));
51 #if defined(__BIG_ENDIAN__)
52 std::reverse(reinterpret_cast<typename InputStreamType::byte_type*>(&value), reinterpret_cast<typename InputStreamType::byte_type*>(&value) + sizeof(Type));
56 template<typename InputStreamType, typename Type>
57 inline void istream_read_big_endian(InputStreamType& istream, Type& value)
59 istream.read(reinterpret_cast<typename InputStreamType::byte_type*>(&value), sizeof(Type));
60 #if !defined(__BIG_ENDIAN__)
61 std::reverse(reinterpret_cast<typename InputStreamType::byte_type*>(&value), reinterpret_cast<typename InputStreamType::byte_type*>(&value) + sizeof(Type));
65 template<typename InputStreamType>
66 inline void istream_read_byte(InputStreamType& istream, typename InputStreamType::byte_type& b)
72 template<typename InputStreamType>
73 inline int16_t istream_read_int16_le(InputStreamType& istream)
76 istream_read_little_endian(istream, value);
80 template<typename InputStreamType>
81 inline uint16_t istream_read_uint16_le(InputStreamType& istream)
84 istream_read_little_endian(istream, value);
88 template<typename InputStreamType>
89 inline int32_t istream_read_int32_le(InputStreamType& istream)
92 istream_read_little_endian(istream, value);
96 template<typename InputStreamType>
97 inline uint32_t istream_read_uint32_le(InputStreamType& istream)
100 istream_read_little_endian(istream, value);
104 template<typename InputStreamType>
105 inline float istream_read_float32_le(InputStreamType& istream)
108 istream_read_little_endian(istream, value);
112 template<typename InputStreamType>
113 inline typename InputStreamType::byte_type istream_read_byte(InputStreamType& istream)
115 typename InputStreamType::byte_type b;
116 istream.read(&b, sizeof(typename InputStreamType::byte_type));