mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2024-11-12 21:09:01 +00:00
add std:: for <cstdint> types
This commit is contained in:
parent
5baa0580d8
commit
11a96da4bb
9 changed files with 442 additions and 438 deletions
|
@ -1 +1 @@
|
||||||
subdirs( test )
|
subdirs( test )
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
add_executable( libs_net_test_endian endian.cpp )
|
add_executable( libs_net_test_endian endian.cpp )
|
||||||
set_target_properties( libs_net_test_endian PROPERTIES OUTPUT_NAME "endian" )
|
set_target_properties( libs_net_test_endian PROPERTIES OUTPUT_NAME "endian" )
|
||||||
add_test( libs_net_test_endian endian )
|
add_test( libs_net_test_endian endian )
|
||||||
|
|
|
@ -1,49 +1,50 @@
|
||||||
/*=============================================================================
|
/*=============================================================================
|
||||||
Copyright (c) 2011-2014 Bolero MURAKAMI
|
Copyright (c) 2011-2014 Bolero MURAKAMI
|
||||||
https://github.com/bolero-MURAKAMI/Sprout
|
https://github.com/bolero-MURAKAMI/Sprout
|
||||||
|
|
||||||
Copyright (c) 2014 Chris KAY
|
Copyright (c) 2014 Chris KAY
|
||||||
https://github.com/cjkay-cpp-utils/Sprout
|
https://github.com/cjkay-cpp-utils/Sprout
|
||||||
|
|
||||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
=============================================================================*/
|
=============================================================================*/
|
||||||
#ifndef SPROUT_LIBS_NET_TEST_ENDIAN_CPP
|
#ifndef SPROUT_LIBS_NET_TEST_ENDIAN_CPP
|
||||||
#define SPROUT_LIBS_NET_TEST_ENDIAN_CPP
|
#define SPROUT_LIBS_NET_TEST_ENDIAN_CPP
|
||||||
|
|
||||||
#include <sprout/net/endian.hpp>
|
#include <cstdint>
|
||||||
#include <testspr/tools.hpp>
|
#include <sprout/net/endian.hpp>
|
||||||
|
#include <testspr/tools.hpp>
|
||||||
namespace testspr {
|
|
||||||
static void endian_test() {
|
namespace testspr {
|
||||||
using namespace sprout;
|
static void endian_test() {
|
||||||
|
using namespace sprout;
|
||||||
{ // 16
|
|
||||||
TESTSPR_ASSERT(sprout::net::detail::reverse(uint16_t(0x0A1B)) == uint16_t(0x1B0A));
|
{ // 16
|
||||||
TESTSPR_ASSERT(sprout::net::detail::reverse(uint16_t(0x1B0A)) == uint16_t(0x0A1B));
|
TESTSPR_ASSERT(sprout::net::detail::reverse(std::uint16_t(0x0A1B)) == std::uint16_t(0x1B0A));
|
||||||
TESTSPR_ASSERT(sprout::net::detail::reverse_words(uint16_t(0x0A1B)) == uint16_t(0x1B0A));
|
TESTSPR_ASSERT(sprout::net::detail::reverse(std::uint16_t(0x1B0A)) == std::uint16_t(0x0A1B));
|
||||||
TESTSPR_ASSERT(sprout::net::detail::reverse_words(uint16_t(0x1B0A)) == uint16_t(0x0A1B));
|
TESTSPR_ASSERT(sprout::net::detail::reverse_words(std::uint16_t(0x0A1B)) == std::uint16_t(0x1B0A));
|
||||||
}
|
TESTSPR_ASSERT(sprout::net::detail::reverse_words(std::uint16_t(0x1B0A)) == std::uint16_t(0x0A1B));
|
||||||
|
}
|
||||||
{ // 32
|
|
||||||
TESTSPR_ASSERT(sprout::net::detail::reverse(uint32_t(0x0A1B2C3D)) == uint32_t(0x3D2C1B0A));
|
{ // 32
|
||||||
TESTSPR_ASSERT(sprout::net::detail::reverse(uint32_t(0x3D2C1B0A)) == uint32_t(0x0A1B2C3D));
|
TESTSPR_ASSERT(sprout::net::detail::reverse(std::uint32_t(0x0A1B2C3D)) == std::uint32_t(0x3D2C1B0A));
|
||||||
TESTSPR_ASSERT(sprout::net::detail::reverse_words(uint32_t(0x0A1B2C3D)) == uint32_t(0x1B0A3D2C));
|
TESTSPR_ASSERT(sprout::net::detail::reverse(std::uint32_t(0x3D2C1B0A)) == std::uint32_t(0x0A1B2C3D));
|
||||||
TESTSPR_ASSERT(sprout::net::detail::reverse_words(uint32_t(0x1B0A3D2C)) == uint32_t(0x0A1B2C3D));
|
TESTSPR_ASSERT(sprout::net::detail::reverse_words(std::uint32_t(0x0A1B2C3D)) == std::uint32_t(0x1B0A3D2C));
|
||||||
}
|
TESTSPR_ASSERT(sprout::net::detail::reverse_words(std::uint32_t(0x1B0A3D2C)) == std::uint32_t(0x0A1B2C3D));
|
||||||
|
}
|
||||||
{ // 64
|
|
||||||
TESTSPR_ASSERT(sprout::net::detail::reverse(uint64_t(0x0A1B2C3D4E5F6A7B)) == uint64_t(0x7B6A5F4E3D2C1B0A));
|
{ // 64
|
||||||
TESTSPR_ASSERT(sprout::net::detail::reverse(uint64_t(0x7B6A5F4E3D2C1B0A)) == uint64_t(0x0A1B2C3D4E5F6A7B));
|
TESTSPR_ASSERT(sprout::net::detail::reverse(std::uint64_t(0x0A1B2C3D4E5F6A7B)) == std::uint64_t(0x7B6A5F4E3D2C1B0A));
|
||||||
TESTSPR_ASSERT(sprout::net::detail::reverse_words(uint64_t(0x0A1B2C3D4E5F6A7B)) == uint64_t(0x1B0A3D2C5F4E7B6A));
|
TESTSPR_ASSERT(sprout::net::detail::reverse(std::uint64_t(0x7B6A5F4E3D2C1B0A)) == std::uint64_t(0x0A1B2C3D4E5F6A7B));
|
||||||
TESTSPR_ASSERT(sprout::net::detail::reverse_words(uint64_t(0x1B0A3D2C5F4E7B6A)) == uint64_t(0x0A1B2C3D4E5F6A7B));
|
TESTSPR_ASSERT(sprout::net::detail::reverse_words(std::uint64_t(0x0A1B2C3D4E5F6A7B)) == std::uint64_t(0x1B0A3D2C5F4E7B6A));
|
||||||
}
|
TESTSPR_ASSERT(sprout::net::detail::reverse_words(std::uint64_t(0x1B0A3D2C5F4E7B6A)) == std::uint64_t(0x0A1B2C3D4E5F6A7B));
|
||||||
}
|
}
|
||||||
} // namespace testspr
|
}
|
||||||
|
} // namespace testspr
|
||||||
#ifndef TESTSPR_CPP_INCLUDE
|
|
||||||
# define TESTSPR_TEST_FUNCTION testspr::endian_test
|
#ifndef TESTSPR_CPP_INCLUDE
|
||||||
# include <testspr/include_main.hpp>
|
# define TESTSPR_TEST_FUNCTION testspr::endian_test
|
||||||
#endif
|
# include <testspr/include_main.hpp>
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // #ifndef SPROUT_LIBS_NET_TEST_ENDIAN_CPP
|
#endif // #ifndef SPROUT_LIBS_NET_TEST_ENDIAN_CPP
|
|
@ -1,17 +1,17 @@
|
||||||
/*=============================================================================
|
/*=============================================================================
|
||||||
Copyright (c) 2011-2014 Bolero MURAKAMI
|
Copyright (c) 2011-2014 Bolero MURAKAMI
|
||||||
https://github.com/bolero-MURAKAMI/Sprout
|
https://github.com/bolero-MURAKAMI/Sprout
|
||||||
|
|
||||||
Copyright (c) 2014 Chris KAY
|
Copyright (c) 2014 Chris KAY
|
||||||
https://github.com/cjkay-cpp-utils/Sprout
|
https://github.com/cjkay-cpp-utils/Sprout
|
||||||
|
|
||||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
=============================================================================*/
|
=============================================================================*/
|
||||||
#ifndef SPROUT_NET_HPP
|
#ifndef SPROUT_NET_HPP
|
||||||
#define SPROUT_NET_HPP
|
#define SPROUT_NET_HPP
|
||||||
|
|
||||||
#include <sprout/config.hpp>
|
#include <sprout/config.hpp>
|
||||||
#include <sprout/net/endian.hpp>
|
#include <sprout/net/endian.hpp>
|
||||||
|
|
||||||
#endif // #ifndef SPROUT_NET_HPP
|
#endif // #ifndef SPROUT_NET_HPP
|
||||||
|
|
|
@ -1,175 +1,175 @@
|
||||||
/*=============================================================================
|
/*=============================================================================
|
||||||
Copyright (c) 2011-2014 Bolero MURAKAMI
|
Copyright (c) 2011-2014 Bolero MURAKAMI
|
||||||
https://github.com/bolero-MURAKAMI/Sprout
|
https://github.com/bolero-MURAKAMI/Sprout
|
||||||
|
|
||||||
Copyright (c) 2014 Chris KAY
|
Copyright (c) 2014 Chris KAY
|
||||||
https://github.com/cjkay-cpp-utils/Sprout
|
https://github.com/cjkay-cpp-utils/Sprout
|
||||||
|
|
||||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
=============================================================================*/
|
=============================================================================*/
|
||||||
#ifndef SPROUT_NET_NET_HPP
|
#ifndef SPROUT_NET_ENDIAN_HPP
|
||||||
#define SPROUT_NET_NET_HPP
|
#define SPROUT_NET_ENDIAN_HPP
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <sprout/config.hpp>
|
#include <sprout/config.hpp>
|
||||||
#include <boost/detail/endian.hpp>
|
#include <boost/detail/endian.hpp>
|
||||||
|
|
||||||
namespace sprout {
|
namespace sprout {
|
||||||
namespace net {
|
namespace net {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
/*
|
/*
|
||||||
* lshift_by
|
* lshift_by
|
||||||
* Left shift 'val' by 'n' bytes
|
* Left shift 'val' by 'n' bytes
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
SPROUT_CONSTEXPR T lshift_by(T val, uint_fast8_t n) {
|
SPROUT_CONSTEXPR T lshift_by(T val, std::uint_fast8_t n) {
|
||||||
return val << (n * 8);
|
return val << (n * 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* rshift_by
|
* rshift_by
|
||||||
* Right shift 'val' by 'n' bytes
|
* Right shift 'val' by 'n' bytes
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
SPROUT_CONSTEXPR T rshift_by(T val, uint_fast8_t n) {
|
SPROUT_CONSTEXPR T rshift_by(T val, std::uint_fast8_t n) {
|
||||||
return val >> (n * 8);
|
return val >> (n * 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* mask_t
|
* mask_t
|
||||||
* Mask 'n'th byte
|
* Mask 'n'th byte
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
SPROUT_CONSTEXPR T mask_at(uint_fast8_t n) {
|
SPROUT_CONSTEXPR T mask_at(std::uint_fast8_t n) {
|
||||||
return lshift_by(T(0xFF), n);
|
return lshift_by(T(0xFF), n);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* byte_at
|
* byte_at
|
||||||
* Get 'n'th byte from 'val'
|
* Get 'n'th byte from 'val'
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
SPROUT_CONSTEXPR T byte_at(T val, uint_fast8_t n) {
|
SPROUT_CONSTEXPR T byte_at(T val, std::uint_fast8_t n) {
|
||||||
return rshift_by((val & mask_at<T>(n)), n);
|
return rshift_by((val & mask_at<T>(n)), n);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* replace_at
|
* replace_at
|
||||||
* Replace, in 'val', 'n'th byte with 'byte_val'
|
* Replace, in 'val', 'n'th byte with 'byte_val'
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
SPROUT_CONSTEXPR T replace_at(T val, uint8_t byte_val, uint_fast8_t n) {
|
SPROUT_CONSTEXPR T replace_at(T val, std::uint8_t byte_val, std::uint_fast8_t n) {
|
||||||
return (val & ~mask_at<T>(n)) | lshift_by(T(byte_val), n);
|
return (val & ~mask_at<T>(n)) | lshift_by(T(byte_val), n);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* copy
|
* copy
|
||||||
* Copy, in 'val', byte at index 'from' to byte at index 'to'
|
* Copy, in 'val', byte at index 'from' to byte at index 'to'
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
SPROUT_CONSTEXPR T copy(T val, uint_fast8_t from, uint_fast8_t to) {
|
SPROUT_CONSTEXPR T copy(T val, std::uint_fast8_t from, std::uint_fast8_t to) {
|
||||||
return replace_at(val, byte_at(val, from), to);
|
return replace_at(val, byte_at(val, from), to);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* swap
|
* swap
|
||||||
* Swap, in 'val', byte at index 'n1' with byte at index 'n2'
|
* Swap, in 'val', byte at index 'n1' with byte at index 'n2'
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
SPROUT_CONSTEXPR T swap(T val, uint_fast8_t n1, uint_fast8_t n2) {
|
SPROUT_CONSTEXPR T swap(T val, std::uint_fast8_t n1, std::uint_fast8_t n2) {
|
||||||
return replace_at(copy(val, n1, n2), byte_at(val, n2), n1);
|
return replace_at(copy(val, n1, n2), byte_at(val, n2), n1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* reverse_impl
|
* reverse_impl
|
||||||
* Swap, in 'val', byte at index 'n1' with byte at index 'n2' in 'val', increment n1, decrement n2 until n1 > n2
|
* Swap, in 'val', byte at index 'n1' with byte at index 'n2' in 'val', increment n1, decrement n2 until n1 > n2
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
SPROUT_CONSTEXPR T reverse_impl(T val, uint_fast8_t n1, uint_fast8_t n2) {
|
SPROUT_CONSTEXPR T reverse_impl(T val, std::uint_fast8_t n1, std::uint_fast8_t n2) {
|
||||||
return n1 > n2 ? val : reverse_impl(swap(val, n1, n2), n1 + 1, n2 - 1);
|
return n1 > n2 ? val : reverse_impl(swap(val, n1, n2), n1 + 1, n2 - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* reverse
|
* reverse
|
||||||
* Reverse 'val'
|
* Reverse 'val'
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
SPROUT_CONSTEXPR T reverse(T val) {
|
SPROUT_CONSTEXPR T reverse(T val) {
|
||||||
return reverse_impl(val, 0, sizeof(T) - 1);
|
return reverse_impl(val, 0, sizeof(T) - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* reverse_words_impl
|
* reverse_words_impl
|
||||||
* Swap, in 'val', byte at index 'n' - 1 with byte at index 'n' - 2, decrement n by 2 until n == 0
|
* Swap, in 'val', byte at index 'n' - 1 with byte at index 'n' - 2, decrement n by 2 until n == 0
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
SPROUT_CONSTEXPR T reverse_words_impl(T val, uint_fast8_t n) {
|
SPROUT_CONSTEXPR T reverse_words_impl(T val, std::uint_fast8_t n) {
|
||||||
return n == 0 ? val : reverse_words_impl(swap(val, n - 1, n - 2), n - 2);
|
return n == 0 ? val : reverse_words_impl(swap(val, n - 1, n - 2), n - 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* reverse_words
|
* reverse_words
|
||||||
* Reverse each word in 'val'
|
* Reverse each word in 'val'
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
SPROUT_CONSTEXPR T reverse_words(T val) {
|
SPROUT_CONSTEXPR T reverse_words(T val) {
|
||||||
return reverse_words_impl(val, sizeof(T));
|
return reverse_words_impl(val, sizeof(T));
|
||||||
}
|
}
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3620.pdf
|
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3620.pdf
|
||||||
// template<>
|
// template<>
|
||||||
// constexpr unsigned-integral hton(unsigned-integral host)
|
// constexpr unsigned-integral hton(unsigned-integral host)
|
||||||
template<typename T>
|
template<typename T>
|
||||||
SPROUT_CONSTEXPR T hton(T host) {
|
SPROUT_CONSTEXPR T hton(T host) {
|
||||||
#if defined(BOOST_BIG_ENDIAN)
|
#if defined(BOOST_BIG_ENDIAN)
|
||||||
return host;
|
return host;
|
||||||
#elif defined(BOOST_LITTLE_ENDIAN)
|
#elif defined(BOOST_LITTLE_ENDIAN)
|
||||||
return detail::reverse(host);
|
return detail::reverse(host);
|
||||||
#elif defined(BOOST_PDP_ENDIAN)
|
#elif defined(BOOST_PDP_ENDIAN)
|
||||||
return detail::reverse_words(host);
|
return detail::reverse_words(host);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3620.pdf
|
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3620.pdf
|
||||||
// template<>
|
// template<>
|
||||||
// constexpr unsigned-integral ntoh(unsigned-integral net)
|
// constexpr unsigned-integral ntoh(unsigned-integral net)
|
||||||
template<typename T>
|
template<typename T>
|
||||||
SPROUT_CONSTEXPR T ntoh(T net) {
|
SPROUT_CONSTEXPR T ntoh(T net) {
|
||||||
#if defined(BOOST_BIG_ENDIAN)
|
#if defined(BOOST_BIG_ENDIAN)
|
||||||
return net;
|
return net;
|
||||||
#elif defined(BOOST_LITTLE_ENDIAN)
|
#elif defined(BOOST_LITTLE_ENDIAN)
|
||||||
return detail::reverse(net);
|
return detail::reverse(net);
|
||||||
#elif defined(BOOST_PDP_ENDIAN)
|
#elif defined(BOOST_PDP_ENDIAN)
|
||||||
return detail::reverse_words(host);
|
return detail::reverse_words(host);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3620.pdf
|
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3620.pdf
|
||||||
// uint32_t htonl(uint32_t host32)
|
// uint32_t htonl(uint32_t host32)
|
||||||
SPROUT_CONSTEXPR uint32_t htonl(uint32_t host32) {
|
SPROUT_CONSTEXPR std::uint32_t htonl(std::uint32_t host32) {
|
||||||
return hton(host32);
|
return hton(host32);
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3620.pdf
|
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3620.pdf
|
||||||
// uint16_t htons(uint16_t host16)
|
// uint16_t htons(uint16_t host16)
|
||||||
SPROUT_CONSTEXPR uint16_t htons(uint16_t host16) {
|
SPROUT_CONSTEXPR std::uint16_t htons(std::uint16_t host16) {
|
||||||
return hton(host16);
|
return hton(host16);
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3620.pdf
|
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3620.pdf
|
||||||
// uint32_t ntohl(uint32_t net32)
|
// uint32_t ntohl(uint32_t net32)
|
||||||
SPROUT_CONSTEXPR uint32_t ntohl(uint32_t net32) {
|
SPROUT_CONSTEXPR std::uint32_t ntohl(std::uint32_t net32) {
|
||||||
return ntoh(net32);
|
return ntoh(net32);
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3620.pdf
|
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3620.pdf
|
||||||
// uint16_t ntohs(uint32_t net16)
|
// uint16_t ntohs(uint32_t net16)
|
||||||
SPROUT_CONSTEXPR uint16_t ntohs(uint16_t net16) {
|
SPROUT_CONSTEXPR std::uint16_t ntohs(std::uint16_t net16) {
|
||||||
return ntoh(net16);
|
return ntoh(net16);
|
||||||
}
|
}
|
||||||
} //namespace net
|
} //namespace net
|
||||||
} // namespace sprout
|
} // namespace sprout
|
||||||
|
|
||||||
#endif // #ifndef SPROUT_NET_NET_HPP
|
#endif // #ifndef SPROUT_NET_ENDIAN_HPP
|
||||||
|
|
|
@ -46,6 +46,7 @@
|
||||||
#include <sprout/limits.hpp>
|
#include <sprout/limits.hpp>
|
||||||
#include <sprout/logic.hpp>
|
#include <sprout/logic.hpp>
|
||||||
#include <sprout/math.hpp>
|
#include <sprout/math.hpp>
|
||||||
|
#include <sprout/net.hpp>
|
||||||
#include <sprout/none.hpp>
|
#include <sprout/none.hpp>
|
||||||
#include <sprout/numeric.hpp>
|
#include <sprout/numeric.hpp>
|
||||||
#include <sprout/numeric/dft.hpp>
|
#include <sprout/numeric/dft.hpp>
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "../libs/random/test/random.cpp"
|
#include "../libs/random/test/random.cpp"
|
||||||
#include "../libs/utility/string_ref/test/string_ref.cpp"
|
#include "../libs/utility/string_ref/test/string_ref.cpp"
|
||||||
#include "../libs/cstring/test/cstring.cpp"
|
#include "../libs/cstring/test/cstring.cpp"
|
||||||
|
#include "../libs/net/test/endian.cpp"
|
||||||
|
|
||||||
#ifdef TESTSPR_CPP_INCLUDE_DISABLE_TESTSPR_SPROUT_HPP
|
#ifdef TESTSPR_CPP_INCLUDE_DISABLE_TESTSPR_SPROUT_HPP
|
||||||
# undef TESTSPR_CPP_INCLUDE
|
# undef TESTSPR_CPP_INCLUDE
|
||||||
|
@ -40,6 +41,7 @@ namespace testspr {
|
||||||
testspr::random_test();
|
testspr::random_test();
|
||||||
testspr::string_ref_test();
|
testspr::string_ref_test();
|
||||||
testspr::cstring_test();
|
testspr::cstring_test();
|
||||||
|
testspr::endian_test();
|
||||||
}
|
}
|
||||||
} // namespace testspr
|
} // namespace testspr
|
||||||
|
|
||||||
|
|
|
@ -1,121 +1,121 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# Copyright (c) 2011-2014 Bolero MURAKAMI
|
# Copyright (c) 2011-2014 Bolero MURAKAMI
|
||||||
# https://github.com/bolero-MURAKAMI/Sprout
|
# https://github.com/bolero-MURAKAMI/Sprout
|
||||||
#
|
#
|
||||||
# Distributed under the Boost Software License, Version 1.0. (See accompanying
|
# Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
import sys
|
import sys
|
||||||
import optparse
|
import optparse
|
||||||
import subprocess
|
import subprocess
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import logging
|
import logging
|
||||||
import tty
|
import tty
|
||||||
|
|
||||||
def build(command):
|
def build(command):
|
||||||
sys.stdout.write(".")
|
sys.stdout.write(".")
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
return subprocess.call(command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
return subprocess.call(command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||||
|
|
||||||
def continue_build(command):
|
def continue_build(command):
|
||||||
if command[2]:
|
if command[2]:
|
||||||
sys.stdout.write("*")
|
sys.stdout.write("*")
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
return 0
|
return 0
|
||||||
sys.stdout.write(".")
|
sys.stdout.write(".")
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
result = subprocess.call(command[0], shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
result = subprocess.call(command[0], shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||||
if not result:
|
if not result:
|
||||||
logging.critical(command[1])
|
logging.critical(command[1])
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = optparse.OptionParser(description='darkcult.py')
|
parser = optparse.OptionParser(description='darkcult.py')
|
||||||
parser.add_option('--source', type='string', default='../../example/darkroom/two_spheres.hpp')
|
parser.add_option('--source', type='string', default='../../example/darkroom/two_spheres.hpp')
|
||||||
parser.add_option('--stagedir', type='string', default='darkroom')
|
parser.add_option('--stagedir', type='string', default='darkroom')
|
||||||
parser.add_option('--output', type='string', default='out.ppm')
|
parser.add_option('--output', type='string', default='out.ppm')
|
||||||
parser.add_option('--compiler', type='string', default='g++')
|
parser.add_option('--compiler', type='string', default='g++')
|
||||||
parser.add_option('--width', type='int', default=16)
|
parser.add_option('--width', type='int', default=16)
|
||||||
parser.add_option('--height', type='int', default=16)
|
parser.add_option('--height', type='int', default=16)
|
||||||
parser.add_option('--tile_width', type='int', default=16)
|
parser.add_option('--tile_width', type='int', default=16)
|
||||||
parser.add_option('--tile_height', type='int', default=16)
|
parser.add_option('--tile_height', type='int', default=16)
|
||||||
parser.add_option('--left', type='int', default=0)
|
parser.add_option('--left', type='int', default=0)
|
||||||
parser.add_option('--top', type='int', default=0)
|
parser.add_option('--top', type='int', default=0)
|
||||||
parser.add_option('--right', type='int')
|
parser.add_option('--right', type='int')
|
||||||
parser.add_option('--bottom', type='int')
|
parser.add_option('--bottom', type='int')
|
||||||
parser.add_option('--compile_options', type='string', default='')
|
parser.add_option('--compile_options', type='string', default='')
|
||||||
parser.add_option('--darkcult_cpp', type='string')
|
parser.add_option('--darkcult_cpp', type='string')
|
||||||
parser.add_option('--continuable', type='int', default=0)
|
parser.add_option('--continuable', type='int', default=0)
|
||||||
parser.add_option('--continue_file', type='string', default='continue.log')
|
parser.add_option('--continue_file', type='string', default='continue.log')
|
||||||
parser.add_option('--max_procs', type='int', default=0)
|
parser.add_option('--max_procs', type='int', default=0)
|
||||||
(opts, args) = parser.parse_args()
|
(opts, args) = parser.parse_args()
|
||||||
|
|
||||||
def format_command(x, y):
|
def format_command(x, y):
|
||||||
bin = "%s/%d/%d.out" % (opts.stagedir, y, x)
|
bin = "%s/%d/%d.out" % (opts.stagedir, y, x)
|
||||||
out = "%s/%d/%d.ppm" % (opts.stagedir, y, x)
|
out = "%s/%d/%d.ppm" % (opts.stagedir, y, x)
|
||||||
return "%s -o %s" \
|
return "%s -o %s" \
|
||||||
" %s" \
|
" %s" \
|
||||||
" -DDARKROOM_SOURCE=\'\"%s\"\'" \
|
" -DDARKROOM_SOURCE=\'\"%s\"\'" \
|
||||||
" -DDARKROOM_TOTAL_WIDTH=%d -DDARKROOM_TOTAL_HEIGHT=%d" \
|
" -DDARKROOM_TOTAL_WIDTH=%d -DDARKROOM_TOTAL_HEIGHT=%d" \
|
||||||
" -DDARKROOM_TILE_WIDTH=%d -DDARKROOM_TILE_HEIGHT=%d" \
|
" -DDARKROOM_TILE_WIDTH=%d -DDARKROOM_TILE_HEIGHT=%d" \
|
||||||
" -DDARKROOM_OFFSET_X=%d -DDARKROOM_OFFSET_Y=%d" \
|
" -DDARKROOM_OFFSET_X=%d -DDARKROOM_OFFSET_Y=%d" \
|
||||||
" %s" \
|
" %s" \
|
||||||
" && %s > %s" \
|
" && %s > %s" \
|
||||||
% (opts.compiler, bin,
|
% (opts.compiler, bin,
|
||||||
opts.compile_options,
|
opts.compile_options,
|
||||||
opts.source,
|
opts.source,
|
||||||
opts.width, opts.height,
|
opts.width, opts.height,
|
||||||
opts.tile_width, opts.tile_height,
|
opts.tile_width, opts.tile_height,
|
||||||
x, y,
|
x, y,
|
||||||
opts.darkcult_cpp,
|
opts.darkcult_cpp,
|
||||||
bin, out
|
bin, out
|
||||||
)
|
)
|
||||||
|
|
||||||
if opts.continuable:
|
if opts.continuable:
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
filename=opts.continue_file,
|
filename=opts.continue_file,
|
||||||
format="%(message)s"
|
format="%(message)s"
|
||||||
)
|
)
|
||||||
completed = [line.strip() for line in open(opts.continue_file)]
|
completed = [line.strip() for line in open(opts.continue_file)]
|
||||||
|
|
||||||
fd = sys.stdin.fileno()
|
fd = sys.stdin.fileno()
|
||||||
tc_old = tty.tcgetattr(fd)
|
tc_old = tty.tcgetattr(fd)
|
||||||
tty.setcbreak(fd)
|
tty.setcbreak(fd)
|
||||||
|
|
||||||
def format_continue_command(x, y):
|
def format_continue_command(x, y):
|
||||||
key = "%d %d" % (x, y)
|
key = "%d %d" % (x, y)
|
||||||
return (format_command(x, y), key, key in completed)
|
return (format_command(x, y), key, key in completed)
|
||||||
|
|
||||||
pool = multiprocessing.Pool(opts.max_procs if opts.max_procs != 0 else None)
|
pool = multiprocessing.Pool(opts.max_procs if opts.max_procs != 0 else None)
|
||||||
try:
|
try:
|
||||||
results = pool.map_async(
|
results = pool.map_async(
|
||||||
continue_build,
|
continue_build,
|
||||||
[format_continue_command(x, y)
|
[format_continue_command(x, y)
|
||||||
for y in range(opts.top, opts.bottom, opts.tile_height)
|
for y in range(opts.top, opts.bottom, opts.tile_height)
|
||||||
for x in range(opts.left, opts.right, opts.tile_width)
|
for x in range(opts.left, opts.right, opts.tile_width)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
while True:
|
while True:
|
||||||
code = sys.stdin.read(1)
|
code = sys.stdin.read(1)
|
||||||
if results.ready():
|
if results.ready():
|
||||||
break
|
break
|
||||||
if code == 'q':
|
if code == 'q':
|
||||||
pool.terminate()
|
pool.terminate()
|
||||||
return 2
|
return 2
|
||||||
return any(results.get())
|
return any(results.get())
|
||||||
finally:
|
finally:
|
||||||
tty.tcsetattr(fd, tty.TCSADRAIN, tc_old)
|
tty.tcsetattr(fd, tty.TCSADRAIN, tc_old)
|
||||||
logging.shutdown()
|
logging.shutdown()
|
||||||
else:
|
else:
|
||||||
pool = multiprocessing.Pool(opts.max_procs if opts.max_procs != 0 else None)
|
pool = multiprocessing.Pool(opts.max_procs if opts.max_procs != 0 else None)
|
||||||
return any(pool.map(
|
return any(pool.map(
|
||||||
build,
|
build,
|
||||||
[format_command(x, y)
|
[format_command(x, y)
|
||||||
for y in range(opts.top, opts.bottom, opts.tile_height)
|
for y in range(opts.top, opts.bottom, opts.tile_height)
|
||||||
for x in range(opts.left, opts.right, opts.tile_width)
|
for x in range(opts.left, opts.right, opts.tile_width)
|
||||||
]
|
]
|
||||||
))
|
))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
sys.exit(main())
|
sys.exit(main())
|
||||||
|
|
|
@ -1,73 +1,73 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# Copyright (c) 2011-2014 Bolero MURAKAMI
|
# Copyright (c) 2011-2014 Bolero MURAKAMI
|
||||||
# https://github.com/bolero-MURAKAMI/Sprout
|
# https://github.com/bolero-MURAKAMI/Sprout
|
||||||
#
|
#
|
||||||
# Distributed under the Boost Software License, Version 1.0. (See accompanying
|
# Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
import sys
|
import sys
|
||||||
import optparse
|
import optparse
|
||||||
import subprocess
|
import subprocess
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
|
|
||||||
def build(command):
|
def build(command):
|
||||||
sys.stdout.write(".")
|
sys.stdout.write(".")
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
return subprocess.call(command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
return subprocess.call(command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = optparse.OptionParser(description='test.py')
|
parser = optparse.OptionParser(description='test.py')
|
||||||
parser.add_option('--stagedir', type='string', default='testspr')
|
parser.add_option('--stagedir', type='string', default='testspr')
|
||||||
parser.add_option('--gcc_version', type='string', default='.')
|
parser.add_option('--gcc_version', type='string', default='.')
|
||||||
parser.add_option('--clang_version', type='string', default='.')
|
parser.add_option('--clang_version', type='string', default='.')
|
||||||
parser.add_option('--gcc_root', type='string', default='/usr/local')
|
parser.add_option('--gcc_root', type='string', default='/usr/local')
|
||||||
parser.add_option('--clang_root', type='string', default='/usr/local')
|
parser.add_option('--clang_root', type='string', default='/usr/local')
|
||||||
parser.add_option('--all_options', type='string', default='')
|
parser.add_option('--all_options', type='string', default='')
|
||||||
parser.add_option('--test_cpp', type='string')
|
parser.add_option('--test_cpp', type='string')
|
||||||
parser.add_option('--serialized_std_options', type='string', default='{}')
|
parser.add_option('--serialized_std_options', type='string', default='{}')
|
||||||
parser.add_option('--serialized_compiler_specific_options', type='string', default='{}')
|
parser.add_option('--serialized_compiler_specific_options', type='string', default='{}')
|
||||||
parser.add_option('--serialized_version_specific_options', type='string', default='{}')
|
parser.add_option('--serialized_version_specific_options', type='string', default='{}')
|
||||||
parser.add_option('--max_procs', type='int', default=0)
|
parser.add_option('--max_procs', type='int', default=0)
|
||||||
(opts, args) = parser.parse_args()
|
(opts, args) = parser.parse_args()
|
||||||
|
|
||||||
std_options = eval(opts.serialized_std_options)
|
std_options = eval(opts.serialized_std_options)
|
||||||
version_specific_options = eval(opts.serialized_version_specific_options)
|
version_specific_options = eval(opts.serialized_version_specific_options)
|
||||||
compiler_specific_options = eval(opts.serialized_compiler_specific_options)
|
compiler_specific_options = eval(opts.serialized_compiler_specific_options)
|
||||||
|
|
||||||
def format_command(name, version, root):
|
def format_command(name, version, root):
|
||||||
base = "%s-%s" % (name, version) if version != "." else name
|
base = "%s-%s" % (name, version) if version != "." else name
|
||||||
bin = "%s/test.%s.out" % (opts.stagedir, base.replace('.', ''))
|
bin = "%s/test.%s.out" % (opts.stagedir, base.replace('.', ''))
|
||||||
compile_log = "%s/test.%s.compile.log" % (opts.stagedir, base.replace('.', ''))
|
compile_log = "%s/test.%s.compile.log" % (opts.stagedir, base.replace('.', ''))
|
||||||
execute_log = "%s/test.%s.execute.log" % (opts.stagedir, base.replace('.', ''))
|
execute_log = "%s/test.%s.execute.log" % (opts.stagedir, base.replace('.', ''))
|
||||||
compiler = "%s/%s/bin/%s++" % (root, base, name.rstrip('c')) if version != "." else "%s++" % name.rstrip('c')
|
compiler = "%s/%s/bin/%s++" % (root, base, name.rstrip('c')) if version != "." else "%s++" % name.rstrip('c')
|
||||||
return "%s -o %s" \
|
return "%s -o %s" \
|
||||||
" %s %s" \
|
" %s %s" \
|
||||||
" %s %s" \
|
" %s %s" \
|
||||||
" %s > %s 2>&1" \
|
" %s > %s 2>&1" \
|
||||||
" && %s > %s 2>&1" \
|
" && %s > %s 2>&1" \
|
||||||
% (compiler, bin,
|
% (compiler, bin,
|
||||||
std_options.get(base, ''), opts.all_options,
|
std_options.get(base, ''), opts.all_options,
|
||||||
compiler_specific_options.get(name, ''), version_specific_options.get(base, ''),
|
compiler_specific_options.get(name, ''), version_specific_options.get(base, ''),
|
||||||
opts.test_cpp, compile_log,
|
opts.test_cpp, compile_log,
|
||||||
bin, execute_log
|
bin, execute_log
|
||||||
)
|
)
|
||||||
|
|
||||||
pool = multiprocessing.Pool(opts.max_procs if opts.max_procs != 0 else None)
|
pool = multiprocessing.Pool(opts.max_procs if opts.max_procs != 0 else None)
|
||||||
return sum(result != 0 for result in pool.map(
|
return sum(result != 0 for result in pool.map(
|
||||||
build,
|
build,
|
||||||
([format_command('gcc', version, opts.gcc_root)
|
([format_command('gcc', version, opts.gcc_root)
|
||||||
for version in opts.gcc_version.split(' ')
|
for version in opts.gcc_version.split(' ')
|
||||||
] if opts.gcc_version != ' '
|
] if opts.gcc_version != ' '
|
||||||
else []
|
else []
|
||||||
)
|
)
|
||||||
+
|
+
|
||||||
([format_command('clang', version, opts.clang_root)
|
([format_command('clang', version, opts.clang_root)
|
||||||
for version in opts.clang_version.split(' ')
|
for version in opts.clang_version.split(' ')
|
||||||
] if opts.clang_version != ' '
|
] if opts.clang_version != ' '
|
||||||
else []
|
else []
|
||||||
)
|
)
|
||||||
))
|
))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
sys.exit(main())
|
sys.exit(main())
|
||||||
|
|
Loading…
Reference in a new issue