IGNITE-1610: Implemented portable reader and writer for iterators.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/6695e6c3 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/6695e6c3 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/6695e6c3 Branch: refs/heads/ignite-1655 Commit: 6695e6c3e46473c8b17d5a8fddd720ec7c6d91df Parents: 2a77dd3 Author: isapego <[email protected]> Authored: Thu Oct 15 13:38:31 2015 +0300 Committer: vozerov-gridgain <[email protected]> Committed: Thu Oct 15 13:38:31 2015 +0300 ---------------------------------------------------------------------- .../src/portable_reader_writer_raw_test.cpp | 63 ++++++++++- .../src/portable_reader_writer_test.cpp | 65 ++++++++++++ .../interop/interop_stream_position_guard.h | 79 ++++++++++++++ .../ignite/impl/portable/portable_reader_impl.h | 104 +++++++++++++++++++ .../ignite/impl/portable/portable_writer_impl.h | 55 ++++++++++ .../ignite/portable/portable_raw_reader.h | 26 +++++ .../ignite/portable/portable_raw_writer.h | 30 +++++- .../include/ignite/portable/portable_reader.h | 29 ++++++ .../include/ignite/portable/portable_writer.h | 27 +++++ .../platforms/cpp/core/project/vs/core.vcxproj | 1 + .../cpp/core/project/vs/core.vcxproj.filters | 3 + .../src/impl/portable/portable_reader_impl.cpp | 75 +++++++++++++ .../core/src/portable/portable_raw_reader.cpp | 10 ++ .../cpp/core/src/portable/portable_reader.cpp | 10 ++ 14 files changed, 574 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/6695e6c3/modules/platforms/cpp/core-test/src/portable_reader_writer_raw_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/src/portable_reader_writer_raw_test.cpp b/modules/platforms/cpp/core-test/src/portable_reader_writer_raw_test.cpp index c3a98aa..e93796f 100644 --- a/modules/platforms/cpp/core-test/src/portable_reader_writer_raw_test.cpp +++ b/modules/platforms/cpp/core-test/src/portable_reader_writer_raw_test.cpp @@ -495,6 +495,55 @@ void CheckRawCollection(CollectionType* colType) BOOST_REQUIRE(rawReader.ReadInt8() == 1); } +void CheckRawCollectionIterators(CollectionType* colType) +{ + typedef std::vector<PortableInner> PortableInnerVector; + + PortableInnerVector writeValues; + writeValues.push_back(1); + writeValues.push_back(0); + writeValues.push_back(2); + + InteropUnpooledMemory mem(1024); + + InteropOutputStream out(&mem); + PortableWriterImpl writer(&out, NULL); + PortableRawWriter rawWriter(&writer); + + if (colType) + rawWriter.WriteCollection(writeValues.begin(), writeValues.end(), *colType); + else + rawWriter.WriteCollection(writeValues.begin(), writeValues.end()); + + rawWriter.WriteInt8(1); + + out.Synchronize(); + + InteropInputStream in(&mem); + PortableReaderImpl reader(&in); + PortableRawReader rawReader(&reader); + + int32_t collectionSize = rawReader.ReadCollectionSize(); + BOOST_REQUIRE(collectionSize == writeValues.size()); + + if (colType) + BOOST_REQUIRE(rawReader.ReadCollectionType() == *colType); + else + BOOST_REQUIRE(rawReader.ReadCollectionType() == IGNITE_COLLECTION_UNDEFINED); + + PortableInnerVector readValues(collectionSize); + + int32_t elementsRead = rawReader.ReadCollection<PortableInner>(readValues.begin()); + + BOOST_REQUIRE(elementsRead == 3); + + BOOST_REQUIRE(readValues[0].GetValue() == writeValues[0].GetValue()); + BOOST_REQUIRE(readValues[1].GetValue() == writeValues[1].GetValue()); + BOOST_REQUIRE(readValues[2].GetValue() == writeValues[2].GetValue()); + + BOOST_REQUIRE(rawReader.ReadInt8() == 1); +} + void CheckRawMapEmpty(MapType* mapType) { InteropUnpooledMemory mem(1024); @@ -1457,13 +1506,25 @@ BOOST_AUTO_TEST_CASE(TestCollection) CheckRawCollection(NULL); } -BOOST_AUTO_TEST_CASE(testCollectionTyped) +BOOST_AUTO_TEST_CASE(TestCollectionTyped) { CollectionType typ = IGNITE_COLLECTION_CONCURRENT_SKIP_LIST_SET; CheckRawCollection(&typ); } +BOOST_AUTO_TEST_CASE(TestCollectionIterators) +{ + CheckRawCollectionIterators(NULL); +} + +BOOST_AUTO_TEST_CASE(TestCollectionIteratorsTyped) +{ + CollectionType typ = IGNITE_COLLECTION_CONCURRENT_SKIP_LIST_SET; + + CheckRawCollectionIterators(&typ); +} + BOOST_AUTO_TEST_CASE(TestMapNull) { InteropUnpooledMemory mem(1024); http://git-wip-us.apache.org/repos/asf/ignite/blob/6695e6c3/modules/platforms/cpp/core-test/src/portable_reader_writer_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/src/portable_reader_writer_test.cpp b/modules/platforms/cpp/core-test/src/portable_reader_writer_test.cpp index aff929b..0825ecc 100644 --- a/modules/platforms/cpp/core-test/src/portable_reader_writer_test.cpp +++ b/modules/platforms/cpp/core-test/src/portable_reader_writer_test.cpp @@ -572,6 +572,59 @@ void CheckCollection(CollectionType* colType) BOOST_REQUIRE(reader.ReadInt8("field2") == 1); } +void CheckCollectionIterators(CollectionType* colType) +{ + typedef std::vector<PortableInner> PortableInnerVector; + PortableInnerVector writeValues; + + writeValues.push_back(1); + writeValues.push_back(0); + writeValues.push_back(2); + + TemplatedPortableIdResolver<PortableDummy> idRslvr; + + InteropUnpooledMemory mem(1024); + + InteropOutputStream out(&mem); + PortableWriterImpl writerImpl(&out, &idRslvr, NULL, NULL); + PortableWriter writer(&writerImpl); + + out.Position(18); + + if (colType) + writer.WriteCollection("field1", writeValues.begin(), writeValues.end(), *colType); + else + writer.WriteCollection("field1", writeValues.begin(), writeValues.end()); + + writer.WriteInt8("field2", 1); + + out.Synchronize(); + + InteropInputStream in(&mem); + PortableReaderImpl readerImpl(&in, &idRslvr, 0, true, idRslvr.GetTypeId(), 0, 1000, 1000); + PortableReader reader(&readerImpl); + + in.Position(18); + + BOOST_REQUIRE(reader.ReadCollectionSize("field1") == writeValues.size()); + + CollectionType expectedCollectionType = colType ? *colType : IGNITE_COLLECTION_UNDEFINED; + BOOST_REQUIRE(reader.ReadCollectionType("field1") == expectedCollectionType); + + PortableInnerVector readValues; + std::back_insert_iterator<PortableInnerVector> readInsertIterator(readValues); + + reader.ReadCollection<PortableInner>("field1", readInsertIterator); + + BOOST_REQUIRE(readValues.size() == 3); + + BOOST_REQUIRE(readValues[0].GetValue() == writeValues[0].GetValue()); + BOOST_REQUIRE(readValues[1].GetValue() == writeValues[1].GetValue()); + BOOST_REQUIRE(readValues[2].GetValue() == writeValues[2].GetValue()); + + BOOST_REQUIRE(reader.ReadInt8("field2") == 1); +} + void CheckMapEmpty(MapType* mapType) { TemplatedPortableIdResolver<PortableDummy> idRslvr; @@ -1698,6 +1751,18 @@ BOOST_AUTO_TEST_CASE(testCollectionTyped) CheckCollection(&typ); } +BOOST_AUTO_TEST_CASE(TestCollectionIterators) +{ + CheckCollectionIterators(NULL); +} + +BOOST_AUTO_TEST_CASE(TestCollectionIteratorsTyped) +{ + CollectionType typ = IGNITE_COLLECTION_CONCURRENT_SKIP_LIST_SET; + + CheckCollectionIterators(&typ); +} + BOOST_AUTO_TEST_CASE(TestMapNull) { TemplatedPortableIdResolver<PortableDummy> idRslvr; http://git-wip-us.apache.org/repos/asf/ignite/blob/6695e6c3/modules/platforms/cpp/core/include/ignite/impl/interop/interop_stream_position_guard.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/include/ignite/impl/interop/interop_stream_position_guard.h b/modules/platforms/cpp/core/include/ignite/impl/interop/interop_stream_position_guard.h new file mode 100644 index 0000000..17ecf53 --- /dev/null +++ b/modules/platforms/cpp/core/include/ignite/impl/interop/interop_stream_position_guard.h @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _IGNITE_IMPL_INTEROP_STREAM_POSITION_GUARD +#define _IGNITE_IMPL_INTEROP_OUTPUT_POSITION_GUARD + +#include "ignite/impl/interop/interop_memory.h" + +namespace ignite +{ + namespace impl + { + namespace interop + { + /** + * Interop stream position guard. + */ + template<typename T> + class IGNITE_IMPORT_EXPORT InteropStreamPositionGuard { + public: + /** + * Create new position guard and saves current stream position. + * + * @param stream Stream which position should be saved. + */ + InteropStreamPositionGuard(T& stream) : stream(&stream), pos(stream.Position()) + { + //No-op + } + + /** + * Destructor. + * + * Restores stream's position to a saved one on destruction. + */ + ~InteropStreamPositionGuard() + { + if (stream) + stream->Position(pos); + } + + /** + * Releases guard so it will not restore streams position on destruction. + * + * @param val Value. + */ + void Release() + { + stream = NULL; + } + + private: + /** Stream. */ + T* stream; + + /** Saved position. */ + int32_t pos; + + IGNITE_NO_COPY_ASSIGNMENT(InteropStreamPositionGuard) + }; + } + } +} + +#endif \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/6695e6c3/modules/platforms/cpp/core/include/ignite/impl/portable/portable_reader_impl.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/include/ignite/impl/portable/portable_reader_impl.h b/modules/platforms/cpp/core/include/ignite/impl/portable/portable_reader_impl.h index ab93d10..5050a04 100644 --- a/modules/platforms/cpp/core/include/ignite/impl/portable/portable_reader_impl.h +++ b/modules/platforms/cpp/core/include/ignite/impl/portable/portable_reader_impl.h @@ -518,6 +518,66 @@ namespace ignite int32_t ReadCollection(const char* fieldName, ignite::portable::CollectionType* typ, int32_t* size); /** + * Read values and insert them to specified position. + * + * @param out Output iterator to the initial position in the destination sequence. + * @return Actual amount of elements read. + */ + template<typename T, typename OutputIterator> + int32_t ReadCollection(OutputIterator out) + { + int32_t size; + int32_t id = StartContainerSession(true, IGNITE_TYPE_COLLECTION, &size); + + // Reading collection type. We don't need it here but it should be read. + if (size != -1) + stream->ReadInt8(); + + while (HasNextElement(id)) + { + *out = ReadElement<T>(id); + ++out; + } + + return size; + } + + /** + * Read values and insert them to specified position. + * + * @param fieldName Field name. + * @param out Output iterator to the initial position in the destination sequence. + * @return Actual amount of elements read. + */ + template<typename T, typename OutputIterator> + int32_t ReadCollection(const char* fieldName, OutputIterator out) + { + CheckRawMode(false); + CheckSingleMode(true); + + int32_t fieldId = idRslvr->GetFieldId(typeId, fieldName); + int32_t fieldLen = SeekField(fieldId); + + if (fieldLen <= 0) + return -1; + + int32_t size; + int32_t id = StartContainerSession(false, IGNITE_TYPE_COLLECTION, &size); + + // Reading collection type. We don't need it here but it should be read. + if (size != -1) + stream->ReadInt8(); + + while (HasNextElement(id)) + { + *out = ReadElement<T>(id); + ++out; + } + + return size; + } + + /** * Start map read. * * @param typ Map type. @@ -537,6 +597,36 @@ namespace ignite int32_t ReadMap(const char* fieldName, ignite::portable::MapType* typ, int32_t* size); /** + * Read type of the collection. + * + * @return Collection type. + */ + ignite::portable::CollectionType ReadCollectionType(); + + /** + * Read type of the collection. + * + * @param fieldName Field name. + * @return Collection type. + */ + ignite::portable::CollectionType ReadCollectionType(const char* fieldName); + + /** + * Read size of the collection. + * + * @return Collection size. + */ + int32_t ReadCollectionSize(); + + /** + * Read size of the collection. + * + * @param fieldName Field name. + * @return Collection size. + */ + int32_t ReadCollectionSize(const char* fieldName); + + /** * Check whether next value exists. * * @param id Session ID. @@ -1014,6 +1104,20 @@ namespace ignite int32_t ReadStringInternal(char* res, const int32_t len); /** + * Read type of the collection. Do not preserve stream position. + * + * @return Collection type. + */ + ignite::portable::CollectionType ReadCollectionTypeUnprotected(); + + /** + * Read size of the collection. Do not preserve stream position. + * + * @return Collection size. + */ + int32_t ReadCollectionSizeUnprotected(); + + /** * Read value. * * @param expHdr Expected header. http://git-wip-us.apache.org/repos/asf/ignite/blob/6695e6c3/modules/platforms/cpp/core/include/ignite/impl/portable/portable_writer_impl.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/include/ignite/impl/portable/portable_writer_impl.h b/modules/platforms/cpp/core/include/ignite/impl/portable/portable_writer_impl.h index 2e5a0e7..0259a7e 100644 --- a/modules/platforms/cpp/core/include/ignite/impl/portable/portable_writer_impl.h +++ b/modules/platforms/cpp/core/include/ignite/impl/portable/portable_writer_impl.h @@ -440,6 +440,40 @@ namespace ignite * @return Session ID. */ int32_t WriteCollection(const char* fieldName, ignite::portable::CollectionType typ); + + /** + * Write values in interval [first, last). + * + * @param first Iterator pointing to the beginning of the interval. + * @param last Iterator pointing to the end of the interval. + * @param typ Collection type. + */ + template<typename InputIterator> + void WriteCollection(InputIterator first, InputIterator last, ignite::portable::CollectionType typ) + { + StartContainerSession(true); + + WriteCollectionWithinSession(first, last, typ); + } + + /** + * Write values in interval [first, last). + * + * @param fieldName Field name. + * @param first Iterator pointing to the beginning of the interval. + * @param last Iterator pointing to the end of the interval. + * @param typ Collection type. + */ + template<typename InputIterator> + void WriteCollection(const char* fieldName, InputIterator first, InputIterator last, + ignite::portable::CollectionType typ) + { + StartContainerSession(false); + + WriteFieldIdSkipLength(fieldName, IGNITE_TYPE_COLLECTION); + + WriteCollectionWithinSession(first, last, typ); + } /** * Start map write. @@ -747,6 +781,27 @@ namespace ignite } /** + * Write values in interval [first, last). + * New session should be started prior to call to this method. + * @param first Iterator pointing to the beginning of the interval. + * @param last Iterator pointing to the end of the interval. + * @param typ Collection type. + */ + template<typename InputIterator> + void WriteCollectionWithinSession(InputIterator first, InputIterator last, + ignite::portable::CollectionType typ) + { + stream->WriteInt8(IGNITE_TYPE_COLLECTION); + stream->Position(stream->Position() + 4); + stream->WriteInt8(typ); + + for (InputIterator i = first; i != last; ++i) + WriteElement(elemId, *i); + + CommitContainer(elemId); + } + + /** * Check raw mode. * * @param expected Expected raw mode of the reader. http://git-wip-us.apache.org/repos/asf/ignite/blob/6695e6c3/modules/platforms/cpp/core/include/ignite/portable/portable_raw_reader.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/include/ignite/portable/portable_raw_reader.h b/modules/platforms/cpp/core/include/ignite/portable/portable_raw_reader.h index 0ecaa4d..40abe8b 100644 --- a/modules/platforms/cpp/core/include/ignite/portable/portable_raw_reader.h +++ b/modules/platforms/cpp/core/include/ignite/portable/portable_raw_reader.h @@ -289,6 +289,18 @@ namespace ignite } /** + * Read values and insert them to specified position. + * + * @param out Output iterator to the initial position in the destination sequence. + * @return Number of elements that have been read. + */ + template<typename T, typename OutputIterator> + int32_t ReadCollection(OutputIterator out) + { + return impl->ReadCollection<T>(out); + } + + /** * Start map read. * * @return Map reader. @@ -305,6 +317,20 @@ namespace ignite } /** + * Read type of the collection. + * + * @return Collection type. + */ + CollectionType ReadCollectionType(); + + /** + * Read type of the collection. + * + * @return Collection size. + */ + int32_t ReadCollectionSize(); + + /** * Read object. * * @return Object. http://git-wip-us.apache.org/repos/asf/ignite/blob/6695e6c3/modules/platforms/cpp/core/include/ignite/portable/portable_raw_writer.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/include/ignite/portable/portable_raw_writer.h b/modules/platforms/cpp/core/include/ignite/portable/portable_raw_writer.h index 4cf2f00..7d0c118 100644 --- a/modules/platforms/cpp/core/include/ignite/portable/portable_raw_writer.h +++ b/modules/platforms/cpp/core/include/ignite/portable/portable_raw_writer.h @@ -247,7 +247,7 @@ namespace ignite * @return Collection writer. */ template<typename T> - PortableCollectionWriter<T> WriteCollection(ignite::portable::CollectionType typ) + PortableCollectionWriter<T> WriteCollection(CollectionType typ) { int32_t id = impl->WriteCollection(typ); @@ -255,6 +255,32 @@ namespace ignite } /** + * Write values in interval [first, last). + * + * @param first Iterator pointing to the beginning of the interval. + * @param last Iterator pointing to the end of the interval. + * @param typ Collection type. + */ + template<typename InputIterator> + void WriteCollection(InputIterator first, InputIterator last) + { + impl->WriteCollection(first, last, IGNITE_COLLECTION_UNDEFINED); + } + + /** + * Write values in interval [first, last). + * + * @param first Iterator pointing to the beginning of the interval. + * @param last Iterator pointing to the end of the interval. + * @param typ Collection type. + */ + template<typename InputIterator> + void WriteCollection(InputIterator first, InputIterator last, CollectionType typ) + { + impl->WriteCollection(first, last, typ); + } + + /** * Start map write. * * @param typ Map type. @@ -273,7 +299,7 @@ namespace ignite * @return Map writer. */ template<typename K, typename V> - PortableMapWriter<K, V> WriteMap(ignite::portable::MapType typ) + PortableMapWriter<K, V> WriteMap(MapType typ) { int32_t id = impl->WriteMap(typ); http://git-wip-us.apache.org/repos/asf/ignite/blob/6695e6c3/modules/platforms/cpp/core/include/ignite/portable/portable_reader.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/include/ignite/portable/portable_reader.h b/modules/platforms/cpp/core/include/ignite/portable/portable_reader.h index 8a04f0f..d0533fd 100644 --- a/modules/platforms/cpp/core/include/ignite/portable/portable_reader.h +++ b/modules/platforms/cpp/core/include/ignite/portable/portable_reader.h @@ -311,6 +311,19 @@ namespace ignite } /** + * Read values and insert them to specified position. + * + * @param fieldName Field name. + * @param out Output iterator to the initial position in the destination sequence. + * @return Number of elements that have been read. + */ + template<typename T, typename OutputIterator> + int32_t ReadCollection(const char* fieldName, OutputIterator out) + { + return impl->ReadCollection<T>(fieldName, out); + } + + /** * Start map read. * * @param fieldName Field name. @@ -328,6 +341,22 @@ namespace ignite } /** + * Read type of the collection. + * + * @param fieldName Field name. + * @return Collection type. + */ + CollectionType ReadCollectionType(const char* fieldName); + + /** + * Read type of the collection. + * + * @param fieldName Field name. + * @return Collection size. + */ + int32_t ReadCollectionSize(const char* fieldName); + + /** * Read object. * * @param fieldName Field name. http://git-wip-us.apache.org/repos/asf/ignite/blob/6695e6c3/modules/platforms/cpp/core/include/ignite/portable/portable_writer.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/include/ignite/portable/portable_writer.h b/modules/platforms/cpp/core/include/ignite/portable/portable_writer.h index d5009ac..c225340 100644 --- a/modules/platforms/cpp/core/include/ignite/portable/portable_writer.h +++ b/modules/platforms/cpp/core/include/ignite/portable/portable_writer.h @@ -280,6 +280,33 @@ namespace ignite } /** + * Write values in interval [first, last). + * + * @param fieldName Field name. + * @param first Iterator pointing to the beginning of the interval. + * @param last Iterator pointing to the end of the interval. + */ + template<typename InputIterator> + void WriteCollection(const char* fieldName, InputIterator first, InputIterator last) + { + WriteCollection(fieldName, first, last, IGNITE_COLLECTION_UNDEFINED); + } + + /** + * Write values in interval [first, last). + * + * @param fieldName Field name. + * @param first Iterator pointing to the beginning of the interval. + * @param last Iterator pointing to the end of the interval. + * @param typ Collection type. + */ + template<typename InputIterator> + void WriteCollection(const char* fieldName, InputIterator first, InputIterator last, CollectionType typ) + { + impl->WriteCollection(fieldName, first, last, typ); + } + + /** * Start map write. * * @param fieldName Field name. http://git-wip-us.apache.org/repos/asf/ignite/blob/6695e6c3/modules/platforms/cpp/core/project/vs/core.vcxproj ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/project/vs/core.vcxproj b/modules/platforms/cpp/core/project/vs/core.vcxproj index 58fa283..b7e4f7c 100644 --- a/modules/platforms/cpp/core/project/vs/core.vcxproj +++ b/modules/platforms/cpp/core/project/vs/core.vcxproj @@ -211,6 +211,7 @@ <ClInclude Include="..\..\include\ignite\impl\interop\interop_input_stream.h" /> <ClInclude Include="..\..\include\ignite\impl\interop\interop_memory.h" /> <ClInclude Include="..\..\include\ignite\impl\interop\interop_output_stream.h" /> + <ClInclude Include="..\..\include\ignite\impl\interop\interop_stream_position_guard.h" /> <ClInclude Include="..\..\include\ignite\impl\operations.h" /> <ClInclude Include="..\..\include\ignite\impl\portable\portable_common.h" /> <ClInclude Include="..\..\include\ignite\impl\portable\portable_id_resolver.h" /> http://git-wip-us.apache.org/repos/asf/ignite/blob/6695e6c3/modules/platforms/cpp/core/project/vs/core.vcxproj.filters ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/project/vs/core.vcxproj.filters b/modules/platforms/cpp/core/project/vs/core.vcxproj.filters index d18599d..83f2fc7 100644 --- a/modules/platforms/cpp/core/project/vs/core.vcxproj.filters +++ b/modules/platforms/cpp/core/project/vs/core.vcxproj.filters @@ -213,6 +213,9 @@ <ClInclude Include="..\..\include\ignite\cache\query\query_scan.h"> <Filter>Code\cache\query</Filter> </ClInclude> + <ClInclude Include="..\..\include\ignite\impl\interop\interop_stream_position_guard.h"> + <Filter>Code\impl\interop</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <Filter Include="Code"> http://git-wip-us.apache.org/repos/asf/ignite/blob/6695e6c3/modules/platforms/cpp/core/src/impl/portable/portable_reader_impl.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/impl/portable/portable_reader_impl.cpp b/modules/platforms/cpp/core/src/impl/portable/portable_reader_impl.cpp index e41dafc..a8196a1 100644 --- a/modules/platforms/cpp/core/src/impl/portable/portable_reader_impl.cpp +++ b/modules/platforms/cpp/core/src/impl/portable/portable_reader_impl.cpp @@ -22,6 +22,7 @@ #include "ignite/impl/portable/portable_utils.h" #include "ignite/portable/portable_type.h" #include "ignite/ignite_error.h" +#include "ignite/impl/interop/interop_stream_position_guard.h" using namespace ignite::impl::interop; using namespace ignite::impl::portable; @@ -477,6 +478,80 @@ namespace ignite } } + CollectionType PortableReaderImpl::ReadCollectionTypeUnprotected() + { + int32_t size = ReadCollectionSizeUnprotected(); + if (size == -1) + return IGNITE_COLLECTION_UNDEFINED; + + CollectionType typ = static_cast<CollectionType>(stream->ReadInt8()); + + return typ; + } + + CollectionType PortableReaderImpl::ReadCollectionType() + { + InteropStreamPositionGuard<InteropInputStream> positionGuard(*stream); + + return ReadCollectionTypeUnprotected(); + } + + CollectionType PortableReaderImpl::ReadCollectionType(const char* fieldName) + { + CheckRawMode(false); + CheckSingleMode(true); + + InteropStreamPositionGuard<InteropInputStream> positionGuard(*stream); + + int32_t fieldId = idRslvr->GetFieldId(typeId, fieldName); + int32_t fieldLen = SeekField(fieldId); + + if (fieldLen <= 0) + return IGNITE_COLLECTION_UNDEFINED; + + return ReadCollectionTypeUnprotected(); + } + + int32_t PortableReaderImpl::ReadCollectionSizeUnprotected() + { + int8_t hdr = stream->ReadInt8(); + + if (hdr != IGNITE_TYPE_COLLECTION) + { + if (hdr != IGNITE_HDR_NULL) + ThrowOnInvalidHeader(IGNITE_TYPE_COLLECTION, hdr); + + return -1; + } + + int32_t size = stream->ReadInt32(); + + return size; + } + + int32_t PortableReaderImpl::ReadCollectionSize() + { + InteropStreamPositionGuard<InteropInputStream> positionGuard(*stream); + + return ReadCollectionSizeUnprotected(); + } + + int32_t PortableReaderImpl::ReadCollectionSize(const char* fieldName) + { + CheckRawMode(false); + CheckSingleMode(true); + + InteropStreamPositionGuard<InteropInputStream> positionGuard(*stream); + + int32_t fieldId = idRslvr->GetFieldId(typeId, fieldName); + int32_t fieldLen = SeekField(fieldId); + + if (fieldLen <= 0) + return -1; + + return ReadCollectionSizeUnprotected(); + } + bool PortableReaderImpl::HasNextElement(int32_t id) const { return elemId == id && elemRead < elemCnt; http://git-wip-us.apache.org/repos/asf/ignite/blob/6695e6c3/modules/platforms/cpp/core/src/portable/portable_raw_reader.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/portable/portable_raw_reader.cpp b/modules/platforms/cpp/core/src/portable/portable_raw_reader.cpp index f659913..775c561 100644 --- a/modules/platforms/cpp/core/src/portable/portable_raw_reader.cpp +++ b/modules/platforms/cpp/core/src/portable/portable_raw_reader.cpp @@ -131,5 +131,15 @@ namespace ignite return PortableStringArrayReader(impl, id, size); } + + CollectionType PortableRawReader::ReadCollectionType() + { + return impl->ReadCollectionType(); + } + + int32_t PortableRawReader::ReadCollectionSize() + { + return impl->ReadCollectionSize(); + } } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/6695e6c3/modules/platforms/cpp/core/src/portable/portable_reader.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/src/portable/portable_reader.cpp b/modules/platforms/cpp/core/src/portable/portable_reader.cpp index fe8fba1..62c1e67 100644 --- a/modules/platforms/cpp/core/src/portable/portable_reader.cpp +++ b/modules/platforms/cpp/core/src/portable/portable_reader.cpp @@ -132,6 +132,16 @@ namespace ignite return PortableStringArrayReader(impl, id, size); } + CollectionType PortableReader::ReadCollectionType(const char* fieldName) + { + return impl->ReadCollectionType(fieldName); + } + + int32_t PortableReader::ReadCollectionSize(const char* fieldName) + { + return impl->ReadCollectionSize(fieldName); + } + PortableRawReader PortableReader::RawReader() { impl->SetRawMode();
