Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r62822 - in sandbox/endian_ext: boost/endian libs/integer/test
From: vicente.botet_at_[hidden]
Date: 2010-06-11 19:00:41


Author: viboes
Date: 2010-06-11 19:00:40 EDT (Fri, 11 Jun 2010)
New Revision: 62822
URL: http://svn.boost.org/trac/boost/changeset/62822

Log:
Cleanup + test update
Added:
   sandbox/endian_ext/libs/integer/test/endian_convert_unique_endian_test.cpp (contents, props changed)
Removed:
   sandbox/endian_ext/boost/endian/native_tree.hpp
Text files modified:
   sandbox/endian_ext/libs/integer/test/Jamfile.v2 | 1 +
   sandbox/endian_ext/libs/integer/test/endian_view_test.cpp | 18 +++++++++++++++++-
   2 files changed, 18 insertions(+), 1 deletions(-)

Deleted: sandbox/endian_ext/boost/endian/native_tree.hpp
==============================================================================
--- sandbox/endian_ext/boost/endian/native_tree.hpp 2010-06-11 19:00:40 EDT (Fri, 11 Jun 2010)
+++ (empty file)
@@ -1,103 +0,0 @@
-// Boost endian_view.hpp header file -------------------------------------------------------//
-
-// (C) Copyright VicenteJ Botet Escriba 2010
-
-// 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_NATIVE_TREE__HPP
-#define BOOST_ENDIAN_NATIVE_TREE__HPP
-
-#include <boost/endian/endian.hpp>
-#include <boost/mpl/vector.hpp>
-#include <boost/mpl/push_back.hpp>
-#include <boost/mpl/void.hpp>
-#include <boost/fusion/include/deref.hpp>
-#include <boost/fusion/include/next.hpp>
-#include <boost/fusion/include/begin.hpp>
-#include <boost/fusion/include/end.hpp>
-#include <boost/fusion/include/is_sequence.hpp>
-
-namespace boost {
-
-
-namespace endian {
-
- namespace endian_detail {
-
- template <typename T,
- bool isFundamental = is_fundamental<T>::value,
- bool IsSeq = fusion::traits::is_sequence<T>::value
- >
- struct native_tree_impl;
-
- }
-
- /// By default the shared endianess of a type depends on whether it is fundamental and or a fusion sequence.
- template <typename T>
- struct native_tree : endian_detail::native_tree_impl<T> {};
-
- namespace endian_detail {
-
- // fundamental types are native
- template <typename T, bool IsSeq>
- struct native_tree_impl<T, true, IsSeq> {
- typedef native type;
- };
-
- // other type which has not been explicitly declared is undefined,
- template <typename T>
- struct native_tree_impl<T, false, false> {};
-
- template <typename SharedTree, typename It, typename End>
- struct native_tree_loop {
- private:
- typedef
- typename remove_reference<
- typename remove_cv<
- typename fusion::result_of::deref<It>::type
- >::type
- >::type it_type;
- public:
- typedef typename native_tree_loop<
- typename mpl::push_back<SharedTree, typename native_tree<it_type>::type>::type,
- typename fusion::result_of::next<It>::type,
- End
- >::type type;
- };
-
- // When iteration ends, accumulated SharedTree
- template <typename SharedTree, typename End>
- struct native_tree_loop<SharedTree,End,End> {
- typedef SharedTree type;
- };
-
- // fusion sequences are mixed if not all the elements habve the same endianess,
- // otherwise the endianess of all the types.
- template <typename Seq>
- struct native_tree_impl<Seq, false, true> :
- native_tree_loop< mpl::vector<>,
- typename fusion::result_of::begin<Seq>::type,
- typename fusion::result_of::end<Seq>::type
- >
- {};
-
- }
- /// All the elements of an array are seen with the same endianess.
- template <typename T, std::size_t N>
- struct native_tree<T[N]> {
- typedef typename native_tree<T>::type type;
- };
-
-} // namespace endian
-
-} // namespace boost
-
-
-
-#endif // BOOST_ENDIAN_NATIVE_TREE__HPP

Modified: sandbox/endian_ext/libs/integer/test/Jamfile.v2
==============================================================================
--- sandbox/endian_ext/libs/integer/test/Jamfile.v2 (original)
+++ sandbox/endian_ext/libs/integer/test/Jamfile.v2 2010-06-11 19:00:40 EDT (Fri, 11 Jun 2010)
@@ -22,4 +22,5 @@
          [ run endian_view_test.cpp ]
          [ run endian_type_test.cpp ]
          [ run endian_convert_test.cpp ]
+ [ run endian_convert_unique_endian_test.cpp ]
       ;

Added: sandbox/endian_ext/libs/integer/test/endian_convert_unique_endian_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/endian_ext/libs/integer/test/endian_convert_unique_endian_test.cpp 2010-06-11 19:00:40 EDT (Fri, 11 Jun 2010)
@@ -0,0 +1,125 @@
+// endian_conversion_same_endian_test.cpp ---------------------------------------------------------//
+
+// (C) Copyright VicenteJ Botet Escriba 2010
+
+// 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_pack
+
+//----------------------------------------------------------------------------//
+
+
+#include <boost/detail/lightweight_test.hpp> // for main
+
+#include <iostream>
+#include <boost/type_traits/remove_cv.hpp>
+#include <boost/type_traits/remove_reference.hpp>
+#include <boost/integer/endian_type.hpp>
+#include <boost/integer/endian_conversion.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/fusion/adapted/struct/adapt_struct.hpp>
+
+
+using namespace std; // Not the best programming practice, but I
+using namespace boost; // want to verify this combination of using
+using namespace boost::integer; // namespaces works. See endian_operations_test
+// // for tests that don't do "using namespace".
+
+namespace X {
+
+struct big_c {
+ uint32_t a;
+ uint16_t b;
+};
+
+
+struct little_c {
+ int32_t a;
+ int16_t b;
+};
+
+struct mixed_c {
+ big_c a;
+ little_c b;
+};
+
+}
+
+struct network {};
+
+namespace boost {
+namespace endian {
+
+ template <>
+ struct domain_map <network, X::big_c> {
+ typedef mpl::vector<little,little> type;
+ };
+ template <>
+ struct domain_map <network, X::little_c> {
+ typedef mpl::vector<little,little> type;
+ };
+
+}
+}
+
+BOOST_FUSION_ADAPT_STRUCT(
+ X::big_c,
+ (uint32_t, a)
+ (uint16_t, b)
+)
+
+BOOST_FUSION_ADAPT_STRUCT(
+ X::little_c,
+ (int32_t, a)
+ (int16_t, b)
+)
+
+
+BOOST_FUSION_ADAPT_STRUCT(
+ X::mixed_c,
+ (X::big_c, a)
+ (X::little_c, b)
+)
+
+
+namespace
+{
+void check_endian_send()
+{
+
+ X::mixed_c m;
+ m.a.a=0x01020304;
+ m.a.b=0x0A0B;
+ m.b.a=0x01020304;
+ m.b.b=0x0A0B;
+
+ //~ std::cout << std::hex << m.a.a << std::endl;
+ //~ std::cout << std::hex << m.a.b << std::endl;
+ //~ std::cout << std::hex << m.b.a << std::endl;
+ //~ std::cout << std::hex << m.b.b << std::endl;
+
+ integer::convert_from<network>(m);
+ //~ std::cout << std::hex << m.a.a << std::endl;
+ //~ std::cout << std::hex << m.a.b << std::endl;
+ //~ std::cout << std::hex << m.b.a << std::endl;
+ //~ std::cout << std::hex << m.b.b << std::endl;
+
+ integer::convert_to<network>(m);
+ //~ std::cout << std::hex << m.a.a << std::endl;
+ //~ std::cout << std::hex << m.a.b << std::endl;
+ //~ std::cout << std::hex << m.b.a << std::endl;
+ //~ std::cout << std::hex << m.b.b << std::endl;
+
+ //~ return m.a.a+m.a.b+ m.b.a+m.b.b;
+
+}
+} // unnamed namespace
+
+int main( int argc, char * argv[] )
+{
+ check_endian_send();
+ return boost::report_errors();
+} // main
+

Modified: sandbox/endian_ext/libs/integer/test/endian_view_test.cpp
==============================================================================
--- sandbox/endian_ext/libs/integer/test/endian_view_test.cpp (original)
+++ sandbox/endian_ext/libs/integer/test/endian_view_test.cpp 2010-06-11 19:00:40 EDT (Fri, 11 Jun 2010)
@@ -15,6 +15,7 @@
 // between operand types.
 
 //----------------------------------------------------------------------------//
+#include <iostream>
 
 #include <boost/detail/lightweight_test.hpp> // for main
 
@@ -56,10 +57,18 @@
     as_endian<big_endian>(a.s1)=0x0102;
     as_big(a.i1)=0x01020304;
     
+
     as_little(a.c2)=0x0A;
     as_little(a.s2)=0x0102;
     as_little(a.i2)=0x01020304;
 
+ std::cout << std::hex << int(a.c1) << std::endl;
+ std::cout << std::hex << a.s1 << std::endl;
+ std::cout << std::hex << a.i1 << std::endl;
+ std::cout << std::hex << int(a.c2) << std::endl;
+ std::cout << std::hex << a.s2 << std::endl;
+ std::cout << std::hex << a.i2 << std::endl;
+
     a.c1=as_big(a.c1);
     a.s1=as_big(a.s1);
     a.i1=as_big(a.i1);
@@ -75,7 +84,14 @@
     BOOST_TEST(a.c2 == 0x0A);
     BOOST_TEST(a.s2 == 0x0102);
     BOOST_TEST(a.i2 == 0x01020304);
-
+
+ as_big(a.c1)=as_little(a.c1);
+ as_big(a.s1)=as_little(a.s1);
+ as_big(a.i1)=as_little(a.i1);
+
+ std::cout << std::hex << int(a.c1) << std::endl;
+ std::cout << std::hex << a.s1 << std::endl;
+ std::cout << std::hex << a.i1 << std::endl;
     
 }
 } // unnamed namespace


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk