1
// IOChannel.cpp - a virtual IO channel, for Gnash
3
// Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5
// This program is free software; you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation; either version 3 of the License, or
8
// (at your option) any later version.
10
// This program is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU General Public License for more details.
15
// You should have received a copy of the GNU General Public License
16
// along with this program; if not, write to the Free Software
17
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#include "IOChannel.h"
23
#include <boost/static_assert.hpp>
29
IOChannel::read_le32()
31
// read_byte() is boost::uint8_t, so no masks with 0xff are required.
32
boost::uint32_t result = static_cast<boost::uint32_t>(read_byte());
33
result |= static_cast<boost::uint32_t>(read_byte()) << 8;
34
result |= static_cast<boost::uint32_t>(read_byte()) << 16;
35
result |= static_cast<boost::uint32_t>(read_byte()) << 24;
40
IOChannel::read_le_double64()
42
return static_cast<long double> (
43
static_cast<boost::int64_t> (read_le32()) |
44
static_cast<boost::int64_t> (read_le32()) << 32
49
IOChannel::read_le16()
51
boost::uint16_t result = static_cast<boost::uint16_t>(read_byte());
52
result |= static_cast<boost::uint16_t>(read_byte()) << 8;
57
IOChannel::write_le32(boost::uint32_t u)
59
write_byte(static_cast<boost::int8_t>(u));
60
write_byte(static_cast<boost::int8_t>(u>>8));
61
write_byte(static_cast<boost::int8_t>(u>>16));
62
write_byte(static_cast<boost::int8_t>(u>>24));
66
IOChannel::write_le16(boost::uint16_t u)
68
write_byte(static_cast<boost::int8_t>(u));
69
write_byte(static_cast<boost::int8_t>(u>>8));
73
IOChannel::write_string(const char* src)
84
IOChannel::read_string(char* dst, int max_length)
90
if (dst[i]=='\0') return i;
94
dst[max_length - 1] = '\0'; // force termination.
100
IOChannel::write_float32(float value)
107
BOOST_STATIC_ASSERT(sizeof(alias) == sizeof(boost::uint32_t));
114
IOChannel::read_float32()
121
BOOST_STATIC_ASSERT(sizeof(u) == sizeof(u.i));
128
IOChannel::read_byte()
131
if ( read(&u, 1) == -1 )
133
throw IOException("Could not read a single byte from input");
139
IOChannel::write_byte(boost::uint8_t u)
141
write(&u, 1); // will trhow on error it seems
145
IOChannel::write(const void* /*src*/, int /*num*/)
147
throw IOException("This IOChannel implementation doesn't support output");