From 22231518b9c2c0b7f73c72a6ca834df659c63c7f Mon Sep 17 00:00:00 2001 From: Dennis Brentjes Date: Wed, 22 Jun 2016 00:15:08 +0200 Subject: Reduces the amount of boilerplate neccesary to parse the binary format. --- mz/mz_header.cpp | 38 ++++++++------------------------------ 1 file changed, 8 insertions(+), 30 deletions(-) (limited to 'mz/mz_header.cpp') diff --git a/mz/mz_header.cpp b/mz/mz_header.cpp index 02241cf..c33270f 100644 --- a/mz/mz_header.cpp +++ b/mz/mz_header.cpp @@ -1,18 +1,16 @@ #include "mz_header.hpp" -#include "index_list.hpp" - -#include "binparse.hpp" +#include "parse.hpp" +#include "output.hpp" #include -#include #include #include BOOST_FUSION_ADAPT_STRUCT( - mz::MZHeader, + mz::Header, (binparse::Magic16, magic) (binparse::Value16, bytes_in_last_block) (binparse::Value16, blocks_in_file) @@ -35,35 +33,15 @@ 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; +Header parse_header(std::istream& is) { + using binparse::parse; - return parse_header_impl(is, indices{}); + return parse
(is); } -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) +std::ostream& operator<<(std::ostream& os, Header const& header) { - typedef build_indices::value>::type indices; - - return output_impl(os, header, indices{}); + return binparse::operator<<(os, header); } } -- cgit v1.2.3-70-g09d2