2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
4 * This file is part of CasparCG (www.casparcg.com).
6 * CasparCG 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 * CasparCG 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 CasparCG. If not, see <http://www.gnu.org/licenses/>.
19 * Author: Niklas P Andersson, niklas.p.andersson@svt.se
24 #include <common/except.h>
26 #include <boost/filesystem/fstream.hpp>
32 namespace caspar { namespace psd {
34 struct unexpected_eof_exception : virtual io_error {};
36 class bigendian_file_input_stream
39 explicit bigendian_file_input_stream();
40 virtual ~bigendian_file_input_stream();
42 void open(const std::wstring& filename);
44 void read(char*, std::streamsize);
45 std::uint8_t read_byte();
46 std::uint16_t read_short();
47 std::uint32_t read_long();
48 std::wstring read_pascal_string(int padding = 1);
49 std::wstring read_unicode_string();
50 std::wstring read_id_string();
53 void discard_bytes(std::streamoff);
54 void discard_to_next_word();
55 void discard_to_next_dword();
57 std::streamoff current_position();
58 void set_position(std::streamoff);
62 boost::filesystem::ifstream ifs_;
63 std::wstring filename_;
66 class StreamPositionBackup
69 StreamPositionBackup(bigendian_file_input_stream& stream, std::streamoff newPos) : stream_(stream)
71 oldPosition_ = stream.current_position();
72 stream_.set_position(newPos);
75 ~StreamPositionBackup()
77 stream_.set_position(oldPosition_);
80 std::streamoff oldPosition_;
81 bigendian_file_input_stream& stream_;