You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by is...@apache.org on 2019/04/17 16:07:49 UTC

[ignite] branch master updated: IGNITE-11703: Added default implementation of some BinaryType methods.

This is an automated email from the ASF dual-hosted git repository.

isapego pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new 806939e  IGNITE-11703: Added default implementation of some BinaryType methods.
806939e is described below

commit 806939e4c926cc599bb3d3a2e53766d3870916dc
Author: Igor Sapego <is...@apache.org>
AuthorDate: Wed Apr 17 19:06:07 2019 +0300

    IGNITE-11703: Added default implementation of some BinaryType methods.
    
    This closes #6435
---
 .../cpp/binary/include/ignite/binary/binary_type.h | 66 ++++++++++++++++
 .../include/ignite/impl/binary/binary_type_impl.h  |  2 +-
 .../core-test/include/ignite/binary_test_defs.h    | 88 ++++------------------
 .../platforms/cpp/core-test/src/compute_test.cpp   | 66 +---------------
 .../cpp/core-test/src/continuous_query_test.cpp    | 36 +++------
 .../impl/cache/cache_entry_processor_holder.h      |  5 +-
 .../compute-example/src/compute_example.cpp        | 27 +------
 .../src/continuous_query_example.cpp               | 23 +-----
 .../cpp/examples/include/ignite/examples/address.h | 31 +-------
 .../include/ignite/examples/organization.h         | 35 ++-------
 10 files changed, 108 insertions(+), 271 deletions(-)

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 14a95b6..84de648 100644
--- a/modules/platforms/cpp/binary/include/ignite/binary/binary_type.h
+++ b/modules/platforms/cpp/binary/include/ignite/binary/binary_type.h
@@ -149,6 +149,72 @@ namespace ignite
         struct IGNITE_IMPORT_EXPORT BinaryType { };
 
         /**
+         * Default implementations of BinaryType hashing functions.
+         */
+        template<typename T>
+        struct IGNITE_IMPORT_EXPORT BinaryTypeDefaultHashing
+        {
+            /**
+             * Get binary object type ID.
+             *
+             * @return Type ID.
+             */
+            static int32_t GetTypeId()
+            {
+                std::string typeName;
+                BinaryType<T>::GetTypeName(typeName);
+
+                return GetBinaryStringHashCode(typeName.c_str());
+            }
+
+            /**
+             * Get binary object field ID.
+             *
+             * @param name Field name.
+             * @return Field ID.
+             */
+            static int32_t GetFieldId(const char* name)
+            {
+                return GetBinaryStringHashCode(name);
+            }
+        };
+
+        /**
+         * Default implementations of BinaryType methods for non-null type.
+         */
+        template<typename T>
+        struct IGNITE_IMPORT_EXPORT BinaryTypeNonNullableType
+        {
+            /**
+             * Check whether passed binary object should be interpreted as NULL.
+             *
+             * @return True if binary object should be interpreted as NULL.
+             */
+            static bool IsNull(const T&)
+            {
+                return false;
+            }
+
+            /**
+             * Get NULL value for the given binary type.
+             *
+             * @param dst Null value for the type.
+             */
+            static void GetNull(T& dst)
+            {
+                dst = T();
+            }
+        };
+
+        /**
+         * Default implementations of BinaryType hashing functions and non-null type behaviour.
+         */
+        template<typename T>
+        struct IGNITE_IMPORT_EXPORT BinaryTypeDefaultAll :
+            BinaryTypeDefaultHashing<T>,
+            BinaryTypeNonNullableType<T> { };
+
+        /**
          * Templated binary type specification for pointers.
          */
         template <typename T>
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 e9bbace..c93ba20 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
@@ -45,7 +45,7 @@ namespace ignite
 
             static int32_t GetFieldId(const char* name);
 
