Ice 3.7 C++98 API Reference
Loading...
Searching...
No Matches
StreamHelpers.h
Go to the documentation of this file.
1//
2// Copyright (c) ZeroC, Inc. All rights reserved.
3//
4
5#ifndef ICE_STREAM_HELPERS_H
6#define ICE_STREAM_HELPERS_H
7
8#include <Ice/ObjectF.h>
9
10#ifndef ICE_CPP11_MAPPING
11# include <IceUtil/ScopedArray.h>
12# include <IceUtil/Iterator.h>
13#endif
14
15namespace Ice
16{
17
19
23typedef int StreamHelperCategory;
24
26const StreamHelperCategory StreamHelperCategoryUnknown = 0;
28const StreamHelperCategory StreamHelperCategoryBuiltin = 1;
30const StreamHelperCategory StreamHelperCategoryStruct = 2;
32const StreamHelperCategory StreamHelperCategoryStructClass = 3;
34const StreamHelperCategory StreamHelperCategoryEnum = 4;
36const StreamHelperCategory StreamHelperCategorySequence = 5;
38const StreamHelperCategory StreamHelperCategoryDictionary = 6;
40const StreamHelperCategory StreamHelperCategoryProxy = 7;
42const StreamHelperCategory StreamHelperCategoryClass = 8;
44const StreamHelperCategory StreamHelperCategoryUserException = 9;
45
54#ifdef ICE_CPP11_MAPPING
55enum class OptionalFormat : unsigned char
56{
58 F1 = 0,
60 F2 = 1,
62 F4 = 2,
64 F8 = 3,
66 Size = 4,
71 VSize = 5,
73 FSize = 6,
75 Class = 7
76};
77#else
78enum OptionalFormat
79{
81 OptionalFormatF1 = 0,
83 OptionalFormatF2 = 1,
85 OptionalFormatF4 = 2,
87 OptionalFormatF8 = 3,
89 OptionalFormatSize = 4,
94 OptionalFormatVSize = 5,
96 OptionalFormatFSize = 6,
98 OptionalFormatClass = 7
99};
100#endif
101
107template<typename T>
108struct IsContainer
109{
110 template<typename C>
111 static char test(typename C::iterator*);
112
113 template<typename C>
114 static long test(...);
115
116 static const bool value = sizeof(test<T>(0)) == sizeof(char);
117};
118
124template<typename T>
125struct IsMap
126{
127 template<typename C>
128 static char test(typename C::mapped_type*);
129
130 template<typename C>
131 static long test(...);
132
133 static const bool value = IsContainer<T>::value && sizeof(test<T>(0)) == sizeof(char);
134};
135
136#ifdef ICE_CPP11_MAPPING
137
142template<typename T, typename Enabler = void>
143struct StreamableTraits
144{
145 static const StreamHelperCategory helper = StreamHelperCategoryUnknown;
146
147 //
148 // When extracting a sequence<T> from a stream, we can ensure the
149 // stream has at least StreamableTraits<T>::minWireSize * size bytes
150 // For containers, the minWireSize is 1 (just 1 byte for an empty container).
151 //
152 //static const int minWireSize = 1;
153
154 //
155 // Is this type encoded on a fixed number of bytes?
156 // Used only for marshaling/unmarshaling optional data members and parameters.
157 //
158 //static const bool fixedLength = false;
159};
160
165template<typename T>
166struct StreamableTraits<T, typename ::std::enable_if<IsMap<T>::value || IsContainer<T>::value>::type>
167{
168 static const StreamHelperCategory helper = IsMap<T>::value ? StreamHelperCategoryDictionary : StreamHelperCategorySequence;
169 static const int minWireSize = 1;
170 static const bool fixedLength = false;
171};
172
177template<typename T>
178struct StreamableTraits<T, typename ::std::enable_if<::std::is_base_of<::Ice::UserException, T>::value>::type>
179{
180 static const StreamHelperCategory helper = StreamHelperCategoryUserException;
181
182 //
183 // There is no sequence/dictionary of UserException (so no need for minWireSize)
184 // and no optional UserException (so no need for fixedLength)
185 //
186};
187
192template<typename T>
193struct StreamableTraits<std::pair<T*, T*>>
194{
195 static const StreamHelperCategory helper = StreamHelperCategorySequence;
196 static const int minWireSize = 1;
197 static const bool fixedLength = false;
198};
199
200#else
201
207template<typename T, typename Enabler = void>
208struct StreamableTraits
209{
210 static const StreamHelperCategory helper = IsMap<T>::value ? StreamHelperCategoryDictionary :
211 (IsContainer<T>::value ? StreamHelperCategorySequence : StreamHelperCategoryUnknown);
212
218 static const int minWireSize = 1;
219
224 static const bool fixedLength = false;
225};
226
231template<>
232struct StreamableTraits<UserException>
233{
234 static const StreamHelperCategory helper = StreamHelperCategoryUserException;
235
236 //
237 // There is no sequence/dictionary of UserException (so no need for minWireSize)
238 // and no optional UserException (so no need for fixedLength)
239 //
240};
241
247template<typename T, typename U>
248struct StreamableTraits< ::std::pair<T, U> >
249{
250 static const StreamHelperCategory helper = StreamHelperCategorySequence;
251 static const int minWireSize = 1;
252 static const bool fixedLength = false;
253};
254#endif
255
261template<>
262struct StreamableTraits<bool>
263{
264 static const StreamHelperCategory helper = StreamHelperCategoryBuiltin;
265 static const int minWireSize = 1;
266 static const bool fixedLength = true;
267};
268
274template<>
275struct StreamableTraits<Byte>
276{
277 static const StreamHelperCategory helper = StreamHelperCategoryBuiltin;
278 static const int minWireSize = 1;
279 static const bool fixedLength = true;
280};
281
287template<>
288struct StreamableTraits<Short>
289{
290 static const StreamHelperCategory helper = StreamHelperCategoryBuiltin;
291 static const int minWireSize = 2;
292 static const bool fixedLength = true;
293};
294
300template<>
301struct StreamableTraits<Int>
302{
303 static const StreamHelperCategory helper = StreamHelperCategoryBuiltin;
304 static const int minWireSize = 4;
305 static const bool fixedLength = true;
306};
307
313template<>
314struct StreamableTraits<Long>
315{
316 static const StreamHelperCategory helper = StreamHelperCategoryBuiltin;
317 static const int minWireSize = 8;
318 static const bool fixedLength = true;
319};
320
326template<>
327struct StreamableTraits<Float>
328{
329 static const StreamHelperCategory helper = StreamHelperCategoryBuiltin;
330 static const int minWireSize = 4;
331 static const bool fixedLength = true;
332};
333
339template<>
340struct StreamableTraits<Double>
341{
342 static const StreamHelperCategory helper = StreamHelperCategoryBuiltin;
343 static const int minWireSize = 8;
344 static const bool fixedLength = true;
345};
346
352template<>
353struct StreamableTraits< ::std::string>
354{
355 static const StreamHelperCategory helper = StreamHelperCategoryBuiltin;
356 static const int minWireSize = 1;
357 static const bool fixedLength = false;
358};
359
365template<>
366struct StreamableTraits< ::std::wstring>
367{
368 static const StreamHelperCategory helper = StreamHelperCategoryBuiltin;
369 static const int minWireSize = 1;
370 static const bool fixedLength = false;
371};
372
377template<>
378struct StreamableTraits< ::std::vector<bool> >
379{
380 static const StreamHelperCategory helper = StreamHelperCategoryBuiltin;
381 static const int minWireSize = 1;
382 static const bool fixedLength = false;
383};
384
389#ifdef ICE_CPP11_MAPPING
390template<typename T>
391struct StreamableTraits<::std::shared_ptr<T>, typename ::std::enable_if<::std::is_base_of<::Ice::ObjectPrx, T>::value>::type>
392{
393 static const StreamHelperCategory helper = StreamHelperCategoryProxy;
394 static const int minWireSize = 2;
395 static const bool fixedLength = false;
396};
397#else
398template<typename T>
399struct StreamableTraits< ::IceInternal::ProxyHandle<T> >
400{
401 static const StreamHelperCategory helper = StreamHelperCategoryProxy;
402 static const int minWireSize = 2;
403 static const bool fixedLength = false;
404};
405#endif
406
411#ifdef ICE_CPP11_MAPPING
412template<typename T>
413struct StreamableTraits<::std::shared_ptr<T>, typename ::std::enable_if<::std::is_base_of<::Ice::Value, T>::value>::type>
414{
415 static const StreamHelperCategory helper = StreamHelperCategoryClass;
416 static const int minWireSize = 1;
417 static const bool fixedLength = false;
418};
419#else
420template<typename T>
421struct StreamableTraits< ::IceInternal::Handle<T> >
422{
423 static const StreamHelperCategory helper = StreamHelperCategoryClass;
424 static const int minWireSize = 1;
425 static const bool fixedLength = false;
426};
427#endif
428
429//
430// StreamHelper templates used by streams to read and write data.
431//
432
434template<typename T, StreamHelperCategory st>
435struct StreamHelper;
436
441template<typename T>
442struct StreamHelper<T, StreamHelperCategoryBuiltin>
443{
444 template<class S> static inline void
445 write(S* stream, const T& v)
446 {
447 stream->write(v);
448 }
449
450 template<class S> static inline void
451 read(S* stream, T& v)
452 {
453 stream->read(v);
454 }
455};
456
457//
458// "helpers" for the StreamHelper<T, StreamHelperCategoryStruct[Class]> below
459// slice2cpp generates specializations as needed
460//
461
466template<typename T, typename S>
467struct StreamWriter
468{
469#ifdef ICE_CPP11_MAPPING
470 static inline void write(S* stream, const T& v)
471 {
472 stream->writeAll(v.ice_tuple());
473 }
474#else
475 static inline void write(S*, const T&)
476 {
477 // Default is to write nothing for C++98
478 }
479#endif
480};
481
486template<typename T, typename S>
487struct StreamReader
488{
489 static inline void read(S*, T&)
490 {
491 // Default is to read nothing
492 }
493};
494
499template<typename T>
500struct StreamHelper<T, StreamHelperCategoryStruct>
501{
502 template<class S> static inline void
503 write(S* stream, const T& v)
504 {
505 StreamWriter<T, S>::write(stream, v);
506 }
507
508 template<class S> static inline void
509 read(S* stream, T& v)
510 {
511 StreamReader<T, S>::read(stream, v);
512 }
513};
514
519template<typename T>
520struct StreamHelper<T, StreamHelperCategoryStructClass>
521{
522 template<class S> static inline void
523 write(S* stream, const T& v)
524 {
525 StreamWriter<T, S>::write(stream, v);
526 }
527
528 template<class S> static inline void
529 read(S* stream, T& v)
530 {
531 v = new typename T::element_type;
532 StreamReader<T, S>::read(stream, v);
533 }
534};
535
540template<typename T>
541struct StreamHelper<T, StreamHelperCategoryEnum>
542{
543 template<class S> static inline void
544 write(S* stream, const T& v)
545 {
546 if(static_cast<Int>(v) < StreamableTraits<T>::minValue || static_cast<Int>(v) > StreamableTraits<T>::maxValue)
547 {
548 IceInternal::Ex::throwMarshalException(__FILE__, __LINE__, "enumerator out of range");
549 }
550 stream->writeEnum(static_cast<Int>(v), StreamableTraits<T>::maxValue);
551 }
552
553 template<class S> static inline void
554 read(S* stream, T& v)
555 {
556 Int value = stream->readEnum(StreamableTraits<T>::maxValue);
557 if(value < StreamableTraits<T>::minValue || value > StreamableTraits<T>::maxValue)
558 {
559 IceInternal::Ex::throwMarshalException(__FILE__, __LINE__, "enumerator out of range");
560 }
561 v = static_cast<T>(value);
562 }
563};
564
569template<typename T>
570struct StreamHelper<T, StreamHelperCategorySequence>
571{
572 template<class S> static inline void
573 write(S* stream, const T& v)
574 {
575 stream->writeSize(static_cast<Int>(v.size()));
576 for(typename T::const_iterator p = v.begin(); p != v.end(); ++p)
577 {
578 stream->write(*p);
579 }
580 }
581
582 template<class S> static inline void
583 read(S* stream, T& v)
584 {
585 Int sz = stream->readAndCheckSeqSize(StreamableTraits<typename T::value_type>::minWireSize);
586 T(static_cast<size_t>(sz)).swap(v);
587 for(typename T::iterator p = v.begin(); p != v.end(); ++p)
588 {
589 stream->read(*p);
590 }
591 }
592};
593
598template<typename T>
599struct StreamHelper<std::pair<const T*, const T*>, StreamHelperCategorySequence>
600{
601 template<class S> static inline void
602 write(S* stream, const std::pair<const T*, const T*>& v)
603 {
604 stream->write(v.first, v.second);
605 }
606
607 template<class S> static inline void
608 read(S* stream, std::pair<const T*, const T*>& v)
609 {
610 stream->read(v);
611 }
612};
613
614#ifndef ICE_CPP11_MAPPING
615
620template<typename T>
621struct StreamHelper<std::pair<T, T>, StreamHelperCategorySequence>
622{
623 template<class S> static inline void
624 write(S* stream, const std::pair<T, T>& v)
625 {
626 stream->writeSize(static_cast<Int>(IceUtilInternal::distance(v.first, v.second)));
627 for(T p = v.first; p != v.second; ++p)
628 {
629 stream->write(*p);
630 }
631 }
632
633 template<class S> static inline void
634 read(S* stream, std::pair<T, T>& v)
635 {
636 stream->read(v);
637 }
638};
639
644template<>
645struct StreamHelper<std::pair< ::std::vector<bool>::const_iterator,
646 ::std::vector<bool>::const_iterator>, StreamHelperCategorySequence>
647{
648 template<class S> static inline void
649 write(S* stream, const std::pair< ::std::vector<bool>::const_iterator,
650 ::std::vector<bool>::const_iterator>& v)
651 {
652 stream->writeSize(static_cast<Int>(IceUtilInternal::distance(v.first, v.second)));
653 for(::std::vector<bool>::const_iterator p = v.first; p != v.second; ++p)
654 {
655 stream->write(static_cast<bool>(*p));
656 }
657 }
658};
659
664template<typename T>
665struct StreamHelper<std::pair<IceUtil::ScopedArray<T>, std::pair<const T*, const T*> >, StreamHelperCategorySequence>
666{
667 template<class S> static inline void
668 read(S* stream, std::pair<IceUtil::ScopedArray<T>, std::pair<const T*, const T*> >& v)
669 {
670 stream->read(v.second, v.first);
671 }
672
673 // no write: only used for unmarshaling
674};
675#endif
676
681template<typename T>
682struct StreamHelper<T, StreamHelperCategoryDictionary>
683{
684 template<class S> static inline void
685 write(S* stream, const T& v)
686 {
687 stream->writeSize(static_cast<Int>(v.size()));
688 for(typename T::const_iterator p = v.begin(); p != v.end(); ++p)
689 {
690 stream->write(p->first);
691 stream->write(p->second);
692 }
693 }
694
695 template<class S> static inline void
696 read(S* stream, T& v)
697 {
698 Int sz = stream->readSize();
699 v.clear();
700 while(sz--)
701 {
702 typename T::value_type p;
703 stream->read(const_cast<typename T::key_type&>(p.first));
704 typename T::iterator i = v.insert(v.end(), p);
705 stream->read(i->second);
706 }
707 }
708};
709
714template<typename T>
715struct StreamHelper<T, StreamHelperCategoryUserException>
716{
717 template<class S> static inline void
718 write(S* stream, const T& v)
719 {
720 stream->writeException(v);
721 }
722
723 // no read: only used for marshaling
724};
725
730template<typename T>
731struct StreamHelper<T, StreamHelperCategoryProxy>
732{
733 template<class S> static inline void
734 write(S* stream, const T& v)
735 {
736 stream->write(v);
737 }
738
739 template<class S> static inline void
740 read(S* stream, T& v)
741 {
742 stream->read(v);
743 }
744};
745
750template<typename T>
751struct StreamHelper<T, StreamHelperCategoryClass>
752{
753 template<class S> static inline void
754 write(S* stream, const T& v)
755 {
756 stream->write(v);
757 }
758
759 template<class S> static inline void
760 read(S* stream, T& v)
761 {
762 stream->read(v);
763 }
764};
765
766//
767// Helpers to read/write optional attributes or members.
768//
769
770//
771// Extract / compute the optionalFormat
772// This is used _only_ for the base StreamOptionalHelper below
773// /!\ Do not use in StreamOptionalHelper specializations, and do
774// not provide specialization not handled by the base StreamOptionalHelper
775//
780template<StreamHelperCategory st, int minWireSize, bool fixedLength>
781struct GetOptionalFormat;
782
787template<>
788struct GetOptionalFormat<StreamHelperCategoryBuiltin, 1, true>
789{
790 static const OptionalFormat value = ICE_SCOPED_ENUM(OptionalFormat, F1);
791};
792
797template<>
798struct GetOptionalFormat<StreamHelperCategoryBuiltin, 2, true>
799{
800 static const OptionalFormat value = ICE_SCOPED_ENUM(OptionalFormat, F2);
801};
802
807template<>
808struct GetOptionalFormat<StreamHelperCategoryBuiltin, 4, true>
809{
810 static const OptionalFormat value = ICE_SCOPED_ENUM(OptionalFormat, F4);
811};
812
817template<>
818struct GetOptionalFormat<StreamHelperCategoryBuiltin, 8, true>
819{
820 static const OptionalFormat value = ICE_SCOPED_ENUM(OptionalFormat, F8);
821};
822
827template<>
828struct GetOptionalFormat<StreamHelperCategoryBuiltin, 1, false>
829{
830 static const OptionalFormat value = ICE_SCOPED_ENUM(OptionalFormat, VSize);
831};
832
837template<>
838struct GetOptionalFormat<StreamHelperCategoryClass, 1, false>
839{
840 static const OptionalFormat value = ICE_SCOPED_ENUM(OptionalFormat, Class);
841};
842
847template<int minWireSize>
848struct GetOptionalFormat<StreamHelperCategoryEnum, minWireSize, false>
849{
850 static const OptionalFormat value = ICE_SCOPED_ENUM(OptionalFormat, Size);
851};
852
857template<typename T, StreamHelperCategory st, bool fixedLength>
858struct StreamOptionalHelper
859{
860 typedef StreamableTraits<T> Traits;
861
862 // If this optionalFormat fails to compile, you must either define your specialization
863 // for GetOptionalFormat (in which case the optional data will be marshaled/unmarshaled
864 // with straight calls to write/read on the stream), or define your own
865 // StreamOptionalHelper specialization (which gives you more control over marshaling)
866 //
867 static const OptionalFormat optionalFormat = GetOptionalFormat<st, Traits::minWireSize, fixedLength>::value;
868
869 template<class S> static inline void
870 write(S* stream, const T& v)
871 {
872 stream->write(v);
873 }
874
875 template<class S> static inline void
876 read(S* stream, T& v)
877 {
878 stream->read(v);
879 }
880};
881
886template<typename T>
887struct StreamOptionalHelper<T, StreamHelperCategoryStruct, true>
888{
889 static const OptionalFormat optionalFormat = ICE_SCOPED_ENUM(OptionalFormat, VSize);
890
891 template<class S> static inline void
892 write(S* stream, const T& v)
893 {
894 stream->writeSize(StreamableTraits<T>::minWireSize);
895 stream->write(v);
896 }
897
898 template<class S> static inline void
899 read(S* stream, T& v)
900 {
901 stream->skipSize();
902 stream->read(v);
903 }
904};
905
910template<typename T>
911struct StreamOptionalHelper<T, StreamHelperCategoryStruct, false>
912{
913 static const OptionalFormat optionalFormat = ICE_SCOPED_ENUM(OptionalFormat, FSize);
914
915 template<class S> static inline void
916 write(S* stream, const T& v)
917 {
918 typename S::size_type pos = stream->startSize();
919 stream->write(v);
920 stream->endSize(pos);
921 }
922
923 template<class S> static inline void
924 read(S* stream, T& v)
925 {
926 stream->skip(4);
927 stream->read(v);
928 }
929};
930
935template<typename T, bool fixedLength>
936struct StreamOptionalHelper<T, StreamHelperCategoryStructClass, fixedLength> : StreamOptionalHelper<T, StreamHelperCategoryStruct, fixedLength>
937{
938};
939
944template<typename T>
945struct StreamOptionalHelper<T, StreamHelperCategoryProxy, false> : StreamOptionalHelper<T, StreamHelperCategoryStruct, false>
946{
947};
948
953template<typename T, bool fixedLength, int sz>
954struct StreamOptionalContainerHelper;
955
963template<typename T, int sz>
964struct StreamOptionalContainerHelper<T, false, sz>
965{
966 static const OptionalFormat optionalFormat = ICE_SCOPED_ENUM(OptionalFormat, FSize);
967
968 template<class S> static inline void
969 write(S* stream, const T& v, Int)
970 {
971 StreamOptionalHelper<T, StreamHelperCategoryStruct, false>::write(stream, v);
972 }
973
974 template<class S> static inline void
975 read(S* stream, T& v)
976 {
977 StreamOptionalHelper<T, StreamHelperCategoryStruct, false>::read(stream, v);
978 }
979};
980
987template<typename T, int sz>
988struct StreamOptionalContainerHelper<T, true, sz>
989{
990 static const OptionalFormat optionalFormat = ICE_SCOPED_ENUM(OptionalFormat, VSize);
991
992 template<class S> static inline void
993 write(S* stream, const T& v, Int n)
994 {
995 //
996 // The container size is the number of elements * the size of
997 // an element and the size-encoded number of elements (1 or
998 // 5 depending on the number of elements).
999 //
1000 stream->writeSize(sz * n + (n < 255 ? 1 : 5));
1001 stream->write(v);
1002 }
1003
1004 template<class S> static inline void
1005 read(S* stream, T& v)
1006 {
1007 stream->skipSize();
1008 stream->read(v);
1009 }
1010};
1011
1019template<typename T>
1020struct StreamOptionalContainerHelper<T, true, 1>
1021{
1022 static const OptionalFormat optionalFormat = ICE_SCOPED_ENUM(OptionalFormat, VSize);
1023
1024 template<class S> static inline void
1025 write(S* stream, const T& v, Int)
1026 {
1027 stream->write(v);
1028 }
1029
1030 template<class S> static inline void
1031 read(S* stream, T& v)
1032 {
1033 stream->read(v);
1034 }
1035};
1036
1042template<typename T>
1043struct StreamOptionalHelper<T, StreamHelperCategorySequence, false>
1044{
1045 typedef typename T::value_type E;
1046 static const int size = StreamableTraits<E>::minWireSize;
1047 static const bool fixedLength = StreamableTraits<E>::fixedLength;
1048
1049 // The optional type of a sequence depends on whether or not elements are fixed
1050 // or variable size elements and their size.
1051 static const OptionalFormat optionalFormat = StreamOptionalContainerHelper<T, fixedLength, size>::optionalFormat;
1052
1053 template<class S> static inline void
1054 write(S* stream, const T& v)
1055 {
1056 StreamOptionalContainerHelper<T, fixedLength, size>::write(stream, v, static_cast<Int>(v.size()));
1057 }
1058
1059 template<class S> static inline void
1060 read(S* stream, T& v)
1061 {
1062 StreamOptionalContainerHelper<T, fixedLength, size>::read(stream, v);
1063 }
1064};
1065
1071template<typename T>
1072struct StreamOptionalHelper<std::pair<const T*, const T*>, StreamHelperCategorySequence, false>
1073{
1074 typedef std::pair<const T*, const T*> P;
1075 static const int size = StreamableTraits<T>::minWireSize;
1076 static const bool fixedLength = StreamableTraits<T>::fixedLength;
1077
1078 // The optional type of a sequence depends on whether or not elements are fixed
1079 // or variable size elements and their size.
1080 static const OptionalFormat optionalFormat = StreamOptionalContainerHelper<P, fixedLength, size>::optionalFormat;
1081
1082 template<class S> static inline void
1083 write(S* stream, const P& v)
1084 {
1085 Int n = static_cast<Int>(v.second - v.first);
1086 StreamOptionalContainerHelper<P, fixedLength, size>::write(stream, v, n);
1087 }
1088
1089 template<class S> static inline void
1090 read(S* stream, P& v)
1091 {
1092 StreamOptionalContainerHelper<P, fixedLength, size>::read(stream, v);
1093 }
1094};
1095
1096#ifndef ICE_CPP11_MAPPING
1097
1103template<typename T>
1104struct StreamOptionalHelper<std::pair<T, T>, StreamHelperCategorySequence, false>
1105{
1106 typedef std::pair<T, T> P;
1107 static const int size = StreamableTraits<typename T::value_type>::minWireSize;
1108 static const bool fixedLength = StreamableTraits<typename T::value_type>::fixedLength;
1109
1110 // The optional type of a sequence depends on whether or not elements are fixed
1111 // or variable size elements and their size.
1112 static const OptionalFormat optionalFormat = StreamOptionalContainerHelper<P, fixedLength, size>::optionalFormat;
1113
1114 template<class S> static inline void
1115 write(S* stream, const P& v)
1116 {
1117 Int n = static_cast<Int>(v.second - v.first);
1118 StreamOptionalContainerHelper<P, fixedLength, size>::write(stream, v, n);
1119 }
1120
1121 template<class S> static inline void
1122 read(S* stream, P& v)
1123 {
1124 StreamOptionalContainerHelper<P, fixedLength, size>::read(stream, v);
1125 }
1126};
1127
1133template<typename T>
1134struct StreamOptionalHelper<std::pair<IceUtil::ScopedArray<T>, std::pair<const T*, const T*> >,
1135 StreamHelperCategorySequence, false>
1136{
1137 typedef std::pair<IceUtil::ScopedArray<T>, std::pair<const T*, const T*> > P;
1138 static const int size = StreamableTraits<T>::minWireSize;
1139 static const bool fixedLength = StreamableTraits<T>::fixedLength;
1140
1141 // The optional type of a sequence depends on whether or not elements are fixed
1142 // or variable size elements and their size.
1143 static const OptionalFormat optionalFormat = StreamOptionalContainerHelper<P, fixedLength, size>::optionalFormat;
1144
1145 template<class S> static inline void
1146 read(S* stream, P& v)
1147 {
1148 StreamOptionalContainerHelper<P, fixedLength, size>::read(stream, v);
1149 }
1150
1151 // no write: only used for unmarshaling
1152};
1153#endif
1154
1160template<typename T>
1161struct StreamOptionalHelper<T, StreamHelperCategoryDictionary, false>
1162{
1163 typedef typename T::key_type K;
1164 typedef typename T::mapped_type V;
1165
1166 static const int size = StreamableTraits<K>::minWireSize + StreamableTraits<V>::minWireSize;
1167 static const bool fixedLength = StreamableTraits<K>::fixedLength && StreamableTraits<V>::fixedLength;
1168
1169 // The optional type of a dictionary depends on whether or not elements are fixed
1170 // or variable size elements.
1171 static const OptionalFormat optionalFormat = StreamOptionalContainerHelper<T, fixedLength, size>::optionalFormat;
1172
1173 template<class S> static inline void
1174 write(S* stream, const T& v)
1175 {
1176 StreamOptionalContainerHelper<T, fixedLength, size>::write(stream, v, static_cast<Int>(v.size()));
1177 }
1178
1179 template<class S> static inline void
1180 read(S* stream, T& v)
1181 {
1182 StreamOptionalContainerHelper<T, fixedLength, size>::read(stream, v);
1183 }
1184};
1185
1187
1188}
1189
1190#endif
#define ICE_SCOPED_ENUM(CLASS, ENUMERATOR)
Definition Config.h:379
Base class for all Ice user exceptions.
Definition Exception.h:68
Definition BuiltinSequences.h:113
int Int
The mapping for the Slice int type.
Definition Config.h:54
float Float
The mapping for the Slice float type.
Definition Config.h:63
IceUtil::Int64 Long
The mapping for the Slice long type.
Definition Config.h:60
double Double
The mapping for the Slice double type.
Definition Config.h:65
short Short
The mapping for the Slice short type.
Definition Config.h:52
unsigned char Byte
The mapping for the Slice byte type.
Definition Config.h:50