summaryrefslogtreecommitdiff
path: root/binparse/output.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'binparse/output.hpp')
-rw-r--r--binparse/output.hpp57
1 files changed, 57 insertions, 0 deletions
diff --git a/binparse/output.hpp b/binparse/output.hpp
new file mode 100644
index 0000000..b16dd89
--- /dev/null
+++ b/binparse/output.hpp
@@ -0,0 +1,57 @@
+#pragma once
+
+#include "types.hpp"
+
+#include "index_list.hpp"
+
+#include <boost/fusion/support/is_sequence.hpp>
+#include <boost/fusion/sequence/intrinsic/at_c.hpp>
+#include <boost/fusion/adapted/struct/detail/extension.hpp>
+
+#include <array>
+#include <vector>
+
+namespace binparse {
+
+std::string to_string(Magic16 magic);
+
+//overload inside this namespace to output unsigned char as value not as characters.
+std::ostream& operator<<(std::ostream& os, uint8_t);
+
+std::ostream& operator<<(std::ostream& os, Value8 v);
+std::ostream& operator<<(std::ostream& os, Offset8 o);
+
+std::ostream& operator<<(std::ostream& os, Magic16 m);
+std::ostream& operator<<(std::ostream& os, Value16 v);
+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, std::array<uint8_t, 8> a);
+std::ostream& operator<<(std::ostream& os, std::array<uint8_t, 22> a);
+
+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 T>
+std::ostream& output_impl(std::ostream& os, T const&, indices<>) {
+ return os;
+}
+
+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{});
+}
+
+} \ No newline at end of file