GridGain C++ Client Library
portable_reader.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) GridGain Systems. All Rights Reserved.
3  * _________ _____ __________________ _____
4  * __ ____/___________(_)______ /__ ____/______ ____(_)_______
5  * _ / __ __ ___/__ / _ __ / _ / __ _ __ `/__ / __ __ \
6  * / /_/ / _ / _ / / /_/ / / /_/ / / /_/ / _ / _ / / /
7  * \____/ /_/ /_/ \_,__/ \____/ \__,_/ /_/ /_/ /_/
8  */
9 
15 #ifndef _GRIDGAIN_PORTABLE_READER
16 #define _GRIDGAIN_PORTABLE_READER
17 
18 #include <stdint.h>
19 #include <string>
20 
21 #include <ignite/common/common.h>
22 
24 #include "gridgain/guid.h"
25 
26 namespace gridgain
27 {
28  namespace portable
29  {
33  class IGNITE_IMPORT_EXPORT PortableReader
34  {
35  public:
41  PortableReader(gridgain::impl::portable::PortableReaderImpl* impl);
42 
50  int8_t ReadInt8(const char* fieldName);
51 
63  int32_t ReadInt8Array(const char* fieldName, int8_t* res, const int32_t len);
64 
71  bool ReadBool(const char* fieldName);
72 
84  int32_t ReadBoolArray(const char* fieldName, bool* res, int32_t len);
85 
92  int16_t ReadInt16(const char* fieldName);
93 
105  int32_t ReadInt16Array(const char* fieldName, int16_t* res, int32_t len);
106 
113  uint16_t ReadUInt16(const char* fieldName);
114 
126  int32_t ReadUInt16Array(const char* fieldName, uint16_t* res, int32_t len);
127 
134  int32_t ReadInt32(const char* fieldName);
135 
147  int32_t ReadInt32Array(const char* fieldName, int32_t* res, int32_t len);
148 
155  int64_t ReadInt64(const char* fieldName);
156 
168  int32_t ReadInt64Array(const char* fieldName, int64_t* res, int32_t len);
169 
176  float ReadFloat(const char* fieldName);
177 
189  int32_t ReadFloatArray(const char* fieldName, float* res, int32_t len);
190 
197  double ReadDouble(const char* fieldName);
198 
210  int32_t ReadDoubleArray(const char* fieldName, double* res, int32_t len);
211 
218  Guid ReadGuid(const char* fieldName);
219 
231  int32_t ReadGuidArray(const char* fieldName, Guid* res, int32_t len);
232 
245  int32_t ReadString(const char* fieldName, char* res, int32_t len);
246 
253  std::string ReadString(const char* fieldName)
254  {
255  int32_t len = ReadString(fieldName, NULL, 0);
256 
257  if (len != -1)
258  {
259  gridgain::impl::utils::SafeArray<char> arr(len + 1);
260 
261  ReadString(fieldName, arr.target, len + 1);
262 
263  return std::string(arr.target);
264  }
265  else
266  return std::string();
267  }
268 
275  PortableStringArrayReader ReadStringArray(const char* fieldName);
276 
283  template<typename T>
284  PortableArrayReader<T> ReadArray(const char* fieldName)
285  {
286  int32_t size;
287 
288  int32_t id = impl->ReadArray(fieldName, &size);
289 
290  return PortableArrayReader<T>(impl, id, size);
291  }
292 
299  template<typename T>
301  {
302  CollectionType typ;
303  int32_t size;
304 
305  int32_t id = impl->ReadCollection(fieldName, &typ, &size);
306 
307  return PortableCollectionReader<T>(impl, id, typ, size);
308  }
309 
317  template<typename T, typename OutputIterator>
318  int32_t ReadCollection(const char* fieldName, OutputIterator out)
319  {
320  return impl->ReadCollection<T>(fieldName, out);
321  }
322 
329  template<typename K, typename V>
330  PortableMapReader<K, V> ReadMap(const char* fieldName)
331  {
332  MapType typ;
333  int32_t size;
334 
335  int32_t id = impl->ReadMap(fieldName, &typ, &size);
336 
337  return PortableMapReader<K, V>(impl, id, typ, size);
338  }
339 
346  CollectionType ReadCollectionType(const char* fieldName);
347 
354  int32_t ReadCollectionSize(const char* fieldName);
355 
362  template<typename T>
363  T ReadObject(const char* fieldName)
364  {
365  return impl->ReadObject<T>(fieldName);
366  }
367 
373  PortableRawReader RawReader();
374  private:
376  gridgain::impl::portable::PortableReaderImpl* impl;
377  };
378  }
379 }
380 
381 #endif
PortableMapReader< K, V > ReadMap(const char *fieldName)
Start map read.
Definition: portable_reader.h:330
Portable raw reader.
Definition: portable_raw_reader.h:35
int32_t ReadCollection(const char *fieldName, OutputIterator out)
Read values and insert them to specified position.
Definition: portable_reader.h:318
std::string ReadString(const char *fieldName)
Read string from the stream.
Definition: portable_reader.h:253
Global universally unique identifier (GUID).
Definition: guid.h:27
Declares gridgain::Guid class.
Portable array reader.
Definition: portable_containers.h:291
T ReadObject(const char *fieldName)
Read object.
Definition: portable_reader.h:363
Portable string array reader.
Definition: portable_containers.h:212
CollectionType
Portable collection types.
Definition: portable_consts.h:27
PortableArrayReader< T > ReadArray(const char *fieldName)
Start array read.
Definition: portable_reader.h:284
PortableCollectionReader< T > ReadCollection(const char *fieldName)
Start collection read.
Definition: portable_reader.h:300
Declares gridgain::portable::PortableRawReader class.
Portable collection reader.
Definition: portable_containers.h:359
Portable map reader.
Definition: portable_containers.h:441
GridGain API.
Definition: cache.h:35
Portable reader.
Definition: portable_reader.h:33
MapType
Portable map types.
Definition: portable_consts.h:68