From 8991eae405cc355c4146d8551d71672d5270ddb2 Mon Sep 17 00:00:00 2001 From: canape Date: Wed, 23 Jan 2008 12:15:49 +0000 Subject: [PATCH] Add primitive types for pack and unpack git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@900 331e1502-861f-0410-8da2-ba01fb791d7f --- trunk/paradiseo-peo/src/core/messaging.h | 13 ++++++++-- trunk/paradiseo-peo/src/rmc/mpi/mess.cpp | 31 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/trunk/paradiseo-peo/src/core/messaging.h b/trunk/paradiseo-peo/src/core/messaging.h index a5d7246ed..78aedd9ad 100644 --- a/trunk/paradiseo-peo/src/core/messaging.h +++ b/trunk/paradiseo-peo/src/core/messaging.h @@ -38,9 +38,13 @@ #define __mess_h #include +#include /* Char */ -extern void pack (const char & __c); +extern void pack (const char & __c); + +/* Boolean */ +extern void pack (const bool & __b, int __nitem = 1); /* Float */ extern void pack (const float & __f, int __nitem = 1); @@ -67,7 +71,8 @@ extern void pack (const long & __l, int __nitem = 1); extern void pack (const unsigned long & __ul, int __nitem = 1); /* String */ -extern void pack (const char * __str); +extern void pack (const char * __str); +extern void pack (const std::string & __str); /* Pointer */ template void pack (const T * __ptr) { @@ -87,6 +92,9 @@ template void pack (const std :: pair & __pair) { /* Char */ extern void unpack (char & __c); +/* Boolean */ +extern void unpack (bool & __b, int __nitem = 1); + /* Float */ extern void unpack (float & __f, int __nitem = 1); @@ -113,6 +121,7 @@ extern void unpack (unsigned long & __ul, int __nitem = 1); /* String */ extern void unpack (char * __str); +extern void unpack (std::string & __str); /* Pointer */ template void unpack (T * & __ptr) { diff --git a/trunk/paradiseo-peo/src/rmc/mpi/mess.cpp b/trunk/paradiseo-peo/src/rmc/mpi/mess.cpp index addadc3b2..075780378 100644 --- a/trunk/paradiseo-peo/src/rmc/mpi/mess.cpp +++ b/trunk/paradiseo-peo/src/rmc/mpi/mess.cpp @@ -158,6 +158,12 @@ void pack (const char & __c) { MPI_Pack ((void *) & __c, 1, MPI_CHAR, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD); } +/* Boolean */ +void pack (const bool & __b, int __nitem){ + + MPI_Pack ((void *) & __b, __nitem, MPI_INT, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD); +} + /* Float */ void pack (const float & __f, int __nitem) { @@ -214,12 +220,27 @@ void pack (const char * __str) { MPI_Pack ((void *) __str, len, MPI_CHAR, mpi_buf, MPI_BUF_SIZE, & pos_buf, MPI_COMM_WORLD); } +void pack (const std::string & __str) { + + size_t size = __str.size() + 1; + char * buffer = new char[ size ]; + strncpy( buffer, __str.c_str(), size ); + pack (buffer); + delete [] buffer; +} + /* Char */ void unpack (char & __c) { MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __c, 1, MPI_CHAR, MPI_COMM_WORLD); } +/* Boolean */ +extern void unpack (bool & __b, int __nitem ){ + + MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & __b, __nitem, MPI_INT, MPI_COMM_WORLD); +} + /* Float */ void unpack (float & __f, int __nitem) { @@ -275,3 +296,13 @@ void unpack (char * __str) { MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & len, 1, MPI_INT, MPI_COMM_WORLD); MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, __str, len, MPI_CHAR, MPI_COMM_WORLD); } +void unpack (std::string & __str) { + + char * buffer; + int len; + MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, & len, 1, MPI_INT, MPI_COMM_WORLD); + MPI_Unpack (mpi_buf, MPI_BUF_SIZE, & pos_buf, buffer, len, MPI_CHAR, MPI_COMM_WORLD); + __str.assign( buffer ); + +} +