Add primitive types for pack and unpack
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@900 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
c775354e77
commit
8991eae405
2 changed files with 42 additions and 2 deletions
|
|
@ -38,9 +38,13 @@
|
|||
#define __mess_h
|
||||
|
||||
#include <utility>
|
||||
#include <string>
|
||||
|
||||
/* 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 <class T> void pack (const T * __ptr) {
|
||||
|
|
@ -87,6 +92,9 @@ template <class U, class V> void pack (const std :: pair <U, V> & __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 <class T> void unpack (T * & __ptr) {
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue