From 1a496f277e290defda2377d86e6ce7edc5db2ab3 Mon Sep 17 00:00:00 2001 From: Beman Date: Tue, 14 May 2013 09:59:18 -0400 Subject: [PATCH] Signs of life --- include/boost/endian/converters.hpp | 2 +- include/boost/endian/std_pair.hpp | 1 + test/pair_test.cpp | 82 +++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 1 deletion(-) diff --git a/include/boost/endian/converters.hpp b/include/boost/endian/converters.hpp index 97f7ade..b91a3a2 100644 --- a/include/boost/endian/converters.hpp +++ b/include/boost/endian/converters.hpp @@ -80,7 +80,7 @@ namespace endian // runtime byte-order conversion template - ReversibleValue convert_value(ReversibleValue from, BOOST_SCOPED_ENUM(order) from_order, + ReversibleValue convert_value(ReversibleValue from, BOOST_SCOPED_ENUM(order) from_order, BOOST_SCOPED_ENUM(order) to_order) BOOST_NOEXCEPT; //--------------------------------------------------------------------------------------// diff --git a/include/boost/endian/std_pair.hpp b/include/boost/endian/std_pair.hpp index 6cf57e1..f1ac7ca 100644 --- a/include/boost/endian/std_pair.hpp +++ b/include/boost/endian/std_pair.hpp @@ -31,6 +31,7 @@ namespace endian reverse(x.first); reverse(x.second); } + } } diff --git a/test/pair_test.cpp b/test/pair_test.cpp index e69de29..66f15f0 100644 --- a/test/pair_test.cpp +++ b/test/pair_test.cpp @@ -0,0 +1,82 @@ +// pair_test.cpp ---------------------------------------------------------------------// + +// Copyright Beman Dawes 2013 + +// Distributed under the Boost Software License, Version 1.0. +// http://www.boost.org/LICENSE_1_0.txt + +//--------------------------------------------------------------------------------------// + +#include + +#include +#include +#include +#include +#include +#include + +using namespace boost::endian; +using std::cout; +using std::endl; +using boost::int16_t; +using boost::uint16_t; +using boost::int32_t; +using boost::uint32_t; +using boost::int64_t; +using boost::uint64_t; + +namespace +{ + + typedef std::pair MyPair; + + template + OS& operator<<(OS& os, MyPair my) + { + const char* first = reinterpret_cast(&my.first); + const char* second = reinterpret_cast(&my.second); + + os << std::hex + << int(*first) << ' ' << int(*(first+1)) << ", " + << int(*second) << ' ' << int(*(second+1)) << ' ' + << int(*(second+2)) << ' ' << int(*(second+3)) + << std::dec << std::endl; + return os; + } + +} // unnamed namespace + +//--------------------------------------------------------------------------------------// + +int cpp_main(int, char * []) +{ + cout << "pair_test" << endl; + + MyPair x(0x0102, 0x01020304); + MyPair y(big_endian_value(x)); + MyPair z(little_endian_value(x)); + + cout << "native: " << x; + cout << " big: " << y; + cout << "little: " << z << endl; + + big_endian(x); + cout << " big: " << x; + reverse(x); + little_endian(x); + cout << "little: " << x << endl; + + convert(x, order::little, order::native); + y = MyPair(0, 0); + y = convert_value(x, order::native, order::big); + z = x; + little_endian(z); + cout << "native: " << x; + cout << " big: " << y; + cout << "little: " << z; + + return ::boost::report_errors(); +} + +#include