Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r55418 - in trunk: boost/mpi/detail libs/mpi/test
From: troyer_at_[hidden]
Date: 2009-08-05 01:02:05


Author: troyer
Date: 2009-08-05 01:02:04 EDT (Wed, 05 Aug 2009)
New Revision: 55418
URL: http://svn.boost.org/trac/boost/changeset/55418

Log:
Fixed ticket #2151
Text files modified:
   trunk/boost/mpi/detail/mpi_datatype_oarchive.hpp | 30 +++++++++++++++++++++++++++++-
   trunk/libs/mpi/test/ring_test.cpp | 5 +++++
   2 files changed, 34 insertions(+), 1 deletions(-)

Modified: trunk/boost/mpi/detail/mpi_datatype_oarchive.hpp
==============================================================================
--- trunk/boost/mpi/detail/mpi_datatype_oarchive.hpp (original)
+++ trunk/boost/mpi/detail/mpi_datatype_oarchive.hpp 2009-08-05 01:02:04 EDT (Wed, 05 Aug 2009)
@@ -9,6 +9,8 @@
 #ifndef BOOST_MPI_DETAIL_MPI_DATATYPE_OARCHIVE_HPP
 #define BOOST_MPI_DETAIL_MPI_DATATYPE_OARCHIVE_HPP
 
+#include <boost/type_traits/is_enum.hpp>
+#include <boost/mpl/bool.hpp>
 #include <boost/archive/detail/oserializer.hpp>
 #include <boost/archive/detail/auto_link_archive.hpp>
 #include <boost/archive/basic_archive.hpp>
@@ -16,6 +18,7 @@
 #include <boost/mpi/detail/mpi_datatype_primitive.hpp>
 #include <boost/mpi/datatype_fwd.hpp>
 #include <boost/mpl/assert.hpp>
+#include <boost/integer.hpp>
 #include <boost/archive/detail/register_archive.hpp>
 
 namespace boost { namespace mpi { namespace detail {
@@ -34,9 +37,34 @@
     mpi_datatype_oarchive(const T& x)
          : mpi_datatype_primitive(&x) // register address
         {
- BOOST_MPL_ASSERT((is_mpi_datatype<T>));
+ BOOST_MPL_ASSERT((is_mpi_datatype<T>));
           *this << x; // serialize the object
         }
+
+ // intermediate level to support override of operators
+ // for templates in the absence of partial function
+ // template ordering
+ template<class T>
+ void save_override(T const& t, BOOST_PFTO int)
+ {
+ save_enum(t,boost::is_enum<T>());
+ }
+
+ template<class T>
+ void save_enum(T const& t, mpl::false_)
+ {
+ ignore_skeleton_oarchive<mpi_datatype_oarchive>::save_override(t, 0);
+ }
+
+ template<class T>
+ void save_enum(T const& t, mpl::true_)
+ {
+ // select the right sized integer for the enum
+ typedef typename boost::uint_t<8*sizeof(T)>::least int_type;
+ BOOST_MPL_ASSERT((sizeof(T)==sizeof(int_type)));
+ this->save(*reinterpret_cast<int_type const*>(&t));
+ }
+
 };
 
 } } } // end namespace boost::mpi::detail

Modified: trunk/libs/mpi/test/ring_test.cpp
==============================================================================
--- trunk/libs/mpi/test/ring_test.cpp (original)
+++ trunk/libs/mpi/test/ring_test.cpp 2009-08-05 01:02:04 EDT (Wed, 05 Aug 2009)
@@ -81,6 +81,9 @@
   delete [] transferred_values;
 }
 
+enum color_t {red, green, blue};
+BOOST_IS_MPI_DATATYPE(color_t)
+
 int test_main(int argc, char* argv[])
 {
   boost::mpi::environment env(argc, argv);
@@ -95,6 +98,8 @@
   // Check transfer of individual objects
   ring_test(comm, 17, "integers", 0);
   ring_test(comm, 17, "integers", 1);
+ ring_test(comm, red, "enums", 1);
+ ring_test(comm, red, "enums", 1);
   ring_test(comm, gps_position(39,16,20.2799), "GPS positions", 0);
   ring_test(comm, gps_position(26,25,30.0), "GPS positions", 1);
   ring_test(comm, std::string("Rosie"), "string", 0);


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