Ice 3.7 C++11 API Reference
|
Go to the documentation of this file.
5 #ifndef ICE_OUTPUT_STREAM_H
6 #define ICE_OUTPUT_STREAM_H
61 const std::pair<const Byte*, const Byte*>& bytes);
67 if(_currentEncaps != &_preAllocatedEncaps)
100 IceInternal::Instance* instance()
const {
return _instance; }
130 void resetEncapsulation();
150 assert(_currentEncaps && _currentEncaps->encoder);
151 _currentEncaps->encoder->startInstance(ValueSlice, data);
159 assert(_currentEncaps && _currentEncaps->encoder);
160 _currentEncaps->encoder->endInstance();
170 assert(_currentEncaps && _currentEncaps->encoder);
171 _currentEncaps->encoder->startInstance(ExceptionSlice, data);
179 assert(_currentEncaps && _currentEncaps->encoder);
180 _currentEncaps->encoder->endInstance();
197 IceInternal::checkSupportedEncoding(encoding);
199 Encaps* oldEncaps = _currentEncaps;
202 _currentEncaps = &_preAllocatedEncaps;
206 _currentEncaps =
new Encaps();
207 _currentEncaps->previous = oldEncaps;
209 _currentEncaps->format = format;
210 _currentEncaps->encoding = encoding;
211 _currentEncaps->start = b.size();
214 write(_currentEncaps->encoding);
222 assert(_currentEncaps);
225 const Int sz =
static_cast<Int>(b.size() - _currentEncaps->start);
226 write(sz, &(*(b.begin() + _currentEncaps->start)));
228 Encaps* oldEncaps = _currentEncaps;
229 _currentEncaps = _currentEncaps->previous;
230 if(oldEncaps == &_preAllocatedEncaps)
246 IceInternal::checkSupportedEncoding(encoding);
260 throwEncapsulationException(__FILE__, __LINE__);
263 Container::size_type position = b.size();
264 resize(position +
static_cast<size_t>(sz));
265 memcpy(&b[position], &v[0],
static_cast<size_t>(sz));
275 return _currentEncaps ? _currentEncaps->encoding : _encoding;
285 void startSlice(
const std::string& typeId,
int compactId,
bool last)
287 assert(_currentEncaps && _currentEncaps->encoder);
288 _currentEncaps->encoder->startSlice(typeId, compactId, last);
296 assert(_currentEncaps && _currentEncaps->encoder);
297 _currentEncaps->encoder->endSlice();
322 write(
static_cast<Byte>(v));
342 *dest =
static_cast<Byte>(v);
366 rewrite(
static_cast<Int>(b.size() - position) - 4, position);
384 Container::size_type position = b.size();
385 resize(position + sz);
386 memcpy(&b[position], &v[0], sz);
394 template<
typename T>
void write(
const T& v)
396 StreamHelper<T, StreamableTraits<T>::helper>::write(
this, v);
411 if(writeOptional(tag, StreamOptionalHelper<T,
412 StreamableTraits<T>::helper,
413 StreamableTraits<T>::fixedLength>::optionalFormat))
415 StreamOptionalHelper<T,
416 StreamableTraits<T>::helper,
417 StreamableTraits<T>::fixedLength>::write(
this, *v);
425 template<
typename T>
void write(
const std::vector<T>& v)
433 write(&v[0], &v[0] + v.size());
442 template<
typename T>
void write(
const T* begin,
const T* end)
444 writeSize(
static_cast<Int>(end - begin));
445 for(
const T* p = begin; p != end; ++p)
451 #ifdef ICE_CPP11_MAPPING
464 template<
typename T,
typename... Te>
void writeAll(
const T& v,
const Te&... ve)
473 template<
size_t I = 0,
typename... Te>
474 typename std::enable_if<I ==
sizeof...(Te),
void>::type
483 template<
size_t I = 0,
typename... Te>
484 typename std::enable_if<I <
sizeof...(Te),
void>::type
485 writeAll(std::tuple<Te...> tuple)
487 write(std::get<I>(tuple));
488 writeAll<I + 1, Te...>(tuple);
497 write(*(tags.begin() + tags.size() - 1), v);
503 template<
typename T,
typename... Te>
506 size_t index = tags.size() -
sizeof...(ve) - 1;
507 write(*(tags.begin() + index), v);
508 writeAll(tags, ve...);
520 bool writeOptional(
Int tag, OptionalFormat format)
522 assert(_currentEncaps);
523 if(_currentEncaps->encoder)
525 return _currentEncaps->encoder->writeOptional(tag, format);
529 return writeOptImpl(tag, format);
555 b.push_back(
static_cast<Byte>(v));
562 void write(
const std::vector<bool>& v);
569 void write(
const bool* begin,
const bool* end);
590 Container::size_type position = b.size();
591 resize(position +
sizeof(
Int));
592 write(v, &b[position]);
603 #ifdef ICE_BIG_ENDIAN
604 const Byte* src =
reinterpret_cast<const Byte*
>(&v) +
sizeof(
Int) - 1;
610 const Byte* src =
reinterpret_cast<const Byte*
>(&v);
670 void write(
const std::string& v,
bool convert =
true)
672 Int sz =
static_cast<Int>(v.size());
673 if(convert && sz > 0)
675 writeConverted(v.data(),
static_cast<size_t>(sz));
682 Container::size_type position = b.size();
683 resize(position +
static_cast<size_t>(sz));
684 memcpy(&b[position], v.data(),
static_cast<size_t>(sz));
696 void write(
const char* vdata,
size_t vsize,
bool convert =
true)
698 Int sz =
static_cast<Int>(vsize);
699 if(convert && sz > 0)
701 writeConverted(vdata, vsize);
708 Container::size_type position = b.size();
709 resize(position +
static_cast<size_t>(sz));
710 memcpy(&b[position], vdata, vsize);
721 void write(
const char* vdata,
bool convert =
true)
723 write(vdata, strlen(vdata), convert);
733 void write(
const std::string* begin,
const std::string* end,
bool convert =
true);
746 void write(
const std::wstring* begin,
const std::wstring* end);
748 #ifdef ICE_CPP11_MAPPING
759 template<typename T, typename ::std::enable_if<::std::is_base_of<ObjectPrx, T>::value>::type* =
nullptr>
760 void write(const ::std::shared_ptr<T>& v)
762 writeProxy(::std::static_pointer_cast<ObjectPrx>(v));
775 template<
typename T>
void write(
const IceInternal::ProxyHandle<T>& v)
781 #ifdef ICE_CPP11_MAPPING // C++11 mapping
786 template<typename T, typename ::std::enable_if<::std::is_base_of<Value, T>::value>::type* =
nullptr>
787 void write(const ::std::shared_ptr<T>& v)
790 _currentEncaps->encoder->write(v);
792 #else // C++98 mapping
797 void write(
const ObjectPtr& v)
800 _currentEncaps->encoder->write(v);
807 template<
typename T>
void write(
const IceInternal::Handle<T>& v)
809 write(ObjectPtr(
upCast(v.get())));
843 write(v, b.begin() + pos);
864 bool writeOptImpl(
Int, OptionalFormat);
872 void writeConverted(
const char*,
size_t);
880 void throwEncapsulationException(
const char*,
int);
886 IceInternal::Instance* _instance;
894 enum SliceType { NoSlice, ValueSlice, ExceptionSlice };
896 typedef std::vector<ValuePtr> ValueList;
902 virtual ~EncapsEncoder();
904 virtual void write(
const ValuePtr&) = 0;
907 virtual void startInstance(SliceType,
const SlicedDataPtr&) = 0;
908 virtual void endInstance() = 0;
909 virtual void startSlice(
const std::string&,
int,
bool) = 0;
910 virtual void endSlice() = 0;
912 virtual bool writeOptional(
Int, OptionalFormat)
917 virtual void writePendingValues()
923 EncapsEncoder(OutputStream* stream, Encaps* encaps) : _stream(stream), _encaps(encaps), _typeIdIndex(0)
927 Int registerTypeId(
const std::string&);
929 OutputStream* _stream;
932 typedef std::map<ValuePtr, Int> PtrToIndexMap;
933 typedef std::map<std::string, Int> TypeIdMap;
936 PtrToIndexMap _marshaledMap;
941 TypeIdMap _typeIdMap;
945 class ICE_API EncapsEncoder10 :
public EncapsEncoder
949 EncapsEncoder10(OutputStream* stream, Encaps* encaps) :
950 EncapsEncoder(stream, encaps), _sliceType(NoSlice), _valueIdIndex(0)
954 virtual void write(
const ValuePtr&);
955 virtual void write(
const UserException&);
957 virtual void startInstance(SliceType,
const SlicedDataPtr&);
958 virtual void endInstance();
959 virtual void startSlice(
const std::string&,
int,
bool);
960 virtual void endSlice();
962 virtual void writePendingValues();
966 Int registerValue(
const ValuePtr&);
969 SliceType _sliceType;
972 Container::size_type _writeSlice;
976 PtrToIndexMap _toBeMarshaledMap;
979 class ICE_API EncapsEncoder11 :
public EncapsEncoder
983 EncapsEncoder11(OutputStream* stream, Encaps* encaps) :
984 EncapsEncoder(stream, encaps), _preAllocatedInstanceData(0), _current(0), _valueIdIndex(1)
988 virtual void write(
const ValuePtr&);
989 virtual void write(
const UserException&);
991 virtual void startInstance(SliceType,
const SlicedDataPtr&);
992 virtual void endInstance();
993 virtual void startSlice(
const std::string&,
int,
bool);
994 virtual void endSlice();
996 virtual bool writeOptional(
Int, OptionalFormat);
1000 void writeSlicedData(
const SlicedDataPtr&);
1001 void writeInstance(
const ValuePtr&);
1005 InstanceData(InstanceData* p) : previous(p), next(0)
1009 previous->next =
this;
1022 SliceType sliceType;
1027 Container::size_type writeSlice;
1028 Container::size_type sliceFlagsPos;
1029 PtrToIndexMap indirectionMap;
1030 ValueList indirectionTable;
1032 InstanceData* previous;
1035 InstanceData _preAllocatedInstanceData;
1036 InstanceData* _current;
1064 Container::size_type start;
1065 EncodingVersion encoding;
1068 EncapsEncoder* encoder;
1079 EncodingVersion _encoding;
1083 Encaps* _currentEncaps;
1087 Encaps _preAllocatedEncaps;
void write(Long v)
Writes a long to the stream.
short Short
The mapping for the Slice short type.
Definition: Config.h:52
void write(Byte v)
Writes a byte to the stream.
Definition: OutputStream.h:537
OutputStream(const CommunicatorPtr &communicator, const EncodingVersion &version)
Constructs a stream using the given communicator and encoding version.
void writeBlob(const Byte *v, Container::size_type sz)
Copies the specified blob of bytes to the stream without modification.
Definition: OutputStream.h:380
void * setClosure(void *p)
Associates closure data with this stream.
size_type startSize()
Writes a placeholder value for the size and returns the starting position of the size value; after wr...
Definition: OutputStream.h:352
void write(const ::std::shared_ptr< T > &v)
Writes a proxy to the stream.
Definition: OutputStream.h:760
void writeAll(const T &v, const Te &... ve)
Writes a list of mandatory data values.
Definition: OutputStream.h:464
void endValue()
Marks the end of a class instance.
Definition: OutputStream.h:157
double Double
The mapping for the Slice double type.
Definition: Config.h:65
void startEncapsulation()
Writes the start of an encapsulation using the default encoding version and class encoding format.
void writeBlob(const std::vector< Byte > &v)
Copies the specified blob of bytes to the stream without modification.
void rewrite(Int v, size_type pos)
Overwrite a 32-bit integer value at the given position in the stream.
Definition: OutputStream.h:841
void endSlice()
Marks the end of a value or exception slice.
Definition: OutputStream.h:294
size_t size_type
Definition: OutputStream.h:31
void write(Short v)
Writes a short to the stream.
void writeSize(Int v)
Writes a size value.
Definition: OutputStream.h:312
#define ICE_ENUM(CLASS, ENUMERATOR)
Definition: Config.h:360
std::experimental::Ice::optional< T > Optional
For compatibility with the Ice C++98 mapping, do not use in new code:
Definition: Optional.h:1100
void write(const Long *begin, const Long *end)
Writes a long sequence to the stream.
float Float
The mapping for the Slice float type.
Definition: Config.h:63
IceUtil::Shared * upCast(::Ice::LocalObject *)
size_type pos()
Obtains the current position of the stream.
Definition: OutputStream.h:830
void write(Int tag, const IceUtil::Optional< T > &v)
Writes an optional data value to the stream.
Definition: OutputStream.h:404
const EncodingVersion & getEncoding() const
Determines the current encoding version.
Definition: OutputStream.h:273
void finished(std::vector< Byte > &v)
Indicates that marshaling is complete.
void writeException(const UserException &v)
Writes an exception to the stream.
#define ICE_API
Definition: Config.h:197
std::enable_if< I==sizeof...(Te), void >::type writeAll(std::tuple< Te... >)
Writes a list of mandatory data values.
Definition: OutputStream.h:475
A version structure for the encoding version.
Definition: Version.h:82
std::pair< const Byte *, const Byte * > finished()
Indicates that marshaling is complete.
void write(const std::vector< T > &v)
Writes a sequence of data values to the stream.
Definition: OutputStream.h:425
CommunicatorPtr initialize(int &argc, const char *argv[], const InitializationData &initData=InitializationData(), int version=30710)
Initializes a new communicator.
unsigned char Byte
The mapping for the Slice byte type.
Definition: Config.h:50
void write(const std::string &v, bool convert=true)
Writes a string to the stream.
Definition: OutputStream.h:670
~OutputStream()
Definition: OutputStream.h:63
void write(const Float *begin, const Float *end)
Writes a float sequence to the stream.
void write(const T &v)
Writes a data value to the stream.
Definition: OutputStream.h:394
void write(Double v)
Writes a double to the stream.
void write(const char *vdata, size_t vsize, bool convert=true)
Writes a string to the stream.
Definition: OutputStream.h:696
void write(const Byte *start, const Byte *end)
Writes a byte sequence to the stream.
void write(const bool *begin, const bool *end)
Writes a byte sequence to the stream.
void swap(OutputStream &other)
Swaps the contents of one stream with another.
void writeEncapsulation(const Byte *v, Int sz)
Copies the marshaled form of an encapsulation to the buffer.
Definition: OutputStream.h:256
void write(const T *begin, const T *end)
Writes a sequence of data values to the stream.
Definition: OutputStream.h:442
void resize(Container::size_type sz)
Resizes the stream to a new size.
Definition: OutputStream.h:138
void write(const Int *begin, const Int *end)
Writes an int sequence to the stream.
void write(const char *vdata, bool convert=true)
Writes a string to the stream.
Definition: OutputStream.h:721
void clear()
Releases any data retained by encapsulations.
void write(const Double *begin, const Double *end)
Writes a double sequence to the stream.
FormatType
Describes the possible formats for classes and exceptions.
Definition: Format.h:21
Interface for output streams used to create a sequence of bytes from Slice types.
Definition: OutputStream.h:28
void endException()
Marks the end of an exception instance.
Definition: OutputStream.h:177
void write(bool v)
Writes a boolean to the stream.
Definition: OutputStream.h:553
void startValue(const SlicedDataPtr &data)
Marks the start of a class instance.
Definition: OutputStream.h:148
OutputStream(const CommunicatorPtr &communicator)
Constructs a stream using the communicator's default encoding version.
void writeEmptyEncapsulation(const EncodingVersion &encoding)
Writes an empty encapsulation using the given encoding version.
Definition: OutputStream.h:244
void writeAll(const T &v)
Writes a list of mandatory data values.
Definition: OutputStream.h:456
void write(Int v, Container::iterator dest)
Overwrites a 32-bit integer value at the given destination in the stream.
Definition: OutputStream.h:601
void setFormat(FormatType format)
Sets the class encoding format.
void * getClosure() const
Obtains the closure data associated with this stream.
long long int Long
The mapping for the Slice long type.
Definition: Config.h:57
void writePendingValues()
Encodes the state of class instances whose insertion was delayed during a previous call to write.
void startSlice(const std::string &typeId, int compactId, bool last)
Writes the start of a value or exception slice.
Definition: OutputStream.h:285
Definition: BuiltinSequences.h:56
OutputStream(const CommunicatorPtr &communicator, const EncodingVersion &version, const std::pair< const Byte *, const Byte * > &bytes)
Constructs a stream using the given communicator and encoding version.
void initialize(const CommunicatorPtr &communicator)
Initializes the stream to use the communicator's default encoding version, class encoding format and ...
Base class of all object proxies.
Definition: Proxy.h:317
void write(const std::string *begin, const std::string *end, bool convert=true)
Writes a string sequence to the stream.
void startException(const SlicedDataPtr &data)
Marks the start of an exception instance.
Definition: OutputStream.h:168
void write(Int v)
Writes an int to the stream.
Definition: OutputStream.h:588
void startEncapsulation(const EncodingVersion &encoding, FormatType format)
Writes the start of an encapsulation using the given encoding version and class encoding format.
Definition: OutputStream.h:195
void writeEnum(Int v, Int maxValue)
Writes an enumerator to the stream.
void write(const std::vector< bool > &v)
Writes a byte sequence to the stream.
void rewriteSize(Int v, Container::iterator dest)
Replaces a size value at the given destination in the stream.
Definition: OutputStream.h:332
void endSize(size_type position)
Updates the size value at the given position to contain a size based on the stream's current position...
Definition: OutputStream.h:364
void endEncapsulation()
Ends the current encapsulation.
Definition: OutputStream.h:220
void write(Float v)
Writes a float to the stream.
void write(const Short *begin, const Short *end)
Writes a short sequence to the stream.
void write(const std::wstring *begin, const std::wstring *end)
Writes a wide string sequence to the stream.
void initialize(const CommunicatorPtr &communicator, const EncodingVersion &version)
Initializes the stream to use the given encoding version and the communicator's default class encodin...
int Int
The mapping for the Slice int type.
Definition: Config.h:54
OutputStream()
Constructs an OutputStream using the latest encoding version, the default format for class encoding,...
void writeProxy(const ::std::shared_ptr< ObjectPrx > &v)
Writes a proxy to the stream.
void write(const std::wstring &v)
Writes a wide string to the stream.
Base class for all Ice user exceptions.
Definition: Exception.h:68