diff --git a/benchmark/test.bat b/benchmark/test.bat index 9007d32..a8056d8 100644 --- a/benchmark/test.bat +++ b/benchmark/test.bat @@ -2,7 +2,11 @@ b2 -a toolset=msvc-14.0 variant=release link=static address-model=64 bin\loop_time_test 1000 >msvc-loop-time.html msvc-loop-time.html -echo The GCC build does not work, probably because of a bjam/b2 bug +echo The GCC static build does not work on Windows, probably because of a bjam/b2 bug b2 -a toolset=gcc-c++11 variant=release link=static address-model=64 bin\loop_time_test 1000 >gcc-loop-time.html gcc-loop-time.html + +rem Copyright Beman Dawes 2015 +rem Distributed under the Boost Software License, Version 1.0. +rem See www.boost.org/LICENSE_1_0.txt diff --git a/include/boost/endian/arithmetic.hpp b/include/boost/endian/arithmetic.hpp index 48198ec..0cda700 100644 --- a/include/boost/endian/arithmetic.hpp +++ b/include/boost/endian/arithmetic.hpp @@ -44,7 +44,7 @@ #include #include #include -#include +#include #include #include @@ -75,19 +75,6 @@ namespace boost namespace endian { -#ifndef BOOST_ENDIAN_ORDER_ENUM_DEFINED - BOOST_SCOPED_ENUM_START(order) - { - big, little, -# ifdef BOOST_BIG_ENDIAN - native = big -# else - native = little -# endif - }; BOOST_SCOPED_ENUM_END -# define BOOST_ENDIAN_ORDER_ENUM_DEFINED -#endif - template class endian_arithmetic; @@ -224,16 +211,100 @@ namespace endian typedef little_float32_t native_float32_t; typedef little_float64_t native_float64_t; # endif -} // namespace boost -} // namespace endian + +# ifdef BOOST_ENDIAN_DEPRECATED_NAMES + + typedef order endianness; + typedef align alignment; + +# ifndef BOOST_NO_CXX11_TEMPLATE_ALIASES + template + using endian = endian_arithmetic; +# endif + + // unaligned big endian signed integer types + typedef endian_arithmetic< order::big, int_least8_t, 8 > big8_t; + typedef endian_arithmetic< order::big, int_least16_t, 16 > big16_t; + typedef endian_arithmetic< order::big, int_least32_t, 24 > big24_t; + typedef endian_arithmetic< order::big, int_least32_t, 32 > big32_t; + typedef endian_arithmetic< order::big, int_least64_t, 40 > big40_t; + typedef endian_arithmetic< order::big, int_least64_t, 48 > big48_t; + typedef endian_arithmetic< order::big, int_least64_t, 56 > big56_t; + typedef endian_arithmetic< order::big, int_least64_t, 64 > big64_t; + + // unaligned big endian_arithmetic unsigned integer types + typedef endian_arithmetic< order::big, uint_least8_t, 8 > ubig8_t; + typedef endian_arithmetic< order::big, uint_least16_t, 16 > ubig16_t; + typedef endian_arithmetic< order::big, uint_least32_t, 24 > ubig24_t; + typedef endian_arithmetic< order::big, uint_least32_t, 32 > ubig32_t; + typedef endian_arithmetic< order::big, uint_least64_t, 40 > ubig40_t; + typedef endian_arithmetic< order::big, uint_least64_t, 48 > ubig48_t; + typedef endian_arithmetic< order::big, uint_least64_t, 56 > ubig56_t; + typedef endian_arithmetic< order::big, uint_least64_t, 64 > ubig64_t; + + // unaligned little endian_arithmetic signed integer types + typedef endian_arithmetic< order::little, int_least8_t, 8 > little8_t; + typedef endian_arithmetic< order::little, int_least16_t, 16 > little16_t; + typedef endian_arithmetic< order::little, int_least32_t, 24 > little24_t; + typedef endian_arithmetic< order::little, int_least32_t, 32 > little32_t; + typedef endian_arithmetic< order::little, int_least64_t, 40 > little40_t; + typedef endian_arithmetic< order::little, int_least64_t, 48 > little48_t; + typedef endian_arithmetic< order::little, int_least64_t, 56 > little56_t; + typedef endian_arithmetic< order::little, int_least64_t, 64 > little64_t; + + // unaligned little endian_arithmetic unsigned integer types + typedef endian_arithmetic< order::little, uint_least8_t, 8 > ulittle8_t; + typedef endian_arithmetic< order::little, uint_least16_t, 16 > ulittle16_t; + typedef endian_arithmetic< order::little, uint_least32_t, 24 > ulittle24_t; + typedef endian_arithmetic< order::little, uint_least32_t, 32 > ulittle32_t; + typedef endian_arithmetic< order::little, uint_least64_t, 40 > ulittle40_t; + typedef endian_arithmetic< order::little, uint_least64_t, 48 > ulittle48_t; + typedef endian_arithmetic< order::little, uint_least64_t, 56 > ulittle56_t; + typedef endian_arithmetic< order::little, uint_least64_t, 64 > ulittle64_t; + + // unaligned native endian_arithmetic signed integer types + typedef endian_arithmetic< order::native, int_least8_t, 8 > native8_t; + typedef endian_arithmetic< order::native, int_least16_t, 16 > native16_t; + typedef endian_arithmetic< order::native, int_least32_t, 24 > native24_t; + typedef endian_arithmetic< order::native, int_least32_t, 32 > native32_t; + typedef endian_arithmetic< order::native, int_least64_t, 40 > native40_t; + typedef endian_arithmetic< order::native, int_least64_t, 48 > native48_t; + typedef endian_arithmetic< order::native, int_least64_t, 56 > native56_t; + typedef endian_arithmetic< order::native, int_least64_t, 64 > native64_t; + + // unaligned native endian_arithmetic unsigned integer types + typedef endian_arithmetic< order::native, uint_least8_t, 8 > unative8_t; + typedef endian_arithmetic< order::native, uint_least16_t, 16 > unative16_t; + typedef endian_arithmetic< order::native, uint_least32_t, 24 > unative24_t; + typedef endian_arithmetic< order::native, uint_least32_t, 32 > unative32_t; + typedef endian_arithmetic< order::native, uint_least64_t, 40 > unative40_t; + typedef endian_arithmetic< order::native, uint_least64_t, 48 > unative48_t; + typedef endian_arithmetic< order::native, uint_least64_t, 56 > unative56_t; + typedef endian_arithmetic< order::native, uint_least64_t, 64 > unative64_t; + + // aligned native endian_arithmetic typedefs are not provided because + // types are superior for this use case + + typedef endian_arithmetic< order::big, int16_t, 16, align::yes > aligned_big16_t; + typedef endian_arithmetic< order::big, uint16_t, 16, align::yes > aligned_ubig16_t; + typedef endian_arithmetic< order::little, int16_t, 16, align::yes > aligned_little16_t; + typedef endian_arithmetic< order::little, uint16_t, 16, align::yes > aligned_ulittle16_t; + + typedef endian_arithmetic< order::big, int32_t, 32, align::yes > aligned_big32_t; + typedef endian_arithmetic< order::big, uint32_t, 32, align::yes > aligned_ubig32_t; + typedef endian_arithmetic< order::little, int32_t, 32, align::yes > aligned_little32_t; + typedef endian_arithmetic< order::little, uint32_t, 32, align::yes > aligned_ulittle32_t; + + typedef endian_arithmetic< order::big, int64_t, 64, align::yes > aligned_big64_t; + typedef endian_arithmetic< order::big, uint64_t, 64, align::yes > aligned_ubig64_t; + typedef endian_arithmetic< order::little, int64_t, 64, align::yes > aligned_little64_t; + typedef endian_arithmetic< order::little, uint64_t, 64, align::yes > aligned_ulittle64_t; + +# endif //---------------------------------- end synopsis ------------------------------------// -namespace boost -{ -namespace endian -{ - // endian class template specializations ---------------------------------------------// // Specializations that represent unaligned bytes. diff --git a/include/boost/endian/buffers.hpp b/include/boost/endian/buffers.hpp index 9121fba..99dd185 100644 --- a/include/boost/endian/buffers.hpp +++ b/include/boost/endian/buffers.hpp @@ -40,7 +40,7 @@ #include #include #include -#include +#include #include #include @@ -65,19 +65,12 @@ namespace boost namespace endian { -#ifndef BOOST_ENDIAN_ORDER_ENUM_DEFINED - BOOST_SCOPED_ENUM_START(order) - { - big, little, -# ifdef BOOST_BIG_ENDIAN - native = big -# else - native = little -# endif + BOOST_SCOPED_ENUM_START(align) + {no, yes +# ifdef BOOST_ENDIAN_DEPRECATED_NAMES + , unaligned = no, aligned = yes +# endif }; BOOST_SCOPED_ENUM_END -# define BOOST_ENDIAN_ORDER_ENUM_DEFINED -#endif - BOOST_SCOPED_ENUM_START(align) {no, yes}; BOOST_SCOPED_ENUM_END template @@ -239,15 +232,8 @@ namespace endian return is; } -} // namespace boost -} // namespace endian - //---------------------------------- end synopsis ------------------------------------// -namespace boost -{ -namespace endian -{ namespace detail { diff --git a/include/boost/endian/conversion.hpp b/include/boost/endian/conversion.hpp index 7771eed..ca29176 100644 --- a/include/boost/endian/conversion.hpp +++ b/include/boost/endian/conversion.hpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include #include // for memcpy diff --git a/include/boost/endian/endian.hpp b/include/boost/endian/endian.hpp new file mode 100644 index 0000000..6c610c4 --- /dev/null +++ b/include/boost/endian/endian.hpp @@ -0,0 +1,19 @@ +// boost/endian/endian.hpp -----------------------------------------------------------// + +// Copyright Beman Dawes 2015 + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// See library home page at http://www.boost.org/libs/endian + +#ifndef BOOST_ENDIAN_ENDIAN_HPP +#define BOOST_ENDIAN_ENDIAN_HPP + +#ifndef BOOST_ENDIAN_DEPRECATED_NAMES +# error " is deprecated. Define BOOST_ENDIAN_DEPRECATED_NAMES to use." +#endif + +#include + +#endif //BOOST_ENDIAN_ENDIAN_HPP diff --git a/test/deprecated_test.cpp b/test/deprecated_test.cpp new file mode 100644 index 0000000..ddc33eb --- /dev/null +++ b/test/deprecated_test.cpp @@ -0,0 +1,183 @@ +// deprecated_test.cpp ---------------------------------------------------------------// + +// Copyright Beman Dawes 2014, 2015 + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// See library home page at http://www.boost.org/libs/endian + +//--------------------------------------------------------------------------------------// + +#include + +#define BOOST_ENDIAN_DEPRECATED_NAMES +#include +#include +#include +#include +#include + +using namespace boost::endian; +using std::cout; +using std::endl; + +namespace +{ + + // check_size ----------------------------------------------------------------------// + + void check_size() + { + BOOST_TEST_EQ(sizeof(big8_t), 1); + BOOST_TEST_EQ(sizeof(big16_t), 2); + BOOST_TEST_EQ(sizeof(big24_t), 3); + BOOST_TEST_EQ(sizeof(big32_t), 4); + BOOST_TEST_EQ(sizeof(big40_t), 5); + BOOST_TEST_EQ(sizeof(big48_t), 6); + BOOST_TEST_EQ(sizeof(big56_t), 7); + BOOST_TEST_EQ(sizeof(big64_t), 8); + + BOOST_TEST_EQ(sizeof(ubig8_t), 1); + BOOST_TEST_EQ(sizeof(ubig16_t), 2); + BOOST_TEST_EQ(sizeof(ubig24_t), 3); + BOOST_TEST_EQ(sizeof(ubig32_t), 4); + BOOST_TEST_EQ(sizeof(ubig40_t), 5); + BOOST_TEST_EQ(sizeof(ubig48_t), 6); + BOOST_TEST_EQ(sizeof(ubig56_t), 7); + BOOST_TEST_EQ(sizeof(ubig64_t), 8); + + BOOST_TEST_EQ(sizeof(little8_t), 1); + BOOST_TEST_EQ(sizeof(little16_t), 2); + BOOST_TEST_EQ(sizeof(little24_t), 3); + BOOST_TEST_EQ(sizeof(little32_t), 4); + BOOST_TEST_EQ(sizeof(little40_t), 5); + BOOST_TEST_EQ(sizeof(little48_t), 6); + BOOST_TEST_EQ(sizeof(little56_t), 7); + BOOST_TEST_EQ(sizeof(little64_t), 8); + + BOOST_TEST_EQ(sizeof(ulittle8_t), 1); + BOOST_TEST_EQ(sizeof(ulittle16_t), 2); + BOOST_TEST_EQ(sizeof(ulittle24_t), 3); + BOOST_TEST_EQ(sizeof(ulittle32_t), 4); + BOOST_TEST_EQ(sizeof(ulittle40_t), 5); + BOOST_TEST_EQ(sizeof(ulittle48_t), 6); + BOOST_TEST_EQ(sizeof(ulittle56_t), 7); + BOOST_TEST_EQ(sizeof(ulittle64_t), 8); + + BOOST_TEST_EQ(sizeof(native8_t), 1); + BOOST_TEST_EQ(sizeof(native16_t), 2); + BOOST_TEST_EQ(sizeof(native24_t), 3); + BOOST_TEST_EQ(sizeof(native32_t), 4); + BOOST_TEST_EQ(sizeof(native40_t), 5); + BOOST_TEST_EQ(sizeof(native48_t), 6); + BOOST_TEST_EQ(sizeof(native56_t), 7); + BOOST_TEST_EQ(sizeof(native64_t), 8); + + BOOST_TEST_EQ(sizeof(unative8_t), 1); + BOOST_TEST_EQ(sizeof(unative16_t), 2); + BOOST_TEST_EQ(sizeof(unative24_t), 3); + BOOST_TEST_EQ(sizeof(unative32_t), 4); + BOOST_TEST_EQ(sizeof(unative40_t), 5); + BOOST_TEST_EQ(sizeof(unative48_t), 6); + BOOST_TEST_EQ(sizeof(unative56_t), 7); + BOOST_TEST_EQ(sizeof(unative64_t), 8); + + BOOST_TEST_EQ(sizeof(aligned_big16_t), 2); + BOOST_TEST_EQ(sizeof(aligned_big32_t), 4); + BOOST_TEST_EQ(sizeof(aligned_big64_t), 8); + + BOOST_TEST_EQ(sizeof(aligned_ubig16_t), 2); + BOOST_TEST_EQ(sizeof(aligned_ubig32_t), 4); + BOOST_TEST_EQ(sizeof(aligned_ubig64_t), 8); + + BOOST_TEST_EQ(sizeof(aligned_little16_t), 2); + BOOST_TEST_EQ(sizeof(aligned_little32_t), 4); + BOOST_TEST_EQ(sizeof(aligned_little64_t), 8); + + BOOST_TEST_EQ(sizeof(aligned_ulittle16_t), 2); + BOOST_TEST_EQ(sizeof(aligned_ulittle32_t), 4); + BOOST_TEST_EQ(sizeof(aligned_ulittle64_t), 8); + +# ifndef BOOST_NO_CXX11_TEMPLATE_ALIASES + BOOST_TEST_EQ(sizeof(endian), 2); + BOOST_TEST_EQ(sizeof(endian), 2); +# endif + } // check_size + + // test_inserter_and_extractor -----------------------------------------------------// + + void test_inserter_and_extractor() + { + std::cout << "test inserter and extractor..." << std::endl; + + ubig64_t bu64(0x010203040506070ULL); + ulittle64_t lu64(0x010203040506070ULL); + + uint64_t x; + + std::stringstream ss; + + ss << bu64; + ss >> x; + BOOST_TEST_EQ(x, 0x010203040506070ULL); + + ss.clear(); + ss << lu64; + ss >> x; + BOOST_TEST_EQ(x, 0x010203040506070ULL); + + ss.clear(); + ss << 0x010203040506070ULL; + ubig64_t bu64z(0); + ss >> bu64z; + BOOST_TEST_EQ(bu64z, bu64); + + ss.clear(); + ss << 0x010203040506070ULL; + ulittle64_t lu64z(0); + ss >> lu64z; + BOOST_TEST_EQ(lu64z, lu64); + + std::cout << "test inserter and extractor complete" << std::endl; + + } + +} // unnamed namespace + + //--------------------------------------------------------------------------------------// + +int cpp_main(int, char *[]) +{ + cout << "byte swap intrinsics: " BOOST_ENDIAN_INTRINSIC_MSG << endl; + + cout << " construct big endian aligned" << endl; + big32_t x(1122334455); + + cout << " assign to buffer from built-in integer" << endl; + x = 1234567890; + + cout << " operator==(buffer.value(), built-in)" << endl; + bool b1(x == 1234567890); + BOOST_TEST(b1); + + cout << " construct little endian unaligned" << endl; + little32_t x2(1122334455); + + cout << " assign to buffer from built-in integer" << endl; + x2 = 1234567890; + + cout << " operator==(buffer.value(), built-in)" << endl; + bool b2(x2 == 1234567890); + BOOST_TEST(b2); + + check_size(); + test_inserter_and_extractor(); + + cout << " done" << endl; + + return ::boost::report_errors(); +} + +#include diff --git a/test/loop_time_test.cpp b/test/loop_time_test.cpp index 2ea13b1..e36ffbd 100644 --- a/test/loop_time_test.cpp +++ b/test/loop_time_test.cpp @@ -16,12 +16,20 @@ #include #include #include -#include #include #include #include #include +#ifdef _MSC_VER +# pragma warning (push) +# pragma warning (disable : 4459) +#endif +#include +#ifdef _MSC_VER +# pragma warning (pop) +#endif + using namespace boost; using namespace boost::endian; @@ -245,6 +253,7 @@ int cpp_main(int argc, char* argv[]) cout << "\n\nEndian Loop Time Test\n\n\n" + << "\n" << "
\n" << "\n" diff --git a/test/msvc/deprecated_test/deprecated_test.vcxproj b/test/msvc/deprecated_test/deprecated_test.vcxproj new file mode 100644 index 0000000..7938d75 --- /dev/null +++ b/test/msvc/deprecated_test/deprecated_test.vcxproj @@ -0,0 +1,88 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {DA4BC67F-9284-4D2C-81D5-407312C31BD7} + Win32Proj + deprecated_test + + + + Application + true + v140 + Unicode + + + Application + false + v140 + true + Unicode + + + + + + + + + + + + + + + true + + + false + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/test/msvc/endian.sln b/test/msvc/endian.sln index 4fe29e0..bbb605b 100644 --- a/test/msvc/endian.sln +++ b/test/msvc/endian.sln @@ -31,6 +31,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "associated-files", "associa EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "experiment", "experiment\experiment.vcxproj", "{CE9D8719-6E86-41D0-97CA-5BE5272594E9}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "deprecated_test", "deprecated_test\deprecated_test.vcxproj", "{DA4BC67F-9284-4D2C-81D5-407312C31BD7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -145,6 +147,12 @@ Global {CE9D8719-6E86-41D0-97CA-5BE5272594E9}.Release|Win32.ActiveCfg = Release|Win32 {CE9D8719-6E86-41D0-97CA-5BE5272594E9}.Release|Win32.Build.0 = Release|Win32 {CE9D8719-6E86-41D0-97CA-5BE5272594E9}.Release|x64.ActiveCfg = Release|Win32 + {DA4BC67F-9284-4D2C-81D5-407312C31BD7}.Debug|Win32.ActiveCfg = Debug|Win32 + {DA4BC67F-9284-4D2C-81D5-407312C31BD7}.Debug|Win32.Build.0 = Debug|Win32 + {DA4BC67F-9284-4D2C-81D5-407312C31BD7}.Debug|x64.ActiveCfg = Debug|Win32 + {DA4BC67F-9284-4D2C-81D5-407312C31BD7}.Release|Win32.ActiveCfg = Release|Win32 + {DA4BC67F-9284-4D2C-81D5-407312C31BD7}.Release|Win32.Build.0 = Release|Win32 + {DA4BC67F-9284-4D2C-81D5-407312C31BD7}.Release|x64.ActiveCfg = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE