41 #ifndef EPETRAEXT_PACKTRAITS_H
42 #define EPETRAEXT_PACKTRAITS_H
44 #if defined(EpetraExt_SHOW_DEPRECATED_WARNINGS)
46 #warning "The EpetraExt package is deprecated"
76 static size_t size( T
const &
object )
77 {
return object.packedByteCount(); }
86 static void pack( T
const &
object,
char * buf,
size_t size,
int & pos )
87 {
object.pack( buf, size, pos ); }
96 static void unpack( T &
object,
char * buf,
size_t size,
int & pos )
97 {
object.unpack( buf, size, pos ); }
106 static size_t size( std::string
const &
object )
107 {
return object.length() +
sizeof(size_t); }
109 static void pack( std::string
const &
object,
char * buf,
size_t size,
int & pos )
111 size_t len =
object.length();
112 std::memcpy( buf+pos, &len,
sizeof(
size_t) );
113 pos +=
sizeof(size_t);
114 std::memcpy( buf+pos,
object.c_str(), len );
118 static void unpack( std::string &
object,
char * buf,
size_t size,
int & pos )
121 std::memcpy( &len, buf+pos,
sizeof(
size_t) );
122 pos +=
sizeof(size_t);
123 object = std::string( buf+pos, len );
132 template <
typename T>
135 static size_t size( std::vector<T>
const &
object )
136 {
return object.size() *
sizeof(T) +
sizeof(
size_t); }
138 static void pack( std::vector<T>
const &
object,
char * buf,
size_t size,
int & os )
140 size_t len =
object.size();
141 std::memcpy( buf+pos, &len,
sizeof(
size_t) );
142 pos +=
sizeof(size_t);
143 std::memcpy( buf+pos, &
object[0], len*
sizeof(T) );
144 pos += len*
sizeof(T);
147 static void unpack( std::vector<T> &
object,
char * buf,
int size,
int & pos )
150 std::memcpy( &len, buf+pos,
sizeof(
size_t) );
151 pos +=
sizeof(size_t);
153 std::memcpy( &
object[0], buf+pos, len*
sizeof(T) );
154 pos += len*
sizeof(T);
Traits for packing and unpacking of data into char buffers for communication.
static void pack(std::vector< T > const &object, char *buf, size_t size, int &os)
static void pack(std::string const &object, char *buf, size_t size, int &pos)
static void unpack(T &object, char *buf, size_t size, int &pos)
Unpacks object from char buffer.
static void unpack(std::vector< T > &object, char *buf, int size, int &pos)
static size_t size(std::string const &object)
static size_t size(std::vector< T > const &object)
static void pack(T const &object, char *buf, size_t size, int &pos)
Packs object into char buffer.
static size_t size(T const &object)
Returns size in byte necessary to pack datatype.
static void unpack(std::string &object, char *buf, size_t size, int &pos)