45 #ifndef TEUCHOS_SERIALIZATION_TRAITS_HPP
46 #define TEUCHOS_SERIALIZATION_TRAITS_HPP
52 #ifdef HAVE_TEUCHOSCORE_QUADMATH
54 #endif // HAVE_TEUCHOSCORE_QUADMATH
56 #ifdef HAVE_TEUCHOS_QD
57 #include <qd/dd_real.h>
58 #include <qd/qd_real.h>
72 static inline T
notDefined() {
return(T::this_type_is_missing_a_specialization());}
129 template <
typename Ordinal,
typename T>
197 (void)count; (void)buffer;
222 (void)count; (void)buffer; (void)bytes; (void)charBuffer;
228 const char charBuffer[]) {
229 (void)bytes; (void)charBuffer;
250 const char charBuffer[],
254 (void)bytes; (void)charBuffer; (void)count; (void)buffer;
275 template <
typename Ordinal,
typename T>
310 template <
typename Ordinal,
typename T>
313 static const bool supportsDirectSerialization =
true;
315 static Ordinal fromCountToDirectBytes(
const Ordinal count)
316 {
return sizeof(T)*count; }
317 static char* convertToCharPtr( T* ptr )
318 {
return reinterpret_cast<char*
>(ptr); }
319 static const char* convertToCharPtr(
const T* ptr )
320 {
return reinterpret_cast<const char*
>(ptr); }
321 static Ordinal fromDirectBytesToCount(
const Ordinal count)
322 {
return count/
sizeof(T); }
323 static T* convertFromCharPtr(
char* ptr )
324 {
return reinterpret_cast<T*
>(ptr); }
325 static const T* convertFromCharPtr(
const char* ptr )
326 {
return reinterpret_cast<const T*
>(ptr); }
328 static Ordinal fromCountToIndirectBytes(
const Ordinal count,
const T buffer[])
329 {
return fromCountToDirectBytes(count); }
330 static void serialize(
331 const Ordinal count,
const T buffer[],
const Ordinal bytes,
char charBuffer[]
339 const char *_buffer = convertToCharPtr(buffer);
340 std::copy(_buffer,_buffer+bytes,charBuffer);
342 static Ordinal fromIndirectBytesToCount(
const Ordinal bytes,
343 const char charBuffer[])
344 {
return fromDirectBytesToCount(bytes); }
345 static void deserialize(
346 const Ordinal bytes,
const char charBuffer[],
const Ordinal count, T buffer[]
352 char *_buffer = convertToCharPtr(buffer);
353 std::copy(charBuffer,charBuffer+bytes,_buffer);
362 template<
typename Ordinal>
367 template<
typename Ordinal>
368 class SerializationTraits<Ordinal,signed char>
369 :
public DirectSerializationTraits<Ordinal,signed char>
372 template<
typename Ordinal>
373 class SerializationTraits<Ordinal,unsigned char>
374 :
public DirectSerializationTraits<Ordinal,unsigned char>
377 template<
typename Ordinal>
378 class SerializationTraits<Ordinal,short int>
379 :
public DirectSerializationTraits<Ordinal,short int>
382 template<
typename Ordinal>
383 class SerializationTraits<Ordinal,unsigned short int>
384 :
public DirectSerializationTraits<Ordinal,unsigned short int>
387 template<
typename Ordinal>
388 class SerializationTraits<Ordinal,int>
389 :
public DirectSerializationTraits<Ordinal,int>
392 template<
typename Ordinal>
393 class SerializationTraits<Ordinal,unsigned int>
394 :
public DirectSerializationTraits<Ordinal,unsigned int>
397 template<
typename Ordinal>
398 class SerializationTraits<Ordinal,long int>
399 :
public DirectSerializationTraits<Ordinal,long int>
402 template<
typename Ordinal>
403 class SerializationTraits<Ordinal,unsigned long int>
404 :
public DirectSerializationTraits<Ordinal,long unsigned int>
407 template<
typename Ordinal>
408 class SerializationTraits<Ordinal,float>
409 :
public DirectSerializationTraits<Ordinal,float>
412 template<
typename Ordinal>
413 class SerializationTraits<Ordinal,double>
414 :
public DirectSerializationTraits<Ordinal,double>
418 template<
typename Ordinal,
typename P1,
typename P2>
419 class SerializationTraits<Ordinal,std::pair<P1,P2> >
420 :
public DirectSerializationTraits<Ordinal,std::pair<P1,P2> >
423 #ifdef HAVE_TEUCHOSCORE_QUADMATH
424 template<
typename Ordinal>
425 class SerializationTraits<Ordinal,__float128>
426 :
public DirectSerializationTraits<Ordinal,__float128>
428 #endif // HAVE_TEUCHOSCORE_QUADMATH
430 #ifdef HAVE_TEUCHOS_QD
431 template<
typename Ordinal>
432 class SerializationTraits<Ordinal,dd_real>
433 :
public DirectSerializationTraits<Ordinal,dd_real>
436 template<
typename Ordinal>
437 class SerializationTraits<Ordinal,qd_real>
438 :
public DirectSerializationTraits<Ordinal,qd_real>
442 #ifdef HAVE_TEUCHOS_COMPLEX
444 template<
typename Ordinal>
445 class SerializationTraits<Ordinal,std::complex<float> >
446 :
public DirectSerializationTraits<Ordinal,std::complex<float> >
449 template<
typename Ordinal>
450 class SerializationTraits<Ordinal,std::complex<double> >
451 :
public DirectSerializationTraits<Ordinal,std::complex<double> >
454 #endif // HAVE_TEUCHOS_COMPLEX
461 template<
typename Ordinal>
462 class SerializationTraits<Ordinal, long long int>
463 :
public DirectSerializationTraits<Ordinal, long long int>
471 template<
typename Ordinal>
472 class SerializationTraits<Ordinal, unsigned long long int>
473 :
public DirectSerializationTraits<Ordinal, unsigned long long int>
478 #endif // TEUCHOS_SERIALIZATION_TRAITS_HPP
Serialization traits for objects that support direct serialization.
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 T notDefined()
This function should not compile if there is an attempt to instantiate!
static Ordinal fromCountToIndirectBytes(const Ordinal count, const T buffer[])
Return the number of bytes for count objects.
static const bool supportsDirectSerialization
Whether the type T supports direct serialization.
Teuchos header file which uses auto-configuration information to include necessary C++ headers...
static void deserialize(const Ordinal bytes, const char charBuffer[], const Ordinal count, T buffer[])
Deserialize from an indirect char[] buffer.
Serialization class for types T that use value semantics.
static Ordinal fromIndirectBytesToCount(const Ordinal bytes, const char charBuffer[])
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*.
Report an error if a specialization of SerializationTraits is missing.
Serialization traits class for types T that use value semantics.
Standard test and throw macros.
static Ordinal fromDirectBytesToCount(const Ordinal bytes)
Return the number of objects for bytes of storage.
static void serialize(const Ordinal count, const T buffer[], const Ordinal bytes, char charBuffer[])
Serialize to an indirect char[] buffer.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
This macro is designed to be a short version of TEUCHOS_TEST_FOR_EXCEPTION() that is easier to call...
static Ordinal fromCountToDirectBytes(const Ordinal count)
Return the number of bytes for count objects.