1 #include <libmesh/parallel.h>
2 #include <libmesh/null_output_iterator.h>
13 class Packing<
std::basic_string<T>> {
16 static const unsigned int size_bytes = 4;
23 unsigned int string_len = reinterpret_cast<const unsigned char &>(in[size_bytes-1]);
24 for (
signed int i=size_bytes-2; i >= 0; --i)
27 string_len += reinterpret_cast<const unsigned char &>(in[i]);
36 return get_string_len(in) + size_bytes;
39 static unsigned int packable_size
40 (
const std::basic_string<T> & s,
43 return s.size() + size_bytes;
47 template <
typename Iter>
48 static void pack (
const std::basic_string<T> & b, Iter data_out,
51 unsigned int string_len = b.size();
52 for (
unsigned int i=0; i != size_bytes; ++i)
54 *data_out++ = (string_len % 256);
57 std::copy(b.begin(), b.end(), data_out);
60 static std::basic_string<T>
61 unpack (
typename std::vector<T>::const_iterator in,
void *)
63 unsigned int string_len = get_string_len(in);
65 std::ostringstream oss;
66 for (
unsigned int i = 0; i < string_len; ++i)
67 oss << reinterpret_cast<const unsigned char &>(in[i+size_bytes]);
69 in += size_bytes + string_len;
72 return std::string(oss.str());
90 CPPUNIT_TEST( testNullAllGather );
91 CPPUNIT_TEST( testNullSendReceive );
92 CPPUNIT_TEST( testContainerSendReceive );
96 CPPUNIT_TEST_SUITE_END();
111 std::vector<processor_id_type> vals;
113 std::vector<std::string> send(1);
115 send[0].assign(
"Hello");
117 send[0].assign(
"Goodbye");
120 ((
void *)(NULL), send.begin(), send.end(),
127 std::vector<processor_id_type> vals;
129 std::vector<std::string> send(1);
131 const unsigned int dest_rank =
133 const unsigned int source_rank =
137 std::ostringstream os;
143 (dest_rank, (
void *)(NULL), send.begin(), send.end(),
144 source_rank, (
void *)(NULL),
152 std::vector<processor_id_type> vals;
154 std::vector<std::string> send(1), recv;
157 const unsigned int dest_rank =
159 const unsigned int source_rank =
163 std::ostringstream os;
169 (dest_rank, (
void *)(NULL), send.begin(), send.end(),
170 source_rank, (
void *)(NULL),
171 std::back_inserter(recv),
174 CPPUNIT_ASSERT_EQUAL(recv.size(), std::size_t(1));
178 std::ostringstream os;
183 CPPUNIT_ASSERT_EQUAL(recv[0], check);