Teuchos - Trilinos Tools Package Version of the Day
Teuchos::SerializationTraits< Ordinal, T > Class Template Reference

Serialization traits class for types T that use value semantics. More...

#include <Teuchos_SerializationTraits.hpp>

Inheritance diagram for Teuchos::SerializationTraits< Ordinal, T >:
Teuchos::ValueTypeSerializer< Ordinal, T >

List of all members.

Static Public Member Functions

Direct serialization functions (not defined if supportsDirectSerialization==false)
static Ordinal fromCountToDirectBytes (const Ordinal count)
 Return the number of bytes for count objects.
static char * convertToCharPtr (T *ptr)
 Convert the pointer type to char*.
static const char * convertToCharPtr (const T *ptr)
 Convert the pointer type to const char*.
static Ordinal fromDirectBytesToCount (const Ordinal bytes)
 Return the number of objects for bytes of storage.
static T * convertFromCharPtr (char *ptr)
 Convert the pointer type from char*.
static const T * convertFromCharPtr (const char *ptr)
 Convert the pointer type from char*.
Indirect serialization functions (always defined and supported)
static Ordinal fromCountToIndirectBytes (const Ordinal count, const T buffer[])
 Return the number of bytes for count objects.
static void serialize (const Ordinal count, const T buffer[], const Ordinal bytes, char charBuffer[])
 Serialize to an indirect char[] buffer.
static Ordinal fromIndirectBytesToCount (const Ordinal bytes, const char charBuffer[])
 Return the number of objects for bytes of storage.
static void deserialize (const Ordinal bytes, const char charBuffer[], const Ordinal count, T buffer[])
 Deserialize from an indirect char[] buffer.

Static Public Attributes

Serialization type selection
static const bool supportsDirectSerialization = false
 Whether the type T supports direct serialization.

Detailed Description

template<typename Ordinal, typename T>
class Teuchos::SerializationTraits< Ordinal, T >

Serialization traits class for types T that use value semantics.

This traits class describes how to convert between arrays of T, and arrays of char. We call the process of converting from T to char "serialization," and from char to T "deserialization." Teuchos uses serialization and deserialization mainly for implementing distributed-memory message-passing communication in a generic way.

Template Parameters:
OrdinalThe same template parameter as that of Comm. The integer type used to count the number of packets sent and received.
TThe type of the objects that this class shows how to serialize.

Teuchos defines specializations of this class for many commonly used types in distributed-memory communication, such as char, int (signed and unsigned), float, double, and std::pair<P1, P2> for certain types P1 and P2. Depending on your Trilinos build options, other specializations may be defined as well, for example for long long int, double-double and quad-double real types (dd_real resp. qd_real), or certain std::complex<T> specializations. If a specialization of this class does not exist for your type T, you may define your own specialization.

Note:
Before defining specializations of this class, make sure that they do not duplicate specializations already present in PyTrilinos (see packages/PyTrilinos/src/Teuchos_Traits.i)

There are two different serialization modes: direct and indirect. "Direct" serialization means that you can convert directly between an object of type T and an array of char, of a specific length dependent only on the type T and not on the particular instance. Specifically, it means you can

1. reinterpret_cast a pointer to an instance of T into an array of char (which array has length dependent only on the type T and not on the specific T instance), 2. serialize the resulting array of char, and finally 3. deserialize by reading in the array of char and doing a reinterpret_cast back into a T.

"Indirect" serialization is defined as any serialization method more general than that. The supportsDirectSerialization class Boolean tells you whether this specialization supports direct serialization.

SerializationTraits is used by classes such as ValueTypeSerializationBuffer, ConstValueTypeSerializationBuffer, ValueTypeDeserializationBuffer, and ConstValueTypeDeserializationBuffer.

Definition at line 125 of file Teuchos_SerializationTraits.hpp.


Member Function Documentation

template<typename Ordinal , typename T >
static Ordinal Teuchos::SerializationTraits< Ordinal, T >::fromCountToDirectBytes ( const Ordinal  count) [inline, static]

Return the number of bytes for count objects.

Definition at line 143 of file Teuchos_SerializationTraits.hpp.

template<typename Ordinal , typename T >
static char* Teuchos::SerializationTraits< Ordinal, T >::convertToCharPtr ( T *  ptr) [inline, static]

Convert the pointer type to char*.

Definition at line 150 of file Teuchos_SerializationTraits.hpp.

template<typename Ordinal , typename T >
static const char* Teuchos::SerializationTraits< Ordinal, T >::convertToCharPtr ( const T *  ptr) [inline, static]

Convert the pointer type to const char*.

Definition at line 157 of file Teuchos_SerializationTraits.hpp.

template<typename Ordinal , typename T >
static Ordinal Teuchos::SerializationTraits< Ordinal, T >::fromDirectBytesToCount ( const Ordinal  bytes) [inline, static]

Return the number of objects for bytes of storage.

Definition at line 164 of file Teuchos_SerializationTraits.hpp.

template<typename Ordinal , typename T >
static T* Teuchos::SerializationTraits< Ordinal, T >::convertFromCharPtr ( char *  ptr) [inline, static]

Convert the pointer type from char*.

Definition at line 171 of file Teuchos_SerializationTraits.hpp.

template<typename Ordinal , typename T >
static const T* Teuchos::SerializationTraits< Ordinal, T >::convertFromCharPtr ( const char *  ptr) [inline, static]

Convert the pointer type from char*.

Definition at line 178 of file Teuchos_SerializationTraits.hpp.

template<typename Ordinal , typename T >
static Ordinal Teuchos::SerializationTraits< Ordinal, T >::fromCountToIndirectBytes ( const Ordinal  count,
const T  buffer[] 
) [inline, static]

Return the number of bytes for count objects.

Definition at line 190 of file Teuchos_SerializationTraits.hpp.

template<typename Ordinal , typename T >
static void Teuchos::SerializationTraits< Ordinal, T >::serialize ( const Ordinal  count,
const T  buffer[],
const Ordinal  bytes,
char  charBuffer[] 
) [inline, static]

Serialize to an indirect char[] buffer.

Parameters:
count[in] The number of objects to serialize.
buffer[in] The objects to serialize.
bytes[in] Number of bytes in charBuffer[]
charBuffer[out] Array (length bytes) containing the serialized objects.

Preconditions:

  • bytes==fromCountToIndirectBytes(count)

Definition at line 212 of file Teuchos_SerializationTraits.hpp.

template<typename Ordinal , typename T >
static Ordinal Teuchos::SerializationTraits< Ordinal, T >::fromIndirectBytesToCount ( const Ordinal  bytes,
const char  charBuffer[] 
) [inline, static]

Return the number of objects for bytes of storage.

Definition at line 222 of file Teuchos_SerializationTraits.hpp.

template<typename Ordinal , typename T >
static void Teuchos::SerializationTraits< Ordinal, T >::deserialize ( const Ordinal  bytes,
const char  charBuffer[],
const Ordinal  count,
buffer[] 
) [inline, static]

Deserialize from an indirect char[] buffer.

Parameters:
bytes[in] Number of bytes in charBuffer[]
charBuffer[in] Array (length bytes) containing the serialized objects.
count[in] The number of objects to deserialize.
buffer[out] The deserialized objects.

Preconditions:

  • count==fromIndirectBytesToCount(bytes)

Definition at line 244 of file Teuchos_SerializationTraits.hpp.


Member Data Documentation

template<typename Ordinal , typename T >
const bool Teuchos::SerializationTraits< Ordinal, T >::supportsDirectSerialization = false [static]

Whether the type T supports direct serialization.

See the class documentation for definitions of "direct" and "indirect" serialization.

Definition at line 135 of file Teuchos_SerializationTraits.hpp.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines