30 #ifndef SACADO_TAY_SERIALIZATIONTRAITSIMP_HPP
31 #define SACADO_TAY_SERIALIZATIONTRAITSIMP_HPP
35 #ifdef HAVE_SACADO_TEUCHOSCOMM
46 template <
typename Ordinal,
typename TayType,
typename Serializer>
47 struct SerializationImp {
60 static const bool supportsDirectSerialization =
false;
66 static Ordinal fromCountToIndirectBytes(
const Serializer& vs,
68 const TayType buffer[],
73 for (
Ordinal i=0; i<count; i++) {
74 unsigned int my_sz = buffer[i].degree()+1;
75 unsigned int tot_sz = sz;
76 if (sz == 0) tot_sz = my_sz;
77 if (tot_sz != my_sz) {
78 x =
new TayType(buffer[i]);
79 x->resize(tot_sz-1,
true);
84 Ordinal b1 = iSerT::fromCountToIndirectBytes(1, &tot_sz);
85 Ordinal b2 = vs.fromCountToIndirectBytes(
86 tot_sz, &(cx->fastAccessCoeff(0)));
87 Ordinal b3 = oSerT::fromCountToIndirectBytes(1, &b2);
98 static void serialize (
const Serializer& vs,
100 const TayType buffer[],
106 for (
Ordinal i=0; i<count; i++) {
108 unsigned int my_sz = buffer[i].degree()+1;
109 unsigned int tot_sz = sz;
110 if (sz == 0) tot_sz = my_sz;
111 Ordinal b1 = iSerT::fromCountToIndirectBytes(1, &tot_sz);
112 iSerT::serialize(1, &tot_sz, b1, charBuffer);
116 if (tot_sz != my_sz) {
117 x =
new TayType(buffer[i]);
118 x->resize(tot_sz-1,
true);
123 Ordinal b2 = vs.fromCountToIndirectBytes(
124 tot_sz, &(cx->fastAccessCoeff(0)));
125 Ordinal b3 = oSerT::fromCountToIndirectBytes(1, &b2);
126 oSerT::serialize(1, &b2, b3, charBuffer);
128 vs.serialize(tot_sz, &(cx->fastAccessCoeff(0)), b2, charBuffer);
138 static Ordinal fromIndirectBytesToCount(
const Serializer& vs,
140 const char charBuffer[],
144 while (bytes_used < bytes) {
147 Ordinal b1 = iSerT::fromCountToDirectBytes(1);
152 Ordinal b3 = oSerT::fromCountToDirectBytes(1);
153 const Ordinal *b2 = oSerT::convertFromCharPtr(charBuffer);
165 static void deserialize (
const Serializer& vs,
167 const char charBuffer[],
171 for (
Ordinal i=0; i<count; i++) {
174 Ordinal b1 = iSerT::fromCountToDirectBytes(1);
175 const unsigned int *my_sz = iSerT::convertFromCharPtr(charBuffer);
179 unsigned int tot_sz = sz;
180 if (sz == 0) tot_sz = *my_sz;
181 buffer[i] = TayType(tot_sz-1, 0.0);
184 Ordinal b3 = oSerT::fromCountToDirectBytes(1);
185 const Ordinal *b2 = oSerT::convertFromCharPtr(charBuffer);
187 vs.deserialize(*b2, charBuffer, *my_sz,
188 &(buffer[i].fastAccessCoeff(0)));
199 template <
typename Ordinal,
typename TayType>
200 struct SerializationTraitsImp {
211 typedef typename DS::DefaultSerializerType ValueSerializer;
214 typedef SerializationImp<Ordinal,TayType,ValueSerializer> Imp;
219 static const bool supportsDirectSerialization =
220 Imp::supportsDirectSerialization;
227 const TayType buffer[]) {
228 return Imp::fromCountToIndirectBytes(
229 DS::getDefaultSerializer(), count, buffer);
233 static void serialize (
const Ordinal count,
234 const TayType buffer[],
238 DS::getDefaultSerializer(), count, buffer, bytes, charBuffer);
243 const char charBuffer[]) {
244 return Imp::fromIndirectBytesToCount(
245 DS::getDefaultSerializer(), bytes, charBuffer);
249 static void deserialize (
const Ordinal bytes,
250 const char charBuffer[],
254 DS::getDefaultSerializer(), bytes, charBuffer, count, buffer);
262 template <
typename Ordinal,
typename TayType,
typename ValueSerializer>
263 class SerializerImp {
268 typedef SerializationImp<Ordinal,TayType,ValueSerializer> Imp;
279 typedef ValueSerializer value_serializer_type;
282 static const bool supportsDirectSerialization =
283 Imp::supportsDirectSerialization;
291 Ordinal getSerializerSize()
const {
return sz; }
302 const TayType buffer[])
const {
303 return Imp::fromCountToIndirectBytes(*vs, count, buffer, sz);
307 void serialize (
const Ordinal count,
308 const TayType buffer[],
310 char charBuffer[])
const {
311 Imp::serialize(*vs, count, buffer, bytes, charBuffer, sz);
316 const char charBuffer[])
const {
317 return Imp::fromIndirectBytesToCount(*vs, bytes, charBuffer, sz);
321 void deserialize (
const Ordinal bytes,
322 const char charBuffer[],
324 TayType buffer[])
const {
325 return Imp::deserialize(*vs, bytes, charBuffer, count, buffer, sz);
336 #endif // HAVE_SACADO_TEUCHOSCOMM
338 #endif // SACADO_FAD_SERIALIZATIONTRAITSIMP_HPP