1 // IOChannel.cpp - a virtual IO channel, for Gnash
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "IOChannel.h"
24 #include <boost/static_assert.hpp>
30 IOChannel::read_le32()
32 // read_byte() is boost::uint8_t, so no masks with 0xff are required.
33 boost::uint32_t result
= static_cast<boost::uint32_t>(read_byte());
34 result
|= static_cast<boost::uint32_t>(read_byte()) << 8;
35 result
|= static_cast<boost::uint32_t>(read_byte()) << 16;
36 result
|= static_cast<boost::uint32_t>(read_byte()) << 24;
41 IOChannel::read_le16()
43 boost::uint16_t result
= static_cast<boost::uint16_t>(read_byte());
44 result
|= static_cast<boost::uint16_t>(read_byte()) << 8;
49 IOChannel::read_string(char* dst
, int max_length
)
55 if (dst
[i
]=='\0') return i
;
59 dst
[max_length
- 1] = '\0'; // force termination.
65 IOChannel::read_float32()
72 BOOST_STATIC_ASSERT(sizeof(u
) == sizeof(u
.i
));
79 IOChannel::read_byte()
82 if ( read(&u
, 1) == -1 )
84 throw IOException("Could not read a single byte from input");
90 IOChannel::write(const void* /*src*/, std::streamsize
/*num*/)
92 throw IOException("This IOChannel implementation doesn't support output");