diff options
Diffstat (limited to 'binparse/output.hpp')
| -rw-r--r-- | binparse/output.hpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/binparse/output.hpp b/binparse/output.hpp index 705a380..c5db2da 100644 --- a/binparse/output.hpp +++ b/binparse/output.hpp @@ -13,6 +13,7 @@ #include <vector> #include <map> #include <streambuf> +#include <typeinfo> namespace binparse { @@ -31,6 +32,8 @@ std::ostream& operator<<(std::ostream& os, Offset16 o); std::ostream& operator<<(std::ostream& os, Value32 v); std::ostream& operator<<(std::ostream& os, Offset32 o); +std::ostream& operator<<(std::ostream& os, PString8 s); + std::ostream& operator<<(std::ostream& os, std::array<uint8_t, 8> a); std::ostream& operator<<(std::ostream& os, std::array<uint8_t, 22> a); @@ -47,7 +50,7 @@ std::ostream& operator<<(std::ostream& os, std::map<Key, Value> const& map) { for(auto&& entry : map) { os << entry.first << ": " << entry.second << std::endl; } - } catch(std::exception&) { + } catch(std::bad_cast&) { os << std::endl; for(auto&& entry : map) { os << entry.first << ": " << entry.second << std::endl; @@ -57,6 +60,25 @@ std::ostream& operator<<(std::ostream& os, std::map<Key, Value> const& map) { return os; } +template <typename ValueType> +std::ostream& operator<<(std::ostream& os, std::vector<ValueType> const& vec) { + try { + indent scoped(os); + os << std::endl; + for(auto&& entry : vec) { + os << entry << std::endl; + } + } catch(std::bad_cast&) { + os << std::endl; + for(auto&& entry : vec) { + os << entry << std::endl; + } + } + return os; +} + + + template<typename T> std::ostream& output_impl(std::ostream& os, T const&, indices<>) { return os; @@ -78,7 +100,7 @@ std::ostream& operator<<(std::ostream& os, T const& t) { indent scoped(os); os << std::endl; output_impl<T>(os, t, indices{}); - } catch(std::exception&) { + } catch(std::bad_cast&) { os << std::endl; output_impl<T>(os, t, indices{}); } |