-            static bool IsNull(const IgniteError& obj)
+            static bool IsNull(const IgniteError&)
             {
                 return false;
             }
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 9d7dcd2..51aeff0 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
@@ -27,14 +27,14 @@ namespace ignite_test
 {
     namespace core
     {
-        namespace binary 
+        namespace binary
         {
             class BinaryDummy
             {
                 // No-op.
             };
 
-            class BinaryInner 
+            class BinaryInner
             {
             public:
                 BinaryInner();
@@ -76,13 +76,13 @@ namespace ignite_test
                 BinaryFields(int32_t val1, int32_t val2, int32_t rawVal1, int32_t rawVal2) :
                     val1(val1), val2(val2), rawVal1(rawVal1), rawVal2(rawVal2)
                 {
-                    // No-op.   
+                    // No-op.
                 }
 
                 friend bool operator==(const BinaryFields& one, const BinaryFields& two)
                 {
-                    return one.val1 == two.val1 && one.val2 == two.val2 && 
-                        one.rawVal1 == two.rawVal1 &&one.rawVal2 == two.rawVal2;
+                    return one.val1 == two.val1 && one.val2 == two.val2 &&
+                        one.rawVal1 == two.rawVal1 && one.rawVal2 == two.rawVal2;
                 }
             };
 
@@ -141,62 +141,32 @@ namespace ignite
         namespace gt = ignite_test::core::binary;
 
         template<>
-        struct BinaryType<gt::BinaryDummy>
+        struct BinaryType<gt::BinaryDummy> : BinaryTypeDefaultAll<gt::BinaryDummy>
         {
-            static int32_t GetTypeId()
-            {
-                return GetBinaryStringHashCode("BinaryDummy");
-            }
-
             static void GetTypeName(std::string& dst)
             {
                 dst = "BinaryDummy";
             }
 
-            static int32_t GetFieldId(const char* name)
-            {
-                return GetBinaryStringHashCode(name);
-            }
-
-            static bool IsNull(const gt::BinaryInner& obj)
-            {
-                return false;
-            }
-
-            static void GetNull(gt::BinaryDummy& dst)
-            {
-                dst = gt::BinaryDummy();
-            }
-
             static void Write(BinaryWriter& writer, const gt::BinaryDummy& obj)
             {
                 // No-op.
             }
 
-            static void Read(BinaryReader& reader, gt::BinaryDummy& dst)
+            static void Read(BinaryReader&, gt::BinaryDummy& dst)
             {
                 dst = gt::BinaryDummy();
             }
         };
 
-        template<> 
-        struct BinaryType<gt::BinaryInner>
+        template<>
+        struct BinaryType<gt::BinaryInner> : BinaryTypeDefaultHashing<gt::BinaryInner>
         {
-            static int32_t GetTypeId()
-            { 
-                return GetBinaryStringHashCode("BinaryInner"); 
-            }
-
             static void GetTypeName(std::string& dst)
             {
                 dst = "BinaryInner";
             }
 
-            static int32_t GetFieldId(const char* name)
-            { 
-                return GetBinaryStringHashCode(name); 
-            }
-
             static bool IsNull(const gt::BinaryInner& obj)
             {
                 return obj.GetValue() == 0;
@@ -221,23 +191,13 @@ namespace ignite
         };
 
         template<>
-        struct BinaryType<gt::BinaryOuter>
+        struct BinaryType<gt::BinaryOuter> : BinaryTypeDefaultHashing<gt::BinaryOuter>
         {
-            static int32_t GetTypeId()
-            {
-                return GetBinaryStringHashCode("BinaryOuter");
-            }
-
             static void GetTypeName(std::string& dst)
             {
                 dst = "BinaryOuter";
             }
 
-            static int32_t GetFieldId(const char* name)
-            {
-                return GetBinaryStringHashCode(name);
-            }
-
             static bool IsNull(const gt::BinaryOuter& obj)
             {
                 return obj.GetValue() == 0 && obj.GetInner().GetValue();
@@ -251,7 +211,7 @@ namespace ignite
             static void Write(BinaryWriter& writer, const gt::BinaryOuter& obj)
             {
                 writer.WriteObject("inner", obj.GetInner());
-                writer.WriteInt32("val", obj.GetValue());                
+                writer.WriteInt32("val", obj.GetValue());
             }
 
             static void Read(BinaryReader& reader, gt::BinaryOuter& dst)
@@ -264,23 +224,13 @@ namespace ignite
         };
 
         template<>
-        struct BinaryType<gt::BinaryFields>
+        struct BinaryType<gt::BinaryFields> : BinaryTypeDefaultHashing<gt::BinaryFields>
         {
-            static int32_t GetTypeId()
-            {
-                return GetBinaryStringHashCode("BinaryFields");
-            }
-
             static void GetTypeName(std::string& dst)
             {
                 dst = "BinaryFields";
             }
 
-            static int32_t GetFieldId(const char* name)
-            {
-                return GetBinaryStringHashCode(name);
-            }
-
             static bool IsNull(const gt::BinaryFields& obj)
             {
                 return false;
@@ -317,23 +267,13 @@ namespace ignite
         };
 
         template<>
-        struct BinaryType<gt::PureRaw>
+        struct BinaryType<gt::PureRaw> : BinaryTypeDefaultHashing<gt::PureRaw>
         {
-            static int32_t GetTypeId()
-            {
-                return GetBinaryStringHashCode("PureRaw");
-            }
-
             static void GetTypeName(std::string& dst)
             {
                 dst = "PureRaw";
             }
 
-            static int32_t GetFieldId(const char* name)
-            {
-                return GetBinaryStringHashCode(name);
-            }
-
             static bool IsNull(const gt::PureRaw& obj)
             {
                 return false;
@@ -363,4 +303,4 @@ namespace ignite
     }
 }
 
-#endif
\ No newline at end of file
+#endif
diff --git a/modules/platforms/cpp/core-test/src/compute_test.cpp b/modules/platforms/cpp/core-test/src/compute_test.cpp
index 0a873f5..2055443 100644
--- a/modules/platforms/cpp/core-test/src/compute_test.cpp
+++ b/modules/platforms/cpp/core-test/src/compute_test.cpp
@@ -190,33 +190,13 @@ namespace ignite
     namespace binary
     {
         template<>
-        struct BinaryType<Func1>
+        struct BinaryType<Func1> : BinaryTypeDefaultAll<Func1>
         {
-            static int32_t GetTypeId()
-            {
-                return GetBinaryStringHashCode("Func1");
-            }
-
             static void GetTypeName(std::string& dst)
             {
                 dst = "Func1";
             }
 
-            static int32_t GetFieldId(const char* name)
-            {
-                return GetBinaryStringHashCode(name);
-            }
-
-            static bool IsNull(const Func1& obj)
-            {
-                return false;
-            }
-
-            static void GetNull(Func1& dst)
-            {
-                dst = Func1(0, 0);
-            }
-
             static void Write(BinaryWriter& writer, const Func1& obj)
             {
                 writer.WriteInt32("a", obj.a);
@@ -233,33 +213,13 @@ namespace ignite
         };
 
         template<>
-        struct BinaryType<Func2>
+        struct BinaryType<Func2> : BinaryTypeDefaultAll<Func2>
         {
-            static int32_t GetTypeId()
-            {
-                return GetBinaryStringHashCode("Func2");
-            }
-
             static void GetTypeName(std::string& dst)
             {
                 dst = "Func2";
             }
 
-            static int32_t GetFieldId(const char* name)
-            {
-                return GetBinaryStringHashCode(name);
-            }
-
-            static bool IsNull(const Func2& obj)
-            {
-                return false;
-            }
-
-            static void GetNull(Func2& dst)
-            {
-                dst = Func2(0, 0);
-            }
-
             static void Write(BinaryWriter& writer, const Func2& obj)
             {
                 writer.WriteInt32("a", obj.a);
@@ -276,33 +236,13 @@ namespace ignite
         };
 
         template<>
-        struct BinaryType<Func3>
+        struct BinaryType<Func3> : BinaryTypeDefaultAll<Func3>
         {
-            static int32_t GetTypeId()
-            {
-                return GetBinaryStringHashCode("Func3");
-            }
-
             static void GetTypeName(std::string& dst)
             {
                 dst = "Func3";
             }
 
-            static int32_t GetFieldId(const char* name)
-            {
-                return GetBinaryStringHashCode(name);
-            }
-
-            static bool IsNull(const Func3& obj)
-            {
-                return false;
-            }
-
-            static void GetNull(Func3& dst)
-            {
-                dst = Func3(0, 0);
-            }
-
             static void Write(BinaryWriter& writer, const Func3& obj)
             {
                 writer.WriteInt32("a", obj.a);
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 81ea0cf..62b0806 100644
--- a/modules/platforms/cpp/core-test/src/continuous_query_test.cpp
+++ b/modules/platforms/cpp/core-test/src/continuous_query_test.cpp
@@ -256,13 +256,12 @@ namespace ignite
     namespace binary
     {
         template<>
-        struct BinaryType<TestEntry>
+        struct BinaryType<TestEntry> : BinaryTypeDefaultAll<TestEntry>
         {
-            IGNITE_BINARY_GET_TYPE_ID_AS_HASH(TestEntry)
-            IGNITE_BINARY_GET_TYPE_NAME_AS_IS(TestEntry)
-            IGNITE_BINARY_GET_FIELD_ID_AS_HASH
-            IGNITE_BINARY_IS_NULL_FALSE(TestEntry)
-            IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(TestEntry)
+            static void GetTypeName(std::string& dst)
+            {
+                dst = "TestEntry";
+            }
 
             static void Write(BinaryWriter& writer, const TestEntry& obj)
             {
@@ -275,30 +274,17 @@ namespace ignite
             }
         };
 
-        template<typename K, typename V>
-        struct BinaryType< RangeFilter<K,V> >
+        namespace
         {
-            static int32_t GetTypeId()
-            {
-                return GetBinaryStringHashCode("RangeFilter");
-            }
+            extern const char typeName[] = "RangeFilter";
+        }
 
+        template<typename K, typename V>
+        struct BinaryType< RangeFilter<K,V> > : BinaryTypeDefaultAll< RangeFilter<K,V> >
+        {
             static void GetTypeName(std::string& dst)
             {
                 dst = "RangeFilter";
-
-            }
-
-            IGNITE_BINARY_GET_FIELD_ID_AS_HASH
-
-            static bool IsNull(const RangeFilter<K,V>&)
-            {
-                return false;
-            }
-
-            static void GetNull(RangeFilter<K, V>& dst)
-            {
-                dst = RangeFilter<K,V>();
             }
 
             static void Write(BinaryWriter& writer, const RangeFilter<K,V>& obj)
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 a821407..cfa0e55 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
@@ -186,13 +186,12 @@ namespace ignite
          * Binary type specialization for CacheEntryProcessorHolder.
          */
         template<typename P, typename A>
-        struct BinaryType<impl::cache::CacheEntryProcessorHolder<P, A> >
+        struct BinaryType<impl::cache::CacheEntryProcessorHolder<P, A> > :
+            BinaryTypeNonNullableType< impl::cache::CacheEntryProcessorHolder<P, A> >
         {
             typedef impl::cache::CacheEntryProcessorHolder<P, A> UnderlyingType;
 
             IGNITE_BINARY_GET_FIELD_ID_AS_HASH
-            IGNITE_BINARY_IS_NULL_FALSE(UnderlyingType)
-            IGNITE_BINARY_GET_NULL_DEFAULT_CTOR(UnderlyingType)
 
             static int32_t GetTypeId()
             {
diff --git a/modules/platforms/cpp/examples/compute-example/src/compute_example.cpp b/modules/platforms/cpp/examples/compute-example/src/compute_example.cpp
index e6bee8d..7ca6e02 100644
--- a/modules/platforms/cpp/examples/compute-example/src/compute_example.cpp
+++ b/modules/platforms/cpp/examples/compute-example/src/compute_example.cpp
@@ -79,38 +79,13 @@ namespace ignite
     namespace binary
     {
         template<>
-        struct BinaryType<CountWords>
+        struct BinaryType<CountWords>: BinaryTypeDefaultAll<CountWords>
         {
-            static int32_t GetTypeId()
-            {
-                return GetBinaryStringHashCode("CountWords");
-            }
-
             static void GetTypeName(std::string& dst)
             {
                 dst = "CountWords";
             }
 
-            static int32_t GetFieldId(const char* name)
-            {
-                return GetBinaryStringHashCode(name);
-            }
-
-            static int32_t GetHashCode(const CountWords& obj)
-            {
-                return 0;
-            }
-
-            static bool IsNull(const CountWords& obj)
-            {
-                return false;
-            }
-
-            static void GetNull(CountWords& dst)
-            {
-                dst = CountWords("");
-            }
-
             static void Write(BinaryWriter& writer, const CountWords& obj)
             {
                 writer.RawWriter().WriteString(obj.text);
diff --git a/modules/platforms/cpp/examples/continuous-query-example/src/continuous_query_example.cpp b/modules/platforms/cpp/examples/continuous-query-example/src/continuous_query_example.cpp
index 8670bf6..230d150 100644
--- a/modules/platforms/cpp/examples/continuous-query-example/src/continuous_query_example.cpp
+++ b/modules/platforms/cpp/examples/continuous-query-example/src/continuous_query_example.cpp
@@ -124,34 +124,15 @@ namespace ignite
     namespace binary
     {
         template<>
-        struct BinaryType< RangeFilter<int32_t, std::string> >
+        struct BinaryType< RangeFilter<int32_t, std::string> > :
+            BinaryTypeDefaultAll< RangeFilter<int32_t, std::string> >
         {
-            static int32_t GetTypeId()
-            {
-                return GetBinaryStringHashCode("RangeFilter<int32_t,std::string>");
-            }
-
             static void GetTypeName(std::string& dst)
             {
                 dst = "RangeFilter<int32_t,std::string>";
 
             }
 
-            static int32_t GetFieldId(const char* name)
-            {
-                return GetBinaryStringHashCode(name);
-            }
-
-            static bool IsNull(const RangeFilter<int32_t, std::string>&)
-            {
-                return false;
-            }
-
-            static void GetNull(RangeFilter<int32_t, std::string>& dst)
-            {
-                dst = RangeFilter<int32_t, std::string>();
-            }
-
             static void Write(BinaryWriter& writer, const RangeFilter<int32_t, std::string>& obj)
             {
                 writer.WriteInt32("rangeBegin", obj.rangeBegin);
diff --git a/modules/platforms/cpp/examples/include/ignite/examples/address.h b/modules/platforms/cpp/examples/include/ignite/examples/address.h
index 8f2689c..6f28f89 100644
--- a/modules/platforms/cpp/examples/include/ignite/examples/address.h
+++ b/modules/platforms/cpp/examples/include/ignite/examples/address.h
@@ -57,45 +57,20 @@ namespace ignite
     namespace binary
     {
         template<>
-        struct BinaryType<ignite::examples::Address>
+        struct BinaryType<examples::Address> : BinaryTypeDefaultAll<examples::Address>
         {
-            static int32_t GetTypeId()
-            {
-                return GetBinaryStringHashCode("Address");
-            }
-
             static void GetTypeName(std::string& dst)
             {
                 dst = "Address";
             }
 
-            static int32_t GetFieldId(const char* name)
-            {
-                return GetBinaryStringHashCode(name);
-            }
-
-            static int32_t GetHashCode(ignite::examples::Address& obj)
-            {
-                return 0;
-            }
-
-            static bool IsNull(ignite::examples::Address obj)
-            {
-                return false;
-            }
-
-            static void GetNull(ignite::examples::Address& dst)
-            {
-                dst = ignite::examples::Address("", 0);
-            }
-
-            static void Write(BinaryWriter& writer, const ignite::examples::Address& obj)
+            static void Write(BinaryWriter& writer, const examples::Address& obj)
             {
                 writer.WriteString("street", obj.street);
                 writer.WriteInt32("zip", obj.zip);
             }
 
-            static void Read(BinaryReader& reader, ignite::examples::Address& dst)
+            static void Read(BinaryReader& reader, examples::Address& dst)
             {
                 dst.street = reader.ReadString("street");
                 dst.zip = reader.ReadInt32("zip");
diff --git a/modules/platforms/cpp/examples/include/ignite/examples/organization.h b/modules/platforms/cpp/examples/include/ignite/examples/organization.h
index 2701933..61df3f6 100644
--- a/modules/platforms/cpp/examples/include/ignite/examples/organization.h
+++ b/modules/platforms/cpp/examples/include/ignite/examples/organization.h
@@ -66,48 +66,23 @@ namespace ignite
     namespace binary
     {
         template<>
-        struct BinaryType<ignite::examples::Organization>
+        struct BinaryType<examples::Organization> : BinaryTypeDefaultAll<examples::Organization>
         {
-            static int32_t GetTypeId()
-            {
-                return GetBinaryStringHashCode("Organization");
-            }
-
             static void GetTypeName(std::string& dst)
             {
                 dst = "Organization";
             }
 
-            static int32_t GetFieldId(const char* name)
-            {
-                return GetBinaryStringHashCode(name);
-            }
-
-            static int32_t GetHashCode(const ignite::examples::Organization& obj)
-            {
-                return 0;
-            }
-
-            static bool IsNull(const ignite::examples::Organization& obj)
-            {
-                return false;
-            }
-
-            static void GetNull(ignite::examples::Organization& dst)
-            {
-                dst = ignite::examples::Organization("", ignite::examples::Address());
-            }
-
-            static void Write(BinaryWriter& writer, const ignite::examples::Organization& obj)
+            static void Write(BinaryWriter& writer, const examples::Organization& obj)
             {
                 writer.WriteString("name", obj.name);
-                writer.WriteObject<ignite::examples::Address>("addr", obj.addr);
+                writer.WriteObject<examples::Address>("addr", obj.addr);
             }
 
-            static void Read(BinaryReader& reader, ignite::examples::Organization& dst)
+            static void Read(BinaryReader& reader, examples::Organization& dst)
             {
                 dst.name = reader.ReadString("name");
-                dst.addr = reader.ReadObject<ignite::examples::Address>("addr");
+                dst.addr = reader.ReadObject<examples::Address>("addr");
             }
         };
     }