10 #ifndef SACADO_FAD_SERIALIZATIONTRAITSIMP_HPP
11 #define SACADO_FAD_SERIALIZATIONTRAITSIMP_HPP
15 #ifdef HAVE_SACADO_TEUCHOSCOMM
26 template <
typename Ordinal,
typename FadType,
typename Serializer>
27 struct SerializationImp {
43 static const bool supportsDirectSerialization =
false;
49 static Ordinal fromCountToIndirectBytes(
const Serializer& vs,
57 int my_sz = buffer[
i].size();
59 if (sz == 0) tot_sz = my_sz;
60 Ordinal b1 = iSerT::fromCountToIndirectBytes(1, &tot_sz);
61 Ordinal b2 = vs.fromCountToIndirectBytes(1, &(buffer[
i].
val()));
62 Ordinal b3 = oSerT::fromCountToIndirectBytes(1, &b2);
64 if (tot_sz != my_sz) {
73 b4 = vs.fromCountToIndirectBytes(tot_sz, cx->dx());
74 Ordinal b5 = oSerT::fromCountToIndirectBytes(1, &b4);
75 bytes += b1+b2+b3+b4+b5;
83 static void serialize (
const Serializer& vs,
93 int my_sz = buffer[
i].size();
95 if (sz == 0) tot_sz = my_sz;
96 Ordinal b1 = iSerT::fromCountToIndirectBytes(1, &tot_sz);
97 iSerT::serialize(1, &tot_sz, b1, charBuffer);
101 Ordinal b2 = vs.fromCountToIndirectBytes(1, &(buffer[
i].
val()));
102 Ordinal b3 = oSerT::fromCountToIndirectBytes(1, &b2);
103 oSerT::serialize(1, &b2, b3, charBuffer);
105 vs.serialize(1, &(buffer[
i].
val()), b2, charBuffer);
110 if (tot_sz != my_sz) {
119 b4 = vs.fromCountToIndirectBytes(tot_sz, cx->dx());
120 Ordinal b5 = oSerT::fromCountToIndirectBytes(1, &b4);
121 oSerT::serialize(1, &b4, b5, charBuffer);
123 vs.serialize(tot_sz, cx->dx(), b4, charBuffer);
131 static Ordinal fromIndirectBytesToCount(
const Serializer& vs,
133 const char charBuffer[],
137 while (bytes_used < bytes) {
140 Ordinal b1 = iSerT::fromCountToDirectBytes(1);
145 Ordinal b3 = oSerT::fromCountToDirectBytes(1);
146 const Ordinal *b2 = oSerT::convertFromCharPtr(charBuffer);
153 Ordinal b5 = oSerT::fromCountToDirectBytes(1);
154 const Ordinal *b4 = oSerT::convertFromCharPtr(charBuffer);
166 static void deserialize (
const Serializer& vs,
168 const char charBuffer[],
175 Ordinal b1 = iSerT::fromCountToDirectBytes(1);
176 const int *my_sz = iSerT::convertFromCharPtr(charBuffer);
181 if (sz == 0) tot_sz = *my_sz;
185 Ordinal b3 = oSerT::fromCountToDirectBytes(1);
186 const Ordinal *b2 = oSerT::convertFromCharPtr(charBuffer);
188 vs.deserialize(*b2, charBuffer, 1, &(buffer[
i].
val()));
192 Ordinal b5 = oSerT::fromCountToDirectBytes(1);
193 const Ordinal *b4 = oSerT::convertFromCharPtr(charBuffer);
195 vs.deserialize(*b4, charBuffer, *my_sz,
207 template <
typename Ordinal,
typename FadType>
208 struct SerializationTraitsImp {
219 typedef typename DS::DefaultSerializerType ValueSerializer;
222 typedef SerializationImp<Ordinal,FadType,ValueSerializer> Imp;
227 static const bool supportsDirectSerialization =
228 Imp::supportsDirectSerialization;
236 return Imp::fromCountToIndirectBytes(
237 DS::getDefaultSerializer(), count, buffer);
241 static void serialize (
const Ordinal count,
246 DS::getDefaultSerializer(), count, buffer, bytes, charBuffer);
251 const char charBuffer[]) {
252 return Imp::fromIndirectBytesToCount(
253 DS::getDefaultSerializer(), bytes, charBuffer);
257 static void deserialize (
const Ordinal bytes,
258 const char charBuffer[],
262 DS::getDefaultSerializer(), bytes, charBuffer, count, buffer);
270 template <
typename Ordinal,
typename FadType>
271 struct StaticSerializationTraitsImp {
275 typedef Sacado::Fad::SerializationTraitsImp<Ordinal,FadType> STI;
278 static const bool supportsDirectSerialization =
279 vSerT::supportsDirectSerialization;
286 return DSerT::fromCountToDirectBytes(count);
290 static char* convertToCharPtr(
FadType* ptr ) {
291 return DSerT::convertToCharPtr(ptr);
295 static const char* convertToCharPtr(
const FadType* ptr ) {
296 return DSerT::convertToCharPtr(ptr);
301 return DSerT::fromDirectBytesToCount(bytes);
305 static FadType* convertFromCharPtr(
char* ptr ) {
306 return DSerT::convertFromCharPtr(ptr);
310 static const FadType* convertFromCharPtr(
const char* ptr ) {
311 return DSerT::convertFromCharPtr(ptr);
322 if (supportsDirectSerialization)
323 return DSerT::fromCountToIndirectBytes(count, buffer);
325 return STI::fromCountToIndirectBytes(count, buffer);
329 static void serialize (
const Ordinal count,
333 if (supportsDirectSerialization)
334 return DSerT::serialize(count, buffer, bytes, charBuffer);
336 return STI::serialize(count, buffer, bytes, charBuffer);
341 const char charBuffer[]) {
342 if (supportsDirectSerialization)
343 return DSerT::fromIndirectBytesToCount(bytes, charBuffer);
345 return STI::fromIndirectBytesToCount(bytes, charBuffer);
349 static void deserialize (
const Ordinal bytes,
350 const char charBuffer[],
353 if (supportsDirectSerialization)
354 return DSerT::deserialize(bytes, charBuffer, count, buffer);
356 return STI::deserialize(bytes, charBuffer, count, buffer);
364 template <
typename Ordinal,
typename FadType,
typename ValueSerializer>
365 class SerializerImp {
370 typedef SerializationImp<Ordinal,FadType,ValueSerializer> Imp;
381 typedef ValueSerializer value_serializer_type;
384 static const bool supportsDirectSerialization =
385 Imp::supportsDirectSerialization;
393 Ordinal getSerializerSize()
const {
return sz; }
404 const FadType buffer[])
const {
405 return Imp::fromCountToIndirectBytes(*vs, count, buffer, sz);
409 void serialize (
const Ordinal count,
412 char charBuffer[])
const {
413 Imp::serialize(*vs, count, buffer, bytes, charBuffer, sz);
418 const char charBuffer[])
const {
419 return Imp::fromIndirectBytesToCount(*vs, bytes, charBuffer, sz);
423 void deserialize (
const Ordinal bytes,
424 const char charBuffer[],
427 return Imp::deserialize(*vs, bytes, charBuffer, count, buffer, sz);
438 #endif // HAVE_SACADO_TEUCHOSCOMM
440 #endif // SACADO_FAD_SERIALIZATIONTRAITSIMP_HPP
Sacado::Fad::DFad< double > FadType
expr expr expr fastAccessDx(i)) FAD_UNARYOP_MACRO(exp