30 #ifndef SACADO_FAD_SERIALIZATIONTRAITSIMP_HPP
31 #define SACADO_FAD_SERIALIZATIONTRAITSIMP_HPP
35 #ifdef HAVE_SACADO_TEUCHOSCOMM
46 template <
typename Ordinal,
typename FadType,
typename Serializer>
47 struct SerializationImp {
63 static const bool supportsDirectSerialization =
false;
69 static Ordinal fromCountToIndirectBytes(
const Serializer& vs,
76 for (
Ordinal i=0; i<count; i++) {
77 int my_sz = buffer[i].size();
79 if (sz == 0) tot_sz = my_sz;
80 Ordinal b1 = iSerT::fromCountToIndirectBytes(1, &tot_sz);
81 Ordinal b2 = vs.fromCountToIndirectBytes(1, &(buffer[i].
val()));
82 Ordinal b3 = oSerT::fromCountToIndirectBytes(1, &b2);
84 if (tot_sz != my_sz) {
93 b4 = vs.fromCountToIndirectBytes(tot_sz, cx->dx());
94 Ordinal b5 = oSerT::fromCountToIndirectBytes(1, &b4);
95 bytes += b1+b2+b3+b4+b5;
103 static void serialize (
const Serializer& vs,
111 for (
Ordinal i=0; i<count; i++) {
113 int my_sz = buffer[i].size();
115 if (sz == 0) tot_sz = my_sz;
116 Ordinal b1 = iSerT::fromCountToIndirectBytes(1, &tot_sz);
117 iSerT::serialize(1, &tot_sz, b1, charBuffer);
121 Ordinal b2 = vs.fromCountToIndirectBytes(1, &(buffer[i].
val()));
122 Ordinal b3 = oSerT::fromCountToIndirectBytes(1, &b2);
123 oSerT::serialize(1, &b2, b3, charBuffer);
125 vs.serialize(1, &(buffer[i].
val()), b2, charBuffer);
130 if (tot_sz != my_sz) {
139 b4 = vs.fromCountToIndirectBytes(tot_sz, cx->dx());
140 Ordinal b5 = oSerT::fromCountToIndirectBytes(1, &b4);
141 oSerT::serialize(1, &b4, b5, charBuffer);
143 vs.serialize(tot_sz, cx->dx(), b4, charBuffer);
151 static Ordinal fromIndirectBytesToCount(
const Serializer& vs,
153 const char charBuffer[],
157 while (bytes_used < bytes) {
160 Ordinal b1 = iSerT::fromCountToDirectBytes(1);
165 Ordinal b3 = oSerT::fromCountToDirectBytes(1);
166 const Ordinal *b2 = oSerT::convertFromCharPtr(charBuffer);
173 Ordinal b5 = oSerT::fromCountToDirectBytes(1);
174 const Ordinal *b4 = oSerT::convertFromCharPtr(charBuffer);
186 static void deserialize (
const Serializer& vs,
188 const char charBuffer[],
192 for (
Ordinal i=0; i<count; i++) {
195 Ordinal b1 = iSerT::fromCountToDirectBytes(1);
196 const int *my_sz = iSerT::convertFromCharPtr(charBuffer);
201 if (sz == 0) tot_sz = *my_sz;
202 buffer[i] =
FadType(tot_sz, 0.0);
205 Ordinal b3 = oSerT::fromCountToDirectBytes(1);
206 const Ordinal *b2 = oSerT::convertFromCharPtr(charBuffer);
208 vs.deserialize(*b2, charBuffer, 1, &(buffer[i].
val()));
212 Ordinal b5 = oSerT::fromCountToDirectBytes(1);
213 const Ordinal *b4 = oSerT::convertFromCharPtr(charBuffer);
215 vs.deserialize(*b4, charBuffer, *my_sz,
227 template <
typename Ordinal,
typename FadType>
228 struct SerializationTraitsImp {
239 typedef typename DS::DefaultSerializerType ValueSerializer;
242 typedef SerializationImp<Ordinal,FadType,ValueSerializer> Imp;
247 static const bool supportsDirectSerialization =
248 Imp::supportsDirectSerialization;
256 return Imp::fromCountToIndirectBytes(
257 DS::getDefaultSerializer(), count, buffer);
261 static void serialize (
const Ordinal count,
266 DS::getDefaultSerializer(), count, buffer, bytes, charBuffer);
271 const char charBuffer[]) {
272 return Imp::fromIndirectBytesToCount(
273 DS::getDefaultSerializer(), bytes, charBuffer);
277 static void deserialize (
const Ordinal bytes,
278 const char charBuffer[],
282 DS::getDefaultSerializer(), bytes, charBuffer, count, buffer);
290 template <
typename Ordinal,
typename FadType>
291 struct StaticSerializationTraitsImp {
295 typedef Sacado::Fad::SerializationTraitsImp<Ordinal,FadType> STI;
298 static const bool supportsDirectSerialization =
299 vSerT::supportsDirectSerialization;
306 return DSerT::fromCountToDirectBytes(count);
310 static char* convertToCharPtr(
FadType* ptr ) {
311 return DSerT::convertToCharPtr(ptr);
315 static const char* convertToCharPtr(
const FadType* ptr ) {
316 return DSerT::convertToCharPtr(ptr);
321 return DSerT::fromDirectBytesToCount(bytes);
325 static FadType* convertFromCharPtr(
char* ptr ) {
326 return DSerT::convertFromCharPtr(ptr);
330 static const FadType* convertFromCharPtr(
const char* ptr ) {
331 return DSerT::convertFromCharPtr(ptr);
342 if (supportsDirectSerialization)
343 return DSerT::fromCountToIndirectBytes(count, buffer);
345 return STI::fromCountToIndirectBytes(count, buffer);
349 static void serialize (
const Ordinal count,
353 if (supportsDirectSerialization)
354 return DSerT::serialize(count, buffer, bytes, charBuffer);
356 return STI::serialize(count, buffer, bytes, charBuffer);
361 const char charBuffer[]) {
362 if (supportsDirectSerialization)
363 return DSerT::fromIndirectBytesToCount(bytes, charBuffer);
365 return STI::fromIndirectBytesToCount(bytes, charBuffer);
369 static void deserialize (
const Ordinal bytes,
370 const char charBuffer[],
373 if (supportsDirectSerialization)
374 return DSerT::deserialize(bytes, charBuffer, count, buffer);
376 return STI::deserialize(bytes, charBuffer, count, buffer);
384 template <
typename Ordinal,
typename FadType,
typename ValueSerializer>
385 class SerializerImp {
390 typedef SerializationImp<Ordinal,FadType,ValueSerializer> Imp;
401 typedef ValueSerializer value_serializer_type;
404 static const bool supportsDirectSerialization =
405 Imp::supportsDirectSerialization;
413 Ordinal getSerializerSize()
const {
return sz; }
424 const FadType buffer[])
const {
425 return Imp::fromCountToIndirectBytes(*vs, count, buffer, sz);
429 void serialize (
const Ordinal count,
432 char charBuffer[])
const {
433 Imp::serialize(*vs, count, buffer, bytes, charBuffer, sz);
438 const char charBuffer[])
const {
439 return Imp::fromIndirectBytesToCount(*vs, bytes, charBuffer, sz);
443 void deserialize (
const Ordinal bytes,
444 const char charBuffer[],
447 return Imp::deserialize(*vs, bytes, charBuffer, count, buffer, sz);
458 #endif // HAVE_SACADO_TEUCHOSCOMM
460 #endif // SACADO_FAD_SERIALIZATIONTRAITSIMP_HPP
Sacado::Fad::DFad< double > FadType
expr expr expr fastAccessDx(i)) FAD_UNARYOP_MACRO(exp