#include "mz_header.hpp" #include "index_list.hpp" #include "binparse.hpp" #include #include #include #include BOOST_FUSION_ADAPT_STRUCT( mz::MZHeader, (binparse::Magic16, magic) (binparse::Value16, bytes_in_last_block) (binparse::Value16, blocks_in_file) (binparse::Value16, num_relocs) (binparse::Value16, header_paragraphs) (binparse::Value16, min_extra_paragraphs) (binparse::Value16, max_extra_paragraphs) (binparse::Offset16, ss) (binparse::Offset16, sp) (binparse::Value16, checksum) (binparse::Offset16, ip) (binparse::Offset16, cs) (binparse::Offset16, reloc_table_offset) (binparse::Value16, overlay_number) ) namespace mz { NotAMZFileException::NotAMZFileException() : std::runtime_error("This stream does not contain a valid MZ executable") {} template MZHeader parse_header_impl(std::istream& is, indices) { return {parse::type>::type>(is, boost::fusion::extension::struct_member_name::call())...}; } MZHeader parse_header(std::istream& is) { typedef build_indices::value>::type indices; return parse_header_impl(is, indices{}); } std::ostream& output_impl(std::ostream& os, MZHeader const&, indices<>) { return os; } template std::ostream& output_impl(std::ostream& os, const MZHeader& header, indices) { os << boost::fusion::extension::struct_member_name::call() << ": " << boost::fusion::at_c(header) << std::endl; return output_impl(os, header, indices{}); } std::ostream& operator<<(std::ostream& os, MZHeader const& header) { typedef build_indices::value>::type indices; return output_impl(os, header, indices{}); } }