diff options
Diffstat (limited to 'binparse/output.hpp')
| -rw-r--r-- | binparse/output.hpp | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/binparse/output.hpp b/binparse/output.hpp index b16dd89..705a380 100644 --- a/binparse/output.hpp +++ b/binparse/output.hpp @@ -1,6 +1,7 @@ #pragma once #include "types.hpp" +#include "otreestream.hpp" #include "index_list.hpp" @@ -10,6 +11,8 @@ #include <array> #include <vector> +#include <map> +#include <streambuf> namespace binparse { @@ -36,6 +39,24 @@ std::ostream& operator<<(std::ostream& os, std::vector<uint8_t> vec); template <typename T, typename std::enable_if<boost::fusion::traits::is_sequence<T>::value>::type* = nullptr> std::ostream& operator<<(std::ostream&, T const&); +template <typename Key, typename Value> +std::ostream& operator<<(std::ostream& os, std::map<Key, Value> const& map) { + try { + indent scoped(os); + os << std::endl; + for(auto&& entry : map) { + os << entry.first << ": " << entry.second << std::endl; + } + } catch(std::exception&) { + os << std::endl; + for(auto&& entry : map) { + os << entry.first << ": " << entry.second << std::endl; + } + } + + return os; +} + template<typename T> std::ostream& output_impl(std::ostream& os, T const&, indices<>) { return os; @@ -43,15 +64,25 @@ std::ostream& output_impl(std::ostream& os, T const&, indices<>) { template <typename T, int I, int... Indices> std::ostream& output_impl(std::ostream& os, T const& t, indices<I, Indices...>) { + os << boost::fusion::extension::struct_member_name<T, I>::call() << ": " << boost::fusion::at_c<I>(t) << std::endl; return output_impl(os, t, indices<Indices...>{}); + } template <typename T, typename std::enable_if<boost::fusion::traits::is_sequence<T>::value>::type*> std::ostream& operator<<(std::ostream& os, T const& t) { typedef typename build_indices<boost::fusion::result_of::size<T>::value>::type indices; - return output_impl<T>(os, t, indices{}); + try { + indent scoped(os); + os << std::endl; + output_impl<T>(os, t, indices{}); + } catch(std::exception&) { + os << std::endl; + output_impl<T>(os, t, indices{}); + } + return os; } }
\ No newline at end of file |
