IGNITE-3584: CPP: BinaryType refactored
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/5c4d43c2 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/5c4d43c2 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/5c4d43c2 Branch: refs/heads/ignite-4929 Commit: 5c4d43c2b6414159fcf15d811d8ca365e01da4d8 Parents: aeacad6 Author: Igor Sapego <[email protected]> Authored: Tue Apr 11 13:48:49 2017 +0300 Committer: Igor Sapego <[email protected]> Committed: Tue Apr 11 13:48:49 2017 +0300 ---------------------------------------------------------------------- .gitignore | 31 ++++- .../binary/include/ignite/binary/binary_type.h | 129 ++++++------------- .../ignite/impl/binary/binary_id_resolver.h | 33 ++--- .../ignite/impl/binary/binary_object_impl.h | 3 +- .../ignite/impl/binary/binary_reader_impl.h | 80 +++++++++++- .../ignite/impl/binary/binary_type_impl.h | 12 +- .../include/ignite/impl/binary/binary_utils.h | 6 +- .../ignite/impl/binary/binary_writer_impl.h | 15 ++- .../core-test/include/ignite/binary_test_defs.h | 117 +++++++++-------- .../cpp/core-test/include/ignite/complex_type.h | 30 ++--- .../cpp/core-test/include/ignite/test_type.h | 37 +++--- .../src/binary_identity_resolver_test.cpp | 92 +++++-------- .../cpp/core-test/src/binary_object_test.cpp | 4 +- .../cpp/core-test/src/binary_test_defs.cpp | 5 + .../cpp/core-test/src/cache_invoke_test.cpp | 18 +-- .../cpp/core-test/src/cache_query_test.cpp | 12 +- .../platforms/cpp/core-test/src/cache_test.cpp | 38 +++--- .../cpp/core-test/src/continuous_query_test.cpp | 34 +++-- .../cpp/core/include/ignite/ignite_binding.h | 6 +- .../impl/cache/cache_entry_processor_holder.h | 33 +++-- .../cpp/odbc-test/include/complex_type.h | 26 ++-- .../platforms/cpp/odbc-test/include/test_type.h | 37 +++--- 22 files changed, 393 insertions(+), 405 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/5c4d43c2/.gitignore ---------------------------------------------------------------------- diff --git a/.gitignore b/.gitignore index e118746..d8dd951 100644 --- a/.gitignore +++ b/.gitignore @@ -59,4 +59,33 @@ ipch/ [Dd]ebug*/ [Rr]elease*/ packages -*.nupkg \ No newline at end of file +*.nupkg + +#Autotools temp files +/modules/platforms/cpp/**/Makefile +/modules/platforms/cpp/**/Makefile.in +/modules/platforms/cpp/**/aclocal.m4 +/modules/platforms/cpp/**/.libs/ +/modules/platforms/cpp/**/.dirstamp +/modules/platforms/cpp/**/*.la +/modules/platforms/cpp/ar-lib +/modules/platforms/cpp/compile +/modules/platforms/cpp/confdefs.h +/modules/platforms/cpp/config.guess +/modules/platforms/cpp/config.h +/modules/platforms/cpp/config.h.in +/modules/platforms/cpp/config.status +/modules/platforms/cpp/config.sub +/modules/platforms/cpp/configure +/modules/platforms/cpp/core-test/ignite-tests +/modules/platforms/cpp/core/ignite.pc +/modules/platforms/cpp/depcomp +/modules/platforms/cpp/ignite/ignite +/modules/platforms/cpp/install-sh +/modules/platforms/cpp/libtool +/modules/platforms/cpp/ltmain.sh +/modules/platforms/cpp/m4/ +/modules/platforms/cpp/missing +/modules/platforms/cpp/odbc-test/ignite-odbc-tests +/modules/platforms/cpp/stamp-h1 + http://git-wip-us.apache.org/repos/asf/ignite/blob/5c4d43c2/modules/platforms/cpp/binary/include/ignite/binary/binary_type.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/binary/include/ignite/binary/binary_type.h b/modules/platforms/cpp/binary/include/ignite/binary/binary_type.h index f65c652..6bd95a1 100644 --- a/modules/platforms/cpp/binary/include/ignite/binary/binary_type.h +++ b/modules/platforms/cpp/binary/include/ignite/binary/binary_type.h @@ -51,7 +51,7 @@ struct BinaryType<T> \ * Implementation of GetTypeId() which returns predefined constant. */ #define IGNITE_BINARY_GET_TYPE_ID_AS_CONST(id) \ -int32_t GetTypeId() \ +static int32_t GetTypeId() \ { \ return id; \ } @@ -61,7 +61,7 @@ int32_t GetTypeId() \ * Implementation of GetTypeId() which returns hash of passed type name. */ #define IGNITE_BINARY_GET_TYPE_ID_AS_HASH(typeName) \ -int32_t GetTypeId() \ +static int32_t GetTypeId() \ { \ return GetBinaryStringHashCode(#typeName); \ } @@ -71,9 +71,9 @@ int32_t GetTypeId() \ * Implementation of GetTypeName() which returns type name as is. */ #define IGNITE_BINARY_GET_TYPE_NAME_AS_IS(typeName) \ -std::string GetTypeName() \ +static void GetTypeName(std::string& dst) \ { \ - return #typeName; \ + dst = #typeName; \ } /** @@ -81,7 +81,7 @@ std::string GetTypeName() \ * Default implementation of GetFieldId() function which returns Java-way hash code of the string. */ #define IGNITE_BINARY_GET_FIELD_ID_AS_HASH \ -int32_t GetFieldId(const char* name) \ +static int32_t GetFieldId(const char* name) \ { \ return GetBinaryStringHashCode(name); \ } @@ -91,7 +91,7 @@ int32_t GetFieldId(const char* name) \ * Implementation of GetHashCode() function which always returns 0. */ #define IGNITE_BINARY_GET_HASH_CODE_ZERO(T) \ -int32_t GetHashCode(const T& obj) \ +static int32_t GetHashCode(const T& obj) \ { \ return 0; \ } @@ -101,7 +101,7 @@ int32_t GetHashCode(const T& obj) \ * Implementation of IsNull() function which always returns false. */ #define IGNITE_BINARY_IS_NULL_FALSE(T) \ -bool IsNull(const T& obj) \ +static bool IsNull(const T& obj) \ { \ return false; \ } @@ -111,7 +111,7 @@ bool IsNull(const T& obj) \ * Implementation of IsNull() function which return true if passed object is null pointer. */ #define IGNITE_BINARY_IS_NULL_IF_NULLPTR(T) \ -bool IsNull(const T& obj) \ +static bool IsNull(const T& obj) \ { \ return obj; \ } @@ -121,9 +121,9 @@ bool IsNull(const T& obj) \ * Implementation of GetNull() function which returns an instance created with defult constructor. */ #define IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(T) \ -T GetNull() \ +static void GetNull(T& dst) \ { \ - return T(); \ + dst = T(); \ } /** @@ -131,11 +131,12 @@ T GetNull() \ * Implementation of GetNull() function which returns NULL pointer. */ #define IGNITE_BINARY_GET_NULL_NULLPTR(T) \ -T GetNull() \ +static void GetNull(T& dst) \ { \ - return NULL; \ + dst = 0; \ } + namespace ignite { namespace binary @@ -155,26 +156,35 @@ namespace ignite * Binary type structure. Defines a set of functions required for type to be serialized and deserialized. */ template<typename T> - struct IGNITE_IMPORT_EXPORT BinaryType + struct IGNITE_IMPORT_EXPORT BinaryType { }; + + /** + * Templated binary type specification for pointers. + */ + template <typename T> + struct IGNITE_IMPORT_EXPORT BinaryType<T*> { + /** Actual type. */ + typedef BinaryType<T> BinaryTypeDereferenced; + /** * Get binary object type ID. * * @return Type ID. */ - int32_t GetTypeId() + static int32_t GetTypeId() { - IGNITE_ERROR_1(IgniteError::IGNITE_ERR_BINARY, "GetTypeId function is not defined for binary type."); + return BinaryTypeDereferenced::GetTypeId(); } /** * Get binary object type name. * - * @return Type name. + * @param dst Output type name. */ - std::string GetTypeName() + static void GetTypeName(std::string& dst) { - IGNITE_ERROR_1(IgniteError::IGNITE_ERR_BINARY, "GetTypeName function is not defined for binary type."); + BinaryTypeDereferenced::GetTypeName(dst); } /** @@ -183,9 +193,9 @@ namespace ignite * @param name Field name. * @return Field ID. */ - int32_t GetFieldId(const char* name) + static int32_t GetFieldId(const char* name) { - return GetBinaryStringHashCode(name); + return BinaryTypeDereferenced::GetFieldId(name); } /** @@ -194,20 +204,22 @@ namespace ignite * @param writer Writer. * @param obj Object. */ - void Write(BinaryWriter& writer, const T& obj) + static void Write(BinaryWriter& writer, T* const& obj) { - IGNITE_ERROR_1(IgniteError::IGNITE_ERR_BINARY, "Write function is not defined for binary type."); + BinaryTypeDereferenced::Write(writer, *obj); } /** * Read binary object. * * @param reader Reader. - * @return Object. + * @param dst Output object. */ - T Read(BinaryReader& reader) + static void Read(BinaryReader& reader, T*& dst) { - IGNITE_ERROR_1(IgniteError::IGNITE_ERR_BINARY, "Read function is not defined for binary type."); + dst = new T(); + + BinaryTypeDereferenced::Read(reader, *dst); } /** @@ -216,76 +228,19 @@ namespace ignite * @param obj Binary object to test. * @return True if binary object should be interpreted as NULL. */ - bool IsNull(const T& obj) + static bool IsNull(T* const& obj) { - return false; + return !obj || BinaryTypeDereferenced::IsNull(*obj); } /** * Get NULL value for the given binary type. * - * @return NULL value. - */ - T GetNull() - { - IGNITE_ERROR_1(IgniteError::IGNITE_ERR_BINARY, "GetNull function is not defined for binary type."); - } - }; - - /** - * Templated binary type specification for pointers. - */ - template <typename T> - struct IGNITE_IMPORT_EXPORT BinaryType<T*> - { - /** Actual type. */ - BinaryType<T> typ; - - /** - * Constructor. + * @param dst Null value for the type. */ - BinaryType() : typ() - { - // No-op. - } - - int32_t GetTypeId() - { - return typ.GetTypeId(); - } - - std::string GetTypeName() - { - return typ.GetTypeName(); - } - - int32_t GetFieldId(const char* name) - { - return typ.GetFieldId(name); - } - - void Write(BinaryWriter& writer, T* const& obj) - { - typ.Write(writer, *obj); - } - - T* Read(BinaryReader& reader) - { - T* res = new T(); - - *res = typ.Read(reader); - - return res; - } - - bool IsNull(T* const& obj) - { - return !obj || typ.IsNull(*obj); - } - - T* GetNull() + static void GetNull(T*& dst) { - return 0; + dst = 0; } }; } http://git-wip-us.apache.org/repos/asf/ignite/blob/5c4d43c2/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_id_resolver.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_id_resolver.h b/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_id_resolver.h index 7d6b12b..123299c 100644 --- a/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_id_resolver.h +++ b/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_id_resolver.h @@ -78,46 +78,29 @@ namespace ignite /** * Constructor. */ - TemplatedBinaryIdResolver() : - type() - { - // No-op. - } - - /** - * Constructor. - * - * @param type Binary type. - */ - TemplatedBinaryIdResolver(ignite::binary::BinaryType<T> type) : - type(type) + TemplatedBinaryIdResolver() { // No-op. } virtual int32_t GetTypeId() { - return type.GetTypeId(); + return ignite::binary::BinaryType<T>::GetTypeId(); } - virtual int32_t GetFieldId(const int32_t typeId, const char* name) { + virtual int32_t GetFieldId(const int32_t typeId, const char* name) + { if (name) - return type.GetFieldId(name); - else - { - IGNITE_ERROR_FORMATTED_1(IgniteError::IGNITE_ERR_BINARY, - "Field name cannot be NULL.", "typeId", typeId); - } + return ignite::binary::BinaryType<T>::GetFieldId(name); + + IGNITE_ERROR_FORMATTED_1(IgniteError::IGNITE_ERR_BINARY, + "Field name cannot be NULL.", "typeId", typeId); } virtual BinaryIdResolver* Clone() const { return new TemplatedBinaryIdResolver<T>(*this); } - - private: - /** Actual type. */ - ignite::binary::BinaryType<T> type; }; /** http://git-wip-us.apache.org/repos/asf/ignite/blob/5c4d43c2/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_object_impl.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_object_impl.h b/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_object_impl.h index 880fff2..976ba29 100644 --- a/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_object_impl.h +++ b/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_object_impl.h @@ -109,9 +109,8 @@ namespace ignite template<typename T> T Deserialize() const { - ignite::binary::BinaryType<T> bt; int32_t actualTypeId = GetTypeId(); - int32_t requestedTypeId = bt.GetTypeId(); + int32_t requestedTypeId = ignite::binary::BinaryType<T>::GetTypeId(); if (requestedTypeId != actualTypeId) { http://git-wip-us.apache.org/repos/asf/ignite/blob/5c4d43c2/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_reader_impl.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_reader_impl.h b/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_reader_impl.h index 8be9172..6d66416 100644 --- a/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_reader_impl.h +++ b/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_reader_impl.h @@ -916,6 +916,8 @@ namespace ignite case IGNITE_HDR_FULL: { + typedef ignite::binary::BinaryType<T> BType; + int8_t protoVer = stream->ReadInt8(); if (protoVer != IGNITE_PROTO_VER) { @@ -976,14 +978,14 @@ namespace ignite bool usrType = (flags & IGNITE_BINARY_FLAG_USER_TYPE) != 0; - ignite::binary::BinaryType<T> type; - TemplatedBinaryIdResolver<T> idRslvr(type); + TemplatedBinaryIdResolver<T> idRslvr; BinaryReaderImpl readerImpl(stream, &idRslvr, pos, usrType, typeId, hashCode, len, rawOff, footerBegin, footerEnd, schemaType); ignite::binary::BinaryReader reader(&readerImpl); - T val = type.Read(reader); + T val; + BType::Read(reader, val); stream->Position(pos + len); @@ -1004,9 +1006,11 @@ namespace ignite template<typename T> T GetNull() const { - ignite::binary::BinaryType<T> type; + T res; + + ignite::binary::BinaryType<T>::GetNull(res); - return type.GetNull(); + return res; } /** @@ -1439,6 +1443,72 @@ namespace ignite template<> std::string IGNITE_IMPORT_EXPORT BinaryReaderImpl::ReadTopObject<std::string>(); + + template<> + inline int8_t BinaryReaderImpl::GetNull() const + { + return 0; + } + + template<> + inline int16_t BinaryReaderImpl::GetNull() const + { + return 0; + } + + template<> + inline int32_t BinaryReaderImpl::GetNull() const + { + return 0; + } + + template<> + inline int64_t BinaryReaderImpl::GetNull() const + { + return 0; + } + + template<> + inline float BinaryReaderImpl::GetNull() const + { + return 0.0f; + } + + template<> + inline double BinaryReaderImpl::GetNull() const + { + return 0.0; + } + + template<> + inline Guid BinaryReaderImpl::GetNull() const + { + return Guid(); + } + + template<> + inline Date BinaryReaderImpl::GetNull() const + { + return Date(); + } + + template<> + inline Timestamp BinaryReaderImpl::GetNull() const + { + return Timestamp(); + } + + template<> + inline Time BinaryReaderImpl::GetNull() const + { + return Time(); + } + + template<> + inline std::string BinaryReaderImpl::GetNull() const + { + return std::string(); + } } } } http://git-wip-us.apache.org/repos/asf/ignite/blob/5c4d43c2/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_type_impl.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_type_impl.h b/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_type_impl.h index 08c60c0..269db61 100644 --- a/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_type_impl.h +++ b/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_type_impl.h @@ -57,9 +57,9 @@ namespace ignite { namespace binary { - IGNITE_DECLARE_BINARY_TYPE_METHOD_CHECKER(GetHashCode, int32_t(ignite::binary::BinaryType<T>::*)(const T&)); + IGNITE_DECLARE_BINARY_TYPE_METHOD_CHECKER(GetHashCode, int32_t(*)(const T&)); IGNITE_DECLARE_BINARY_TYPE_METHOD_CHECKER(GetIdentityResolver, - ignite::Reference<ignite::binary::BinaryIdentityResolver>(ignite::binary::BinaryType<T>::*)()); + ignite::Reference<ignite::binary::BinaryIdentityResolver>(*)()); /** * This type is used to get hash code for binary types which have not @@ -85,9 +85,7 @@ namespace ignite { static int32_t Get(const T& obj, const ignite::binary::BinaryObject&) { - ignite::binary::BinaryType<T> bt; - - return bt.GetHashCode(obj); + return ignite::binary::BinaryType<T>::GetHashCode(obj); } }; @@ -100,8 +98,8 @@ namespace ignite { static int32_t Get(const T&, const ignite::binary::BinaryObject& obj) { - ignite::binary::BinaryType<T> bt; - ignite::Reference<ignite::binary::BinaryIdentityResolver> resolver = bt.GetIdentityResolver(); + ignite::Reference<ignite::binary::BinaryIdentityResolver> resolver = + ignite::binary::BinaryType<T>::GetIdentityResolver(); return resolver.Get()->GetHashCode(obj); } http://git-wip-us.apache.org/repos/asf/ignite/blob/5c4d43c2/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_utils.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_utils.h b/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_utils.h index 268c2d8..84d7a19 100644 --- a/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_utils.h +++ b/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_utils.h @@ -471,9 +471,11 @@ namespace ignite template<typename T> static T GetDefaultValue() { - ignite::binary::BinaryType<T> binType; + T res; - return binType.GetNull(); + ignite::binary::BinaryType<T>::GetNull(res); + + return res; } }; http://git-wip-us.apache.org/repos/asf/ignite/blob/5c4d43c2/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_writer_impl.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_writer_impl.h b/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_writer_impl.h index 50b2375..e7dafb2 100644 --- a/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_writer_impl.h +++ b/modules/platforms/cpp/binary/include/ignite/impl/binary/binary_writer_impl.h @@ -681,17 +681,20 @@ namespace ignite template<typename T> void WriteTopObject(const T& obj) { - ignite::binary::BinaryType<T> type; + typedef ignite::binary::BinaryType<T> BType; - if (type.IsNull(obj)) + if (BType::IsNull(obj)) stream->WriteInt8(IGNITE_HDR_NULL); else { - TemplatedBinaryIdResolver<T> idRslvr(type); - ignite::common::concurrent::SharedPointer<BinaryTypeHandler> metaHnd; + TemplatedBinaryIdResolver<T> idRslvr; + common::concurrent::SharedPointer<BinaryTypeHandler> metaHnd; + + std::string typeName; + BType::GetTypeName(typeName); if (metaMgr) - metaHnd = metaMgr->GetHandler(type.GetTypeName(), idRslvr.GetTypeId()); + metaHnd = metaMgr->GetHandler(typeName, idRslvr.GetTypeId()); int32_t pos = stream->Position(); @@ -708,7 +711,7 @@ namespace ignite // Reserve space for the Object Lenght, Schema ID and Schema or Raw Offset. stream->Reserve(12); - type.Write(writer, obj); + BType::Write(writer, obj); writerImpl.PostWrite(); http://git-wip-us.apache.org/repos/asf/ignite/blob/5c4d43c2/modules/platforms/cpp/core-test/include/ignite/binary_test_defs.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/include/ignite/binary_test_defs.h b/modules/platforms/cpp/core-test/include/ignite/binary_test_defs.h index 196c6d3..0870997 100644 --- a/modules/platforms/cpp/core-test/include/ignite/binary_test_defs.h +++ b/modules/platforms/cpp/core-test/include/ignite/binary_test_defs.h @@ -49,6 +49,8 @@ namespace ignite_test class BinaryOuter { public: + BinaryOuter(); + BinaryOuter(int32_t valIn, int32_t valOut); BinaryInner GetInner() const; @@ -141,175 +143,175 @@ namespace ignite template<> struct BinaryType<gt::BinaryDummy> { - int32_t GetTypeId() + static int32_t GetTypeId() { return GetBinaryStringHashCode("BinaryDummy"); } - std::string GetTypeName() + static void GetTypeName(std::string& dst) { - return "BinaryDummy"; + dst = "BinaryDummy"; } - int32_t GetFieldId(const char* name) + static int32_t GetFieldId(const char* name) { return GetBinaryStringHashCode(name); } - int32_t GetHashCode(const gt::BinaryInner& obj) + static int32_t GetHashCode(const gt::BinaryDummy& obj) { - return obj.GetValue(); + return 0; } - bool IsNull(const gt::BinaryInner& obj) + static bool IsNull(const gt::BinaryDummy& obj) { - return obj.GetValue() == 0; + return false; } - gt::BinaryInner GetNull() + static void GetNull(gt::BinaryDummy& dst) { - return gt::BinaryInner(0); + dst = gt::BinaryDummy(); } - void Write(BinaryWriter& writer, const gt::BinaryDummy& obj) + static void Write(BinaryWriter& writer, const gt::BinaryDummy& obj) { // No-op. } - gt::BinaryDummy Read(BinaryReader& reader) + static void Read(BinaryReader& reader, gt::BinaryDummy& dst) { - return gt::BinaryDummy(); + dst = gt::BinaryDummy(); } }; template<> struct BinaryType<gt::BinaryInner> { - int32_t GetTypeId() + static int32_t GetTypeId() { return GetBinaryStringHashCode("BinaryInner"); } - std::string GetTypeName() + static void GetTypeName(std::string& dst) { - return "BinaryInner"; + dst = "BinaryInner"; } - int32_t GetFieldId(const char* name) + static int32_t GetFieldId(const char* name) { return GetBinaryStringHashCode(name); } - int32_t GetHashCode(const gt::BinaryInner& obj) + static int32_t GetHashCode(const gt::BinaryInner& obj) { return obj.GetValue(); } - bool IsNull(const gt::BinaryInner& obj) + static bool IsNull(const gt::BinaryInner& obj) { return obj.GetValue() == 0; } - gt::BinaryInner GetNull() + static void GetNull(gt::BinaryInner& dst) { - return gt::BinaryInner(0); + dst = gt::BinaryInner(0); } - void Write(BinaryWriter& writer, const gt::BinaryInner& obj) + static void Write(BinaryWriter& writer, const gt::BinaryInner& obj) { writer.WriteInt32("val", obj.GetValue()); } - gt::BinaryInner Read(BinaryReader& reader) + static void Read(BinaryReader& reader, gt::BinaryInner& dst) { int val = reader.ReadInt32("val"); - return gt::BinaryInner(val); + dst = gt::BinaryInner(val); } }; template<> struct BinaryType<gt::BinaryOuter> { - int32_t GetTypeId() + static int32_t GetTypeId() { return GetBinaryStringHashCode("BinaryOuter"); } - std::string GetTypeName() + static void GetTypeName(std::string& dst) { - return "BinaryOuter"; + dst = "BinaryOuter"; } - int32_t GetFieldId(const char* name) + static int32_t GetFieldId(const char* name) { return GetBinaryStringHashCode(name); } - int32_t GetHashCode(const gt::BinaryOuter& obj) + static int32_t GetHashCode(const gt::BinaryOuter& obj) { return obj.GetValue() + obj.GetInner().GetValue(); } - bool IsNull(const gt::BinaryOuter& obj) + static bool IsNull(const gt::BinaryOuter& obj) { return obj.GetValue() == 0 && obj.GetInner().GetValue(); } - gt::BinaryOuter GetNull() + static void GetNull(gt::BinaryOuter& dst) { - return gt::BinaryOuter(0, 0); + dst = gt::BinaryOuter(0, 0); } - void Write(BinaryWriter& writer, const gt::BinaryOuter& obj) + static void Write(BinaryWriter& writer, const gt::BinaryOuter& obj) { writer.WriteObject("inner", obj.GetInner()); writer.WriteInt32("val", obj.GetValue()); } - gt::BinaryOuter Read(BinaryReader& reader) + static void Read(BinaryReader& reader, gt::BinaryOuter& dst) { gt::BinaryInner inner = reader.ReadObject<gt::BinaryInner>("inner"); int val = reader.ReadInt32("val"); - return gt::BinaryOuter(inner.GetValue(), val); + dst = gt::BinaryOuter(inner.GetValue(), val); } }; template<> struct BinaryType<gt::BinaryFields> { - int32_t GetTypeId() + static int32_t GetTypeId() { return GetBinaryStringHashCode("BinaryFields"); } - std::string GetTypeName() + static void GetTypeName(std::string& dst) { - return "BinaryFields"; + dst = "BinaryFields"; } - int32_t GetFieldId(const char* name) + static int32_t GetFieldId(const char* name) { return GetBinaryStringHashCode(name); } - int32_t GetHashCode(const gt::BinaryFields& obj) + static int32_t GetHashCode(const gt::BinaryFields& obj) { return obj.val1 + obj.val2 + obj.rawVal1 + obj.rawVal2; } - bool IsNull(const gt::BinaryFields& obj) + static bool IsNull(const gt::BinaryFields& obj) { return false; } - gt::BinaryFields GetNull() + static void GetNull(gt::BinaryFields&) { throw std::runtime_error("Must not be called."); } - void Write(BinaryWriter& writer, const gt::BinaryFields& obj) + static void Write(BinaryWriter& writer, const gt::BinaryFields& obj) { writer.WriteInt32("val1", obj.val1); writer.WriteInt32("val2", obj.val2); @@ -320,7 +322,7 @@ namespace ignite rawWriter.WriteInt32(obj.rawVal2); } - gt::BinaryFields Read(BinaryReader& reader) + static void Read(BinaryReader& reader, gt::BinaryFields& dst) { int32_t val1 = reader.ReadInt32("val1"); int32_t val2 = reader.ReadInt32("val2"); @@ -330,44 +332,44 @@ namespace ignite int32_t rawVal1 = rawReader.ReadInt32(); int32_t rawVal2 = rawReader.ReadInt32(); - return gt::BinaryFields(val1, val2, rawVal1, rawVal2); + dst = gt::BinaryFields(val1, val2, rawVal1, rawVal2); } }; template<> struct BinaryType<gt::PureRaw> { - int32_t GetTypeId() + static int32_t GetTypeId() { return GetBinaryStringHashCode("PureRaw"); } - std::string GetTypeName() + static void GetTypeName(std::string& dst) { - return "PureRaw"; + dst = "PureRaw"; } - int32_t GetFieldId(const char* name) + static int32_t GetFieldId(const char* name) { return GetBinaryStringHashCode(name); } - int32_t GetHashCode(const gt::PureRaw& obj) + static int32_t GetHashCode(const gt::PureRaw& obj) { return GetBinaryStringHashCode(obj.val1.c_str()) ^ obj.val2; } - bool IsNull(const gt::PureRaw& obj) + static bool IsNull(const gt::PureRaw& obj) { return false; } - gt::PureRaw GetNull() + static void GetNull(gt::PureRaw&) { throw std::runtime_error("Must not be called."); } - void Write(BinaryWriter& writer, const gt::PureRaw& obj) + static void Write(BinaryWriter& writer, const gt::PureRaw& obj) { BinaryRawWriter rawWriter = writer.RawWriter(); @@ -375,15 +377,12 @@ namespace ignite rawWriter.WriteInt32(obj.val2); } - gt::PureRaw Read(BinaryReader& reader) + static void Read(BinaryReader& reader, gt::PureRaw& dst) { BinaryRawReader rawReader = reader.RawReader(); - gt::PureRaw res; - res.val1 = rawReader.ReadString(); - res.val2 = rawReader.ReadInt32(); - - return res; + dst.val1 = rawReader.ReadString(); + dst.val2 = rawReader.ReadInt32(); } }; } http://git-wip-us.apache.org/repos/asf/ignite/blob/5c4d43c2/modules/platforms/cpp/core-test/include/ignite/complex_type.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/include/ignite/complex_type.h b/modules/platforms/cpp/core-test/include/ignite/complex_type.h index cb4a8a1..e1a0351 100644 --- a/modules/platforms/cpp/core-test/include/ignite/complex_type.h +++ b/modules/platforms/cpp/core-test/include/ignite/complex_type.h @@ -18,11 +18,9 @@ #ifndef _IGNITE_ODBC_TEST_COMPLEX_TYPE #define _IGNITE_ODBC_TEST_COMPLEX_TYPE +#include <stdint.h> #include <string> -#include "ignite/ignite.h" -#include "ignite/ignition.h" - namespace ignite { struct InnerObject @@ -81,20 +79,16 @@ namespace ignite IGNITE_BINARY_IS_NULL_FALSE(InnerObject) IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(InnerObject) - void Write(BinaryWriter& writer, InnerObject obj) + static void Write(BinaryWriter& writer, const InnerObject& obj) { writer.WriteInt32("f1", obj.f1); writer.WriteString("f2", obj.f2); } - InnerObject Read(BinaryReader& reader) + static void Read(BinaryReader& reader, InnerObject& dst) { - InnerObject obj; - - obj.f1 = reader.ReadInt32("f1"); - obj.f2 = reader.ReadString("f2"); - - return obj; + dst.f1 = reader.ReadInt32("f1"); + dst.f2 = reader.ReadString("f2"); } IGNITE_BINARY_TYPE_END @@ -110,22 +104,18 @@ namespace ignite IGNITE_BINARY_IS_NULL_FALSE(ComplexType) IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(ComplexType) - void Write(BinaryWriter& writer, ComplexType obj) + static void Write(BinaryWriter& writer, const ComplexType& obj) { writer.WriteInt32("i32Field", obj.i32Field); writer.WriteObject("objField", obj.objField); writer.WriteString("strField", obj.strField); } - ComplexType Read(BinaryReader& reader) + static void Read(BinaryReader& reader, ComplexType& dst) { - ComplexType obj; - - obj.i32Field = reader.ReadInt32("i32Field"); - obj.objField = reader.ReadObject<InnerObject>("objField"); - obj.strField = reader.ReadString("strField"); - - return obj; + dst.i32Field = reader.ReadInt32("i32Field"); + dst.objField = reader.ReadObject<InnerObject>("objField"); + dst.strField = reader.ReadString("strField"); } IGNITE_BINARY_TYPE_END http://git-wip-us.apache.org/repos/asf/ignite/blob/5c4d43c2/modules/platforms/cpp/core-test/include/ignite/test_type.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/include/ignite/test_type.h b/modules/platforms/cpp/core-test/include/ignite/test_type.h index d1dd967..40ada55 100644 --- a/modules/platforms/cpp/core-test/include/ignite/test_type.h +++ b/modules/platforms/cpp/core-test/include/ignite/test_type.h @@ -111,7 +111,7 @@ namespace ignite IGNITE_BINARY_IS_NULL_FALSE(TestType) IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(TestType) - void Write(BinaryWriter& writer, TestType obj) + static void Write(BinaryWriter& writer, const TestType& obj) { if (!obj.allNulls) { @@ -154,32 +154,27 @@ namespace ignite } } - TestType Read(BinaryReader& reader) + static void Read(BinaryReader& reader, TestType& dst) { - int8_t i8Field = reader.ReadInt8("i8Field"); - int16_t i16Field = reader.ReadInt16("i16Field"); - int32_t i32Field = reader.ReadInt32("i32Field"); - int64_t i64Field = reader.ReadInt64("i64Field"); - std::string strField = reader.ReadString("strField"); - float floatField = reader.ReadFloat("floatField"); - double doubleField = reader.ReadDouble("doubleField"); - bool boolField = reader.ReadBool("boolField"); - Guid guidField = reader.ReadGuid("guidField"); - Date dateField = reader.ReadDate("dateField"); - Time timeField = reader.ReadTime("timeField"); - Timestamp timestampField = reader.ReadTimestamp("timestampField"); - - TestType result(i8Field, i16Field, i32Field, i64Field, strField, - floatField, doubleField, boolField, guidField, dateField, - timeField, timestampField); + dst.i8Field = reader.ReadInt8("i8Field"); + dst.i16Field = reader.ReadInt16("i16Field"); + dst.i32Field = reader.ReadInt32("i32Field"); + dst.i64Field = reader.ReadInt64("i64Field"); + dst.strField = reader.ReadString("strField"); + dst.floatField = reader.ReadFloat("floatField"); + dst.doubleField = reader.ReadDouble("doubleField"); + dst.boolField = reader.ReadBool("boolField"); + dst.guidField = reader.ReadGuid("guidField"); + dst.dateField = reader.ReadDate("dateField"); + dst.timeField = reader.ReadTime("timeField"); + dst.timestampField = reader.ReadTimestamp("timestampField"); int32_t len = reader.ReadInt8Array("i8ArrayField", 0, 0); if (len > 0) { - result.i8ArrayField.resize(len); - reader.ReadInt8Array("i8ArrayField", &result.i8ArrayField[0], len); + dst.i8ArrayField.resize(len); + reader.ReadInt8Array("i8ArrayField", &dst.i8ArrayField[0], len); } - return result; } IGNITE_BINARY_TYPE_END http://git-wip-us.apache.org/repos/asf/ignite/blob/5c4d43c2/modules/platforms/cpp/core-test/src/binary_identity_resolver_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/src/binary_identity_resolver_test.cpp b/modules/platforms/cpp/core-test/src/binary_identity_resolver_test.cpp index 55b77bd..802ec97 100644 --- a/modules/platforms/cpp/core-test/src/binary_identity_resolver_test.cpp +++ b/modules/platforms/cpp/core-test/src/binary_identity_resolver_test.cpp @@ -198,18 +198,14 @@ namespace ignite IGNITE_BINARY_IS_NULL_FALSE(DefaultHashing) IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(DefaultHashing) - void Write(BinaryWriter& writer, const DefaultHashing& obj) + static void Write(BinaryWriter& writer, const DefaultHashing& obj) { writer.WriteInt32("field", obj.field); } - DefaultHashing Read(BinaryReader& reader) + static void Read(BinaryReader& reader, DefaultHashing& dst) { - DefaultHashing val; - - val.field = reader.ReadInt32("field"); - - return val; + dst.field = reader.ReadInt32("field"); } }; @@ -222,23 +218,19 @@ namespace ignite IGNITE_BINARY_IS_NULL_FALSE(GetHashDefined) IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(GetHashDefined) - int32_t GetHashCode(const GetHashDefined& obj) + static int32_t GetHashCode(const GetHashDefined& obj) { return obj.field * 10; } - void Write(BinaryWriter& writer, const GetHashDefined& obj) + static void Write(BinaryWriter& writer, const GetHashDefined& obj) { writer.WriteInt32("field", obj.field); } - GetHashDefined Read(BinaryReader& reader) + static void Read(BinaryReader& reader, GetHashDefined& dst) { - GetHashDefined val; - - val.field = reader.ReadInt32("field"); - - return val; + dst.field = reader.ReadInt32("field"); } }; @@ -251,23 +243,19 @@ namespace ignite IGNITE_BINARY_IS_NULL_FALSE(ResolverDefined) IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(ResolverDefined) - ignite::Reference<ignite::binary::BinaryIdentityResolver> GetIdentityResolver() + static ignite::Reference<ignite::binary::BinaryIdentityResolver> GetIdentityResolver() { return ignite::MakeReferenceFromCopy(CustomIdResolver()); } - void Write(BinaryWriter& writer, const ResolverDefined& obj) + static void Write(BinaryWriter& writer, const ResolverDefined& obj) { writer.WriteInt32("field", obj.field); } - ResolverDefined Read(BinaryReader& reader) + static void Read(BinaryReader& reader, ResolverDefined& dst) { - ResolverDefined val; - - val.field = reader.ReadInt32("field"); - - return val; + dst.field = reader.ReadInt32("field"); } }; @@ -280,28 +268,24 @@ namespace ignite IGNITE_BINARY_IS_NULL_FALSE(BothDefined) IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(BothDefined) - int32_t GetHashCode(const GetHashDefined& obj) + static int32_t GetHashCode(const GetHashDefined& obj) { return obj.field * 10; } - ignite::Reference<ignite::binary::BinaryIdentityResolver> GetIdentityResolver() + static ignite::Reference<ignite::binary::BinaryIdentityResolver> GetIdentityResolver() { return ignite::MakeReferenceFromCopy(CustomIdResolver()); } - void Write(BinaryWriter& writer, const BothDefined& obj) + static void Write(BinaryWriter& writer, const BothDefined& obj) { writer.WriteInt32("field", obj.field); } - BothDefined Read(BinaryReader& reader) + static void Read(BinaryReader& reader, BothDefined& dst) { - BothDefined val; - - val.field = reader.ReadInt32("field"); - - return val; + dst.field = reader.ReadInt32("field"); } }; @@ -318,22 +302,18 @@ namespace ignite IGNITE_BINARY_IS_NULL_FALSE(CompositeKey) IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(CompositeKey) - void Write(BinaryWriter& writer, const CompositeKey& obj) + static void Write(BinaryWriter& writer, const CompositeKey& obj) { writer.WriteString("str", obj.str); writer.WriteTimestamp("ts", obj.ts); writer.WriteGuid("guid", obj.guid); } - CompositeKey Read(BinaryReader& reader) + static void Read(BinaryReader& reader, CompositeKey& dst) { - CompositeKey val; - - val.str = reader.ReadString("str"); - val.ts = reader.ReadTimestamp("ts"); - val.guid = reader.ReadGuid("guid"); - - return val; + dst.str = reader.ReadString("str"); + dst.ts = reader.ReadTimestamp("ts"); + dst.guid = reader.ReadGuid("guid"); } }; @@ -349,22 +329,18 @@ namespace ignite IGNITE_BINARY_IS_NULL_FALSE(CompositeKeySimple) IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(CompositeKeySimple) - void Write(BinaryWriter& writer, const CompositeKeySimple& obj) + static void Write(BinaryWriter& writer, const CompositeKeySimple& obj) { writer.WriteString("str", obj.str); writer.WriteTimestamp("ts", obj.ts); writer.WriteInt64("i64", obj.i64); } - CompositeKeySimple Read(BinaryReader& reader) + static void Read(BinaryReader& reader, CompositeKeySimple& dst) { - CompositeKeySimple val; - - val.str = reader.ReadString("str"); - val.ts = reader.ReadTimestamp("ts"); - val.i64 = reader.ReadInt64("i64"); - - return val; + dst.str = reader.ReadString("str"); + dst.ts = reader.ReadTimestamp("ts"); + dst.i64 = reader.ReadInt64("i64"); } }; @@ -380,27 +356,23 @@ namespace ignite IGNITE_BINARY_IS_NULL_FALSE(ComplexType2) IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(ComplexType2) - ignite::Reference<ignite::binary::BinaryIdentityResolver> GetIdentityResolver() + static ignite::Reference<ignite::binary::BinaryIdentityResolver> GetIdentityResolver() { return ignite::MakeReferenceFromCopy(CustomFieldIdResolver()); } - void Write(BinaryWriter& writer, ComplexType2 obj) + static void Write(BinaryWriter& writer, const ComplexType2& obj) { writer.WriteInt32("i32Field", obj.i32Field); writer.WriteObject("objField", obj.objField); writer.WriteString("strField", obj.strField); } - ComplexType2 Read(BinaryReader& reader) + static void Read(BinaryReader& reader, ComplexType2& dst) { - ComplexType2 obj; - - obj.i32Field = reader.ReadInt32("i32Field"); - obj.objField = reader.ReadObject<InnerObject>("objField"); - obj.strField = reader.ReadString("strField"); - - return obj; + dst.i32Field = reader.ReadInt32("i32Field"); + dst.objField = reader.ReadObject<InnerObject>("objField"); + dst.strField = reader.ReadString("strField"); } }; } http://git-wip-us.apache.org/repos/asf/ignite/blob/5c4d43c2/modules/platforms/cpp/core-test/src/binary_object_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/src/binary_object_test.cpp b/modules/platforms/cpp/core-test/src/binary_object_test.cpp index bc30428..16e8c83 100644 --- a/modules/platforms/cpp/core-test/src/binary_object_test.cpp +++ b/modules/platforms/cpp/core-test/src/binary_object_test.cpp @@ -86,9 +86,7 @@ void GetObjectData(const T& obj, common::FixedSizeArray<int8_t>& data) BinaryWriterImpl writerImpl(&stream, &idResolver, 0, 0, 0); BinaryWriter writer(&writerImpl); - BinaryType<T> bt; - - bt.Write(writer, obj); + BinaryType<T>::Write(writer, obj); data.Assign(mem.Data(), stream.Position()); } http://git-wip-us.apache.org/repos/asf/ignite/blob/5c4d43c2/modules/platforms/cpp/core-test/src/binary_test_defs.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/src/binary_test_defs.cpp b/modules/platforms/cpp/core-test/src/binary_test_defs.cpp index 500ecd8..932f486 100644 --- a/modules/platforms/cpp/core-test/src/binary_test_defs.cpp +++ b/modules/platforms/cpp/core-test/src/binary_test_defs.cpp @@ -46,6 +46,11 @@ namespace ignite_test return val; } + BinaryOuter::BinaryOuter() + { + // No-op. + } + BinaryOuter::BinaryOuter(int32_t valIn, int32_t valOut) : inner(valIn), val(valOut) { // No-op. http://git-wip-us.apache.org/repos/asf/ignite/blob/5c4d43c2/modules/platforms/cpp/core-test/src/cache_invoke_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/src/cache_invoke_test.cpp b/modules/platforms/cpp/core-test/src/cache_invoke_test.cpp index 4f1f30a..81261b3 100644 --- a/modules/platforms/cpp/core-test/src/cache_invoke_test.cpp +++ b/modules/platforms/cpp/core-test/src/cache_invoke_test.cpp @@ -133,16 +133,16 @@ namespace ignite IGNITE_BINARY_IS_NULL_FALSE(CacheEntryModifier) IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(CacheEntryModifier) - void Write(BinaryWriter& writer, CacheEntryModifier obj) + static void Write(BinaryWriter& writer, const CacheEntryModifier& obj) { writer.WriteInt32("num", obj.GetNum()); } - CacheEntryModifier Read(BinaryReader& reader) + static void Read(BinaryReader& reader, CacheEntryModifier& dst) { int num = reader.ReadInt32("num"); - return CacheEntryModifier(num); + dst = CacheEntryModifier(num); } IGNITE_BINARY_TYPE_END } @@ -244,16 +244,16 @@ namespace ignite IGNITE_BINARY_IS_NULL_FALSE(Divisor) IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(Divisor) - void Write(BinaryWriter& writer, Divisor obj) + static void Write(BinaryWriter& writer, const Divisor& obj) { writer.WriteDouble("scale", obj.GetScale()); } - Divisor Read(BinaryReader& reader) + static void Read(BinaryReader& reader, Divisor& dst) { double scale = reader.ReadDouble("scale"); - return Divisor(scale); + dst = Divisor(scale); } IGNITE_BINARY_TYPE_END } @@ -365,16 +365,16 @@ namespace ignite IGNITE_BINARY_IS_NULL_FALSE(CharRemover) IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(CharRemover) - void Write(BinaryWriter& writer, CharRemover obj) + static void Write(BinaryWriter& writer, const CharRemover& obj) { writer.WriteInt8("toRemove", obj.GetCharToRemove()); } - CharRemover Read(BinaryReader& reader) + static void Read(BinaryReader& reader, CharRemover& dst) { char toRemove = static_cast<char>(reader.ReadInt8("toRemove")); - return CharRemover(toRemove); + dst = CharRemover(toRemove); } IGNITE_BINARY_TYPE_END } http://git-wip-us.apache.org/repos/asf/ignite/blob/5c4d43c2/modules/platforms/cpp/core-test/src/cache_query_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/src/cache_query_test.cpp b/modules/platforms/cpp/core-test/src/cache_query_test.cpp index 871f66a..328efd9 100644 --- a/modules/platforms/cpp/core-test/src/cache_query_test.cpp +++ b/modules/platforms/cpp/core-test/src/cache_query_test.cpp @@ -249,7 +249,7 @@ namespace ignite IGNITE_BINARY_IS_NULL_FALSE(QueryPerson) IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(QueryPerson) - void Write(BinaryWriter& writer, QueryPerson obj) + static void Write(BinaryWriter& writer, const QueryPerson& obj) { writer.WriteString("name", obj.GetName()); writer.WriteInt32("age", obj.GetAge()); @@ -257,14 +257,14 @@ namespace ignite writer.WriteTimestamp("recordCreated", obj.GetCreationTime()); } - QueryPerson Read(BinaryReader& reader) + static void Read(BinaryReader& reader, QueryPerson& dst) { std::string name = reader.ReadString("name"); int age = reader.ReadInt32("age"); Date birthday = reader.ReadDate("birthday"); Timestamp recordCreated = reader.ReadTimestamp("recordCreated"); - return QueryPerson(name, age, birthday, recordCreated); + dst = QueryPerson(name, age, birthday, recordCreated); } IGNITE_BINARY_TYPE_END @@ -279,18 +279,18 @@ namespace ignite IGNITE_BINARY_IS_NULL_FALSE(QueryRelation) IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(QueryRelation) - void Write(BinaryWriter& writer, QueryRelation obj) + static void Write(BinaryWriter& writer, QueryRelation obj) { writer.WriteInt32("personId", obj.GetPersonId()); writer.WriteInt32("someVal", obj.GetHobbyId()); } - QueryRelation Read(BinaryReader& reader) + static void Read(BinaryReader& reader, QueryRelation& dst) { int32_t personId = reader.ReadInt32("personId"); int32_t someVal = reader.ReadInt32("someVal"); - return QueryRelation(personId, someVal); + dst = QueryRelation(personId, someVal); } IGNITE_BINARY_TYPE_END } http://git-wip-us.apache.org/repos/asf/ignite/blob/5c4d43c2/modules/platforms/cpp/core-test/src/cache_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/src/cache_test.cpp b/modules/platforms/cpp/core-test/src/cache_test.cpp index fef777a..99e0f1b 100644 --- a/modules/platforms/cpp/core-test/src/cache_test.cpp +++ b/modules/platforms/cpp/core-test/src/cache_test.cpp @@ -50,26 +50,24 @@ namespace ignite namespace binary { IGNITE_BINARY_TYPE_START(Person) - IGNITE_BINARY_GET_TYPE_ID_AS_HASH(Person) - IGNITE_BINARY_GET_TYPE_NAME_AS_IS(Person) - IGNITE_BINARY_GET_FIELD_ID_AS_HASH - IGNITE_BINARY_GET_HASH_CODE_ZERO(Person) - IGNITE_BINARY_IS_NULL_FALSE(Person) - IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(Person) - - void Write(BinaryWriter& writer, Person obj) - { - writer.WriteString("name", obj.name); - writer.WriteInt32("age", obj.age); - } - - Person Read(BinaryReader& reader) - { - std::string name = reader.ReadString("name"); - int age = reader.ReadInt32("age"); - - return Person(name, age); - } + IGNITE_BINARY_GET_TYPE_ID_AS_HASH(Person) + IGNITE_BINARY_GET_TYPE_NAME_AS_IS(Person) + IGNITE_BINARY_GET_FIELD_ID_AS_HASH + IGNITE_BINARY_GET_HASH_CODE_ZERO(Person) + IGNITE_BINARY_IS_NULL_FALSE(Person) + IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(Person) + + static void Write(BinaryWriter& writer, const Person& obj) + { + writer.WriteString("name", obj.name); + writer.WriteInt32("age", obj.age); + } + + static void Read(BinaryReader& reader, Person& dst) + { + dst.name = reader.ReadString("name"); + dst.age = reader.ReadInt32("age"); + } IGNITE_BINARY_TYPE_END } http://git-wip-us.apache.org/repos/asf/ignite/blob/5c4d43c2/modules/platforms/cpp/core-test/src/continuous_query_test.cpp ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core-test/src/continuous_query_test.cpp b/modules/platforms/cpp/core-test/src/continuous_query_test.cpp index f81eb5d..8579c54 100644 --- a/modules/platforms/cpp/core-test/src/continuous_query_test.cpp +++ b/modules/platforms/cpp/core-test/src/continuous_query_test.cpp @@ -269,62 +269,58 @@ namespace ignite IGNITE_BINARY_IS_NULL_FALSE(TestEntry) IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(TestEntry) - void Write(BinaryWriter& writer, const TestEntry& obj) + static void Write(BinaryWriter& writer, const TestEntry& obj) { writer.WriteInt32("value", obj.value); } - TestEntry Read(BinaryReader& reader) + static void Read(BinaryReader& reader, TestEntry& dst) { - TestEntry res; - res.value = reader.ReadInt32("value"); - - return res; + dst.value = reader.ReadInt32("value"); } }; template<typename K, typename V> struct BinaryType< RangeFilter<K,V> > { - int32_t GetTypeId() + static int32_t GetTypeId() { return GetBinaryStringHashCode("RangeFilter"); } - std::string GetTypeName() + static void GetTypeName(std::string& dst) { - return "RangeFilter"; + dst = "RangeFilter"; } + IGNITE_BINARY_GET_FIELD_ID_AS_HASH - int32_t GetHashCode(const RangeFilter<K,V>&) + static int32_t GetHashCode(const RangeFilter<K,V>&) { return 0; } - bool IsNull(const RangeFilter<K,V>&) + static bool IsNull(const RangeFilter<K,V>&) { return false; } - RangeFilter<K,V> GetNull() + static void GetNull(RangeFilter<K, V>& dst) { - return RangeFilter<K,V>(); + dst = RangeFilter<K,V>(); } - void Write(BinaryWriter& writer, const RangeFilter<K,V>& obj) + static void Write(BinaryWriter& writer, const RangeFilter<K,V>& obj) { writer.WriteObject("rangeBegin", obj.rangeBegin); writer.WriteObject("rangeEnd", obj.rangeEnd); } - RangeFilter<K,V> Read(BinaryReader& reader) + static void Read(BinaryReader& reader, RangeFilter<K, V>& dst) { - K begin = reader.ReadObject<K>("rangeBegin"); - K end = reader.ReadObject<K>("rangeEnd"); - - return RangeFilter<K,V>(begin, end); + dst.rangeBegin = reader.ReadObject<K>("rangeBegin"); + dst.rangeEnd = reader.ReadObject<K>("rangeEnd"); } }; } http://git-wip-us.apache.org/repos/asf/ignite/blob/5c4d43c2/modules/platforms/cpp/core/include/ignite/ignite_binding.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/include/ignite/ignite_binding.h b/modules/platforms/cpp/core/include/ignite/ignite_binding.h index a84a1c1..70bdedb 100644 --- a/modules/platforms/cpp/core/include/ignite/ignite_binding.h +++ b/modules/platforms/cpp/core/include/ignite/ignite_binding.h @@ -80,13 +80,12 @@ namespace ignite template<typename P> void RegisterCacheEntryProcessor(IgniteError& err) { - binary::BinaryType<P> bt; impl::IgniteBindingImpl *im = impl.Get(); if (im) { im->RegisterCallback(impl::IgniteBindingImpl::CACHE_ENTRY_PROCESSOR_APPLY, - bt.GetTypeId(), impl::binding::ListenerApply<P, typename P::KeyType, + binary::BinaryType<P>::GetTypeId(), impl::binding::ListenerApply<P, typename P::KeyType, typename P::ValueType, typename P::ReturnType, typename P::ArgumentType>, err); } else @@ -105,10 +104,9 @@ namespace ignite template<typename F> void RegisterCacheEntryEventFilter() { - binary::BinaryType<F> bt; impl::IgniteBindingImpl *im = impl.Get(); - int32_t typeId = bt.GetTypeId(); + int32_t typeId = binary::BinaryType<F>::GetTypeId(); if (im) { http://git-wip-us.apache.org/repos/asf/ignite/blob/5c4d43c2/modules/platforms/cpp/core/include/ignite/impl/cache/cache_entry_processor_holder.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/core/include/ignite/impl/cache/cache_entry_processor_holder.h b/modules/platforms/cpp/core/include/ignite/impl/cache/cache_entry_processor_holder.h index c979b4a..decbaa9 100644 --- a/modules/platforms/cpp/core/include/ignite/impl/cache/cache_entry_processor_holder.h +++ b/modules/platforms/cpp/core/include/ignite/impl/cache/cache_entry_processor_holder.h @@ -191,7 +191,7 @@ namespace ignite IGNITE_BINARY_IS_NULL_FALSE(UnderlyingType) IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(UnderlyingType) - int32_t GetTypeId() + static int32_t GetTypeId() { static bool typeIdInited = false; static int32_t typeId; @@ -205,13 +205,16 @@ namespace ignite if (typeIdInited) return typeId; - typeId = GetBinaryStringHashCode(GetTypeName().c_str()); + std::string typeName; + GetTypeName(typeName); + + typeId = GetBinaryStringHashCode(typeName.c_str()); typeIdInited = true; return typeId; } - std::string GetTypeName() + static void GetTypeName(std::string& dst) { // Using static variable and only initialize it once for better // performance. Type name can't change in the course of the @@ -221,17 +224,25 @@ namespace ignite // Name has been constructed already. Return it. if (!name.empty()) - return name; + { + dst = name; + + return; + } common::concurrent::CsLockGuard guard(initLock); if (!name.empty()) - return name; + { + dst = name; + + return; + } // Constructing name here. - BinaryType<P> p; + std::string procName; - std::string procName = p.GetTypeName(); + BinaryType<P>::GetTypeName(procName); // -1 is for unnessecary null byte at the end of the C-string. name.reserve(sizeof("CacheEntryProcessorHolder<>") - 1 + procName.size()); @@ -240,10 +251,10 @@ namespace ignite // forbidden to register the same processor type several times. name.append("CacheEntryProcessorHolder<").append(procName).push_back('>'); - return name; + dst = name; } - void Write(BinaryWriter& writer, UnderlyingType obj) + static void Write(BinaryWriter& writer, const UnderlyingType& obj) { BinaryRawWriter raw = writer.RawWriter(); @@ -251,14 +262,14 @@ namespace ignite raw.WriteObject(obj.getArgument()); } - UnderlyingType Read(BinaryReader& reader) + static void Read(BinaryReader& reader, UnderlyingType& dst) { BinaryRawReader raw = reader.RawReader(); const P& proc = raw.ReadObject<P>(); const A& arg = raw.ReadObject<A>(); - return UnderlyingType(proc, arg); + dst = UnderlyingType(proc, arg); } }; } http://git-wip-us.apache.org/repos/asf/ignite/blob/5c4d43c2/modules/platforms/cpp/odbc-test/include/complex_type.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc-test/include/complex_type.h b/modules/platforms/cpp/odbc-test/include/complex_type.h index a84b033..dd68c9b 100644 --- a/modules/platforms/cpp/odbc-test/include/complex_type.h +++ b/modules/platforms/cpp/odbc-test/include/complex_type.h @@ -68,20 +68,16 @@ namespace ignite IGNITE_BINARY_IS_NULL_FALSE(TestObject) IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(TestObject) - void Write(BinaryWriter& writer, TestObject obj) + static void Write(BinaryWriter& writer, const TestObject& obj) { writer.WriteInt32("f1", obj.f1); writer.WriteString("f2", obj.f2); } - TestObject Read(BinaryReader& reader) + static void Read(BinaryReader& reader, TestObject& dst) { - TestObject obj; - - obj.f1 = reader.ReadInt32("f1"); - obj.f2 = reader.ReadString("f2"); - - return obj; + dst.f1 = reader.ReadInt32("f1"); + dst.f2 = reader.ReadString("f2"); } IGNITE_BINARY_TYPE_END @@ -97,22 +93,18 @@ namespace ignite IGNITE_BINARY_IS_NULL_FALSE(ComplexType) IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(ComplexType) - void Write(BinaryWriter& writer, ComplexType obj) + static void Write(BinaryWriter& writer, const ComplexType& obj) { writer.WriteInt32("i32Field", obj.i32Field); writer.WriteObject("objField", obj.objField); writer.WriteString("strField", obj.strField); } - ComplexType Read(BinaryReader& reader) + static void Read(BinaryReader& reader, ComplexType& dst) { - ComplexType obj; - - obj.i32Field = reader.ReadInt32("i32Field"); - obj.objField = reader.ReadObject<TestObject>("objField"); - obj.strField = reader.ReadString("strField"); - - return obj; + dst.i32Field = reader.ReadInt32("i32Field"); + dst.objField = reader.ReadObject<TestObject>("objField"); + dst.strField = reader.ReadString("strField"); } IGNITE_BINARY_TYPE_END http://git-wip-us.apache.org/repos/asf/ignite/blob/5c4d43c2/modules/platforms/cpp/odbc-test/include/test_type.h ---------------------------------------------------------------------- diff --git a/modules/platforms/cpp/odbc-test/include/test_type.h b/modules/platforms/cpp/odbc-test/include/test_type.h index 51271b5..7bc6b3e 100644 --- a/modules/platforms/cpp/odbc-test/include/test_type.h +++ b/modules/platforms/cpp/odbc-test/include/test_type.h @@ -111,7 +111,7 @@ namespace ignite IGNITE_BINARY_IS_NULL_FALSE(TestType) IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(TestType) - void Write(BinaryWriter& writer, TestType obj) + static void Write(BinaryWriter& writer, const TestType& obj) { if (!obj.allNulls) { @@ -154,32 +154,27 @@ namespace ignite } } - TestType Read(BinaryReader& reader) + static void Read(BinaryReader& reader, TestType& dst) { - int8_t i8Field = reader.ReadInt8("i8Field"); - int16_t i16Field = reader.ReadInt16("i16Field"); - int32_t i32Field = reader.ReadInt32("i32Field"); - int64_t i64Field = reader.ReadInt64("i64Field"); - std::string strField = reader.ReadString("strField"); - float floatField = reader.ReadFloat("floatField"); - double doubleField = reader.ReadDouble("doubleField"); - bool boolField = reader.ReadBool("boolField"); - Guid guidField = reader.ReadGuid("guidField"); - Date dateField = reader.ReadDate("dateField"); - Time timeField = reader.ReadTime("timeField"); - Timestamp timestampField = reader.ReadTimestamp("timestampField"); - - TestType result(i8Field, i16Field, i32Field, i64Field, strField, - floatField, doubleField, boolField, guidField, dateField, - timeField, timestampField); + dst.i8Field = reader.ReadInt8("i8Field"); + dst.i16Field = reader.ReadInt16("i16Field"); + dst.i32Field = reader.ReadInt32("i32Field"); + dst.i64Field = reader.ReadInt64("i64Field"); + dst.strField = reader.ReadString("strField"); + dst.floatField = reader.ReadFloat("floatField"); + dst.doubleField = reader.ReadDouble("doubleField"); + dst.boolField = reader.ReadBool("boolField"); + dst.guidField = reader.ReadGuid("guidField"); + dst.dateField = reader.ReadDate("dateField"); + dst.timeField = reader.ReadTime("timeField"); + dst.timestampField = reader.ReadTimestamp("timestampField"); int32_t len = reader.ReadInt8Array("i8ArrayField", 0, 0); if (len > 0) { - result.i8ArrayField.resize(len); - reader.ReadInt8Array("i8ArrayField", &result.i8ArrayField[0], len); + dst.i8ArrayField.resize(len); + reader.ReadInt8Array("i8ArrayField", &dst.i8ArrayField[0], len); } - return result; } IGNITE_BINARY_TYPE_END
