Ice 3.7 C++11 API Reference
|
Go to the documentation of this file.
5 #ifndef ICE_INPUT_STREAM_H
6 #define ICE_INPUT_STREAM_H
28 template<
typename T>
inline void
29 patchHandle(
void* addr,
const ValuePtr& v)
31 #ifdef ICE_CPP11_MAPPING
32 ::std::shared_ptr<T>* handle =
static_cast<::std::shared_ptr<T>*
>(addr);
33 *handle = ::std::dynamic_pointer_cast<T>(v);
36 IceInternal::Ex::throwUOE(T::ice_staticId(), v);
39 IceInternal::Handle<T>* p =
static_cast<IceInternal::Handle<T>*
>(addr);
40 _icePatchObjectPtr(*p, v);
60 typedef void (*PatchFunc)(
void* addr,
const ValuePtr& v);
86 InputStream(
const std::pair<const Byte*, const Byte*>& bytes);
103 InputStream(
const CommunicatorPtr& communicator,
const std::vector<Byte>& bytes);
110 InputStream(
const CommunicatorPtr& communicator,
const std::pair<const Byte*, const Byte*>& bytes);
113 InputStream(
const CommunicatorPtr& communicator, IceInternal::Buffer&,
bool =
false);
171 const std::pair<const Byte*, const Byte*>& bytes);
181 if(_currentEncaps != &_preAllocatedEncaps)
186 #ifdef ICE_CPP11_MAPPING
188 for(
auto d: _deleters)
220 IceInternal::Instance* instance()
const {
return _instance; }
248 #ifdef ICE_CPP11_MAPPING
254 #ifndef ICE_CPP11_MAPPING
261 void setCollectObjects(
bool b);
310 void resetEncapsulation();
329 assert(_currentEncaps && _currentEncaps->decoder);
330 _currentEncaps->decoder->startInstance(ValueSlice);
342 assert(_currentEncaps && _currentEncaps->decoder);
343 return _currentEncaps->decoder->endInstance(preserve);
351 assert(_currentEncaps && _currentEncaps->decoder);
352 _currentEncaps->decoder->startInstance(ExceptionSlice);
364 assert(_currentEncaps && _currentEncaps->decoder);
365 return _currentEncaps->decoder->endInstance(preserve);
375 Encaps* oldEncaps = _currentEncaps;
378 _currentEncaps = &_preAllocatedEncaps;
382 _currentEncaps =
new Encaps();
383 _currentEncaps->previous = oldEncaps;
385 _currentEncaps->start =
static_cast<size_t>(i - b.begin());
398 throwUnmarshalOutOfBoundsException(__FILE__, __LINE__);
400 if(i -
sizeof(
Int) + sz > b.end())
402 throwUnmarshalOutOfBoundsException(__FILE__, __LINE__);
404 _currentEncaps->sz = sz;
406 read(_currentEncaps->encoding);
407 IceInternal::checkSupportedEncoding(_currentEncaps->encoding);
409 return _currentEncaps->encoding;
417 assert(_currentEncaps);
422 if(i != b.begin() + _currentEncaps->start + _currentEncaps->sz)
424 throwEncapsulationException(__FILE__, __LINE__);
427 else if(i != b.begin() + _currentEncaps->start + _currentEncaps->sz)
429 if(i + 1 != b.begin() + _currentEncaps->start + _currentEncaps->sz)
431 throwEncapsulationException(__FILE__, __LINE__);
443 Encaps* oldEncaps = _currentEncaps;
444 _currentEncaps = _currentEncaps->previous;
445 if(oldEncaps == &_preAllocatedEncaps)
466 throwEncapsulationException(__FILE__, __LINE__);
468 if(i -
sizeof(
Ice::Int) + sz > b.end())
470 throwUnmarshalOutOfBoundsException(__FILE__, __LINE__);
474 IceInternal::checkSupportedEncoding(encoding);
480 throwEncapsulationException(__FILE__, __LINE__);
487 i +=
static_cast<size_t>(sz) -
sizeof(
Ice::Int) - 2;
506 throwEncapsulationException(__FILE__, __LINE__);
508 if(i -
sizeof(
Int) + sz > b.end())
510 throwUnmarshalOutOfBoundsException(__FILE__, __LINE__);
514 i +=
static_cast<size_t>(sz) -
sizeof(
Int) - 2;
525 return _currentEncaps ? _currentEncaps->encoding : _encoding;
549 assert(_currentEncaps && _currentEncaps->decoder);
550 return _currentEncaps->decoder->startSlice();
558 assert(_currentEncaps && _currentEncaps->decoder);
559 _currentEncaps->decoder->endSlice();
567 assert(_currentEncaps && _currentEncaps->decoder);
568 _currentEncaps->decoder->skipSlice();
587 unsigned char val =
static_cast<unsigned char>(byte);
594 throwUnmarshalOutOfBoundsException(__FILE__, __LINE__);
600 return static_cast<Int>(
static_cast<unsigned char>(byte));
631 if(
static_cast<Container::size_type
>(b.end() - i) < sz)
633 throwUnmarshalOutOfBoundsException(__FILE__, __LINE__);
647 template<
typename T>
void read(T& v)
649 StreamHelper<T, StreamableTraits<T>::helper>::read(
this, v);
659 if(readOptional(tag, StreamOptionalHelper<T,
660 StreamableTraits<T>::helper,
661 StreamableTraits<T>::fixedLength>::optionalFormat))
663 #ifdef ICE_CPP11_MAPPING
668 StreamOptionalHelper<T,
669 StreamableTraits<T>::helper,
670 StreamableTraits<T>::fixedLength>::read(
this, *v);
678 #ifdef ICE_CPP11_MAPPING
684 template<
typename T>
void read(std::pair<const T*, const T*>& v)
686 auto holder =
new std::vector<T>;
687 _deleters.push_back([holder] {
delete holder; });
689 if(holder->size() > 0)
691 v.first = holder->data();
692 v.second = holder->data() + holder->size();
712 template<
typename T,
typename... Te>
void readAll(T& v, Te&... ve)
724 read(*(tags.begin() + tags.size() - 1), v);
730 template<
typename T,
typename... Te>
733 size_t index = tags.size() -
sizeof...(ve) - 1;
734 read(*(tags.begin() + index), v);
735 readAll(tags, ve...);
749 assert(_currentEncaps);
750 if(_currentEncaps->decoder)
752 return _currentEncaps->decoder->readOptional(tag, expectedFormat);
756 return readOptImpl(tag, expectedFormat);
768 throwUnmarshalOutOfBoundsException(__FILE__, __LINE__);
777 void read(std::vector<Byte>& v);
784 void read(std::pair<const Byte*, const Byte*>& v);
786 #ifndef ICE_CPP11_MAPPING
793 void read(std::pair<const Byte*, const Byte*>& v, ::IceUtil::ScopedArray<Byte>& arr)
808 throwUnmarshalOutOfBoundsException(__FILE__, __LINE__);
817 void read(std::vector<bool>& v);
819 #ifdef ICE_CPP11_MAPPING
825 void read(std::pair<const bool*, const bool*>& v);
833 void read(std::pair<const bool*, const bool*>& v, ::IceUtil::ScopedArray<bool>& arr);
846 void read(std::vector<Short>& v);
848 #ifdef ICE_CPP11_MAPPING
853 void read(std::pair<const short*, const short*>& v);
860 void read(std::pair<const Short*, const Short*>& v, ::IceUtil::ScopedArray<Short>& arr);
869 if(b.end() - i <
static_cast<int>(
sizeof(
Int)))
871 throwUnmarshalOutOfBoundsException(__FILE__, __LINE__);
873 const Byte* src = &(*i);
875 #ifdef ICE_BIG_ENDIAN
876 Byte* dest =
reinterpret_cast<Byte*
>(&v) +
sizeof(
Int) - 1;
882 Byte* dest =
reinterpret_cast<Byte*
>(&v);
894 void read(std::vector<Int>& v);
896 #ifdef ICE_CPP11_MAPPING
901 void read(std::pair<const int*, const int*>& v);
908 void read(std::pair<const Int*, const Int*>& v, ::IceUtil::ScopedArray<Int>& arr);
921 void read(std::vector<Long>& v);
923 #ifdef ICE_CPP11_MAPPING
928 void read(std::pair<const long long*, const long long*>& v);
935 void read(std::pair<const Long*, const Long*>& v, ::IceUtil::ScopedArray<Long>& arr);
948 void read(std::vector<Float>& v);
950 #ifdef ICE_CPP11_MAPPING
955 void read(std::pair<const float*, const float*>& v);
962 void read(std::pair<const Float*, const Float*>& v, ::IceUtil::ScopedArray<Float>& arr);
975 void read(std::vector<Double>& v);
977 #ifdef ICE_CPP11_MAPPING
982 void read(std::pair<const double*, const double*>& v);
989 void read(std::pair<const Double*, const Double*>& v, ::IceUtil::ScopedArray<Double>& arr);
998 void read(std::string& v,
bool convert =
true);
1000 #ifdef ICE_CPP11_MAPPING
1008 void read(
const char*& vdata,
size_t& vsize,
bool convert =
true);
1016 void read(
const char*& vdata,
size_t& vsize);
1025 void read(
const char*& vdata,
size_t& vsize, std::string& holder);
1034 void read(std::vector<std::string>& v,
bool convert =
true);
1046 void read(std::vector<std::wstring>& v);
1048 #ifdef ICE_CPP11_MAPPING
1059 template<typename T, typename ::std::enable_if<::std::is_base_of<ObjectPrx, T>::value>::type* =
nullptr>
1062 ::std::shared_ptr<ObjectPrx> proxy(readProxy());
1069 v = ::IceInternal::createProxy<T>();
1070 v->_copyFrom(proxy);
1084 template<
typename T>
void read(IceInternal::ProxyHandle<T>& v)
1086 _readProxy(
this, v);
1094 #ifdef ICE_CPP11_MAPPING // C++11 mapping
1095 template<typename T, typename ::std::enable_if<::std::is_base_of<Value, T>::value>::type* =
nullptr>
1098 read(&patchHandle<T>, &v);
1100 #else // C++98 mapping
1101 template<
typename T>
void read(IceInternal::Handle<T>& v)
1103 read(&patchHandle<T>, &v);
1112 void read(PatchFunc patchFunc,
void* patchAddr)
1115 _currentEncaps->decoder->read(patchFunc, patchAddr);
1151 if(i + size > b.end())
1153 throwUnmarshalOutOfBoundsException(__FILE__, __LINE__);
1165 if(
static_cast<unsigned char>(bt) == 255)
1177 return static_cast<size_t>(i - b.begin());
1195 bool readOptImpl(
Int, OptionalFormat);
1205 bool readConverted(std::string&,
Int);
1213 void throwUnmarshalOutOfBoundsException(
const char*,
int);
1214 void throwEncapsulationException(
const char*,
int);
1216 std::string resolveCompactId(
int)
const;
1218 void postUnmarshal(
const ValuePtr&)
const;
1221 enum SliceType { NoSlice, ValueSlice, ExceptionSlice };
1223 void traceSkipSlice(
const std::string&, SliceType)
const;
1225 ValueFactoryManagerPtr valueFactoryManager()
const;
1227 LoggerPtr logger()
const;
1229 #ifdef ICE_CPP11_MAPPING
1230 std::function<std::string(
int)> compactIdResolver()
const;
1235 typedef std::vector<ValuePtr> ValueList;
1241 virtual ~EncapsDecoder();
1243 virtual void read(PatchFunc,
void*) = 0;
1246 virtual void startInstance(SliceType) = 0;
1247 virtual SlicedDataPtr endInstance(
bool) = 0;
1248 virtual const std::string& startSlice() = 0;
1249 virtual void endSlice() = 0;
1250 virtual void skipSlice() = 0;
1252 virtual bool readOptional(
Int, OptionalFormat)
1257 virtual void readPendingValues()
1263 EncapsDecoder(InputStream* stream, Encaps* encaps,
bool sliceValues,
size_t classGraphDepthMax,
1264 const Ice::ValueFactoryManagerPtr& f) :
1265 _stream(stream), _encaps(encaps), _sliceValues(sliceValues), _classGraphDepthMax(classGraphDepthMax),
1266 _classGraphDepth(0), _valueFactoryManager(f), _typeIdIndex(0)
1270 std::string readTypeId(
bool);
1271 ValuePtr newInstance(
const std::string&);
1273 void addPatchEntry(
Int, PatchFunc,
void*);
1274 void unmarshal(
Int,
const ValuePtr&);
1276 typedef std::map<Int, ValuePtr> IndexToPtrMap;
1277 typedef std::map<Int, std::string> TypeIdMap;
1285 typedef std::vector<PatchEntry> PatchList;
1286 typedef std::map<Int, PatchList> PatchMap;
1290 const bool _sliceValues;
1291 const size_t _classGraphDepthMax;
1292 size_t _classGraphDepth;
1293 Ice::ValueFactoryManagerPtr _valueFactoryManager;
1301 IndexToPtrMap _unmarshaledMap;
1302 TypeIdMap _typeIdMap;
1304 ValueList _valueList;
1307 class ICE_API EncapsDecoder10 :
public EncapsDecoder
1311 EncapsDecoder10(
InputStream* stream, Encaps* encaps,
bool sliceValues,
size_t classGraphDepthMax,
1312 const Ice::ValueFactoryManagerPtr& f) :
1313 EncapsDecoder(stream, encaps, sliceValues, classGraphDepthMax, f),
1318 virtual void read(PatchFunc,
void*);
1321 virtual void startInstance(SliceType);
1322 virtual SlicedDataPtr endInstance(
bool);
1323 virtual const std::string& startSlice();
1324 virtual void endSlice();
1325 virtual void skipSlice();
1327 virtual void readPendingValues();
1331 void readInstance();
1334 SliceType _sliceType;
1335 bool _skipFirstSlice;
1339 std::string _typeId;
1342 class ICE_API EncapsDecoder11 :
public EncapsDecoder
1346 EncapsDecoder11(InputStream* stream, Encaps* encaps,
bool sliceValues,
size_t classGraphDepthMax,
1347 const Ice::ValueFactoryManagerPtr& f) :
1348 EncapsDecoder(stream, encaps, sliceValues, classGraphDepthMax, f),
1349 _preAllocatedInstanceData(0), _current(0), _valueIdIndex(1)
1353 virtual void read(PatchFunc,
void*);
1356 virtual void startInstance(SliceType);
1357 virtual SlicedDataPtr endInstance(
bool);
1358 virtual const std::string& startSlice();
1359 virtual void endSlice();
1360 virtual void skipSlice();
1362 virtual bool readOptional(
Int, OptionalFormat);
1366 Int readInstance(
Int, PatchFunc,
void*);
1367 SlicedDataPtr readSlicedData();
1369 struct IndirectPatchEntry
1372 PatchFunc patchFunc;
1375 typedef std::vector<IndirectPatchEntry> IndirectPatchList;
1377 typedef std::vector<Int> IndexList;
1378 typedef std::vector<IndexList> IndexListList;
1382 InstanceData(InstanceData* p) : previous(p), next(0)
1386 previous->next =
this;
1399 SliceType sliceType;
1400 bool skipFirstSlice;
1402 IndexListList indirectionTables;
1409 IndirectPatchList indirectPatchList;
1411 InstanceData* previous;
1414 InstanceData _preAllocatedInstanceData;
1415 InstanceData* _current;
1417 void push(SliceType sliceType)
1421 _current = &_preAllocatedInstanceData;
1425 _current = _current->next ? _current->next :
new InstanceData(_current);
1427 _current->sliceType = sliceType;
1428 _current->skipFirstSlice =
false;
1438 Encaps() : start(0), decoder(0), previous(0)
1456 Container::size_type start;
1458 EncodingVersion encoding;
1460 EncapsDecoder* decoder;
1469 IceInternal::Instance* _instance;
1475 EncodingVersion _encoding;
1477 Encaps* _currentEncaps;
1481 Encaps _preAllocatedEncaps;
1483 #ifndef ICE_CPP11_MAPPING
1484 bool _collectObjects;
1489 size_t _classGraphDepthMax;
1498 ValueFactoryManagerPtr _valueFactoryManager;
1500 #ifdef ICE_CPP11_MAPPING
1501 std::function<std::string(
int)> _compactIdResolver;
1506 #ifdef ICE_CPP11_MAPPING
1507 std::vector<std::function<void()>> _deleters;
short Short
The mapping for the Slice short type.
Definition: Config.h:52
double Double
The mapping for the Slice double type.
Definition: Config.h:65
::std::vector< SliceInfoPtr > SliceInfoSeq
The slices of unknown types.
Definition: SlicedDataF.h:16
constexpr std::experimental::Ice::nullopt_t None
For compatibility with the Ice C++98 mapping, do not use in new code:
Definition: Optional.h:1104
std::experimental::Ice::optional< T > Optional
For compatibility with the Ice C++98 mapping, do not use in new code:
Definition: Optional.h:1100
float Float
The mapping for the Slice float type.
Definition: Config.h:63
#define ICE_API
Definition: Config.h:197
A version structure for the encoding version.
Definition: Version.h:82
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
#define ICE_NULLPTR
Definition: Config.h:362
void * patchAddr
Definition: InputStream.h:1282
#define ICE_IN(...)
Definition: Config.h:370
size_t classGraphDepth
Definition: InputStream.h:1283
long long int Long
The mapping for the Slice long type.
Definition: Config.h:57
Definition: BuiltinSequences.h:56
Definition: InputStream.h:1280
Base class of all object proxies.
Definition: Proxy.h:317
const EncodingVersion Encoding_1_0
Identifies encoding version 1.0.
PatchFunc patchFunc
Definition: InputStream.h:1281
IceUtil::Handle< CompactIdResolver > CompactIdResolverPtr
Definition: FactoryTable.h:31
std::function< void(const std::string &)> UserExceptionFactory
Creates and throws a user exception.
Definition: UserExceptionFactory.h:18
int Int
The mapping for the Slice int type.
Definition: Config.h:54
#define ICE_DELEGATE(T)
Definition: Config.h:369