geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbarr...@apache.org
Subject [geode-native] branch develop updated: GEODE-4359: Remove enable_shared_from_this (#320)
Date Mon, 30 Jul 2018 21:31:54 GMT
This is an automated email from the ASF dual-hosted git repository.

jbarrett pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode-native.git


The following commit(s) were added to refs/heads/develop by this push:
     new ee6547f  GEODE-4359: Remove enable_shared_from_this (#320)
ee6547f is described below

commit ee6547fae2f89c25c7f0ab524c05f56d4bec1a4d
Author: Blake Bender <ekalbredneb@hotmail.com>
AuthorDate: Mon Jul 30 21:31:52 2018 +0000

    GEODE-4359: Remove enable_shared_from_this (#320)
    
    * Remove enable_shared_from_this from PdxSerializable by requiring std::shared_ptr at
top API level
    
    Co-authored-by: Jacob Barrett <jbarrett@pivotal.io>
---
 clicache/src/ManagedPdxTypeHandler.hpp     |  4 ++--
 cppcache/include/geode/DataOutput.hpp      |  3 ++-
 cppcache/include/geode/PdxSerializable.hpp |  3 +--
 cppcache/src/DataOutput.cpp                |  4 ++++
 cppcache/src/PdxHelper.cpp                 |  6 ------
 cppcache/src/PdxHelper.hpp                 |  3 ---
 cppcache/src/SerializationRegistry.cpp     |  6 +++---
 cppcache/src/SerializationRegistry.hpp     | 31 ++++++++++++++++++++++++------
 8 files changed, 37 insertions(+), 23 deletions(-)

diff --git a/clicache/src/ManagedPdxTypeHandler.hpp b/clicache/src/ManagedPdxTypeHandler.hpp
index 89fd7ac..5fc46d7 100644
--- a/clicache/src/ManagedPdxTypeHandler.hpp
+++ b/clicache/src/ManagedPdxTypeHandler.hpp
@@ -38,10 +38,10 @@ namespace apache {
       public:
         ~ManagedPdxTypeHandler() noexcept override = default;
 
-        void serialize(const PdxSerializable& pdxSerializable,
+        void serialize(const std::shared_ptr<PdxSerializable>& pdxSerializable,
           DataOutput& dataOutput) const override
         {
-          if (auto wrappedPdxSerializable = dynamic_cast<const PdxManagedCacheableKey*>(&pdxSerializable))
+          if (auto wrappedPdxSerializable = dynamic_cast<const PdxManagedCacheableKey*>(pdxSerializable.get()))
           {
             try
             {
diff --git a/cppcache/include/geode/DataOutput.hpp b/cppcache/include/geode/DataOutput.hpp
index 2e75078..0f9a01a 100644
--- a/cppcache/include/geode/DataOutput.hpp
+++ b/cppcache/include/geode/DataOutput.hpp
@@ -353,7 +353,7 @@ class APACHE_GEODE_EXPORT DataOutput {
    */
   template <class PTR>
   void writeObject(const std::shared_ptr<PTR>& objptr, bool isDelta = false) {
-    writeObjectInternal(objptr.get(), isDelta);
+    writeObjectInternal(objptr, isDelta);
   }
 
   /**
@@ -516,6 +516,7 @@ class APACHE_GEODE_EXPORT DataOutput {
 
  private:
   void writeObjectInternal(const Serializable* ptr, bool isDelta = false);
+  void writeObjectInternal(const std::shared_ptr<Serializable>& ptr, bool isDelta
= false);
 
   static void acquireLock();
   static void releaseLock();
diff --git a/cppcache/include/geode/PdxSerializable.hpp b/cppcache/include/geode/PdxSerializable.hpp
index afc2d33..a6f73d9 100644
--- a/cppcache/include/geode/PdxSerializable.hpp
+++ b/cppcache/include/geode/PdxSerializable.hpp
@@ -36,8 +36,7 @@ class PdxWriter;
 
 class APACHE_GEODE_EXPORT PdxSerializable
     : public virtual Serializable,
-      public virtual CacheableKey,
-      public std::enable_shared_from_this<PdxSerializable> {
+      public virtual CacheableKey {
  public:
   ~PdxSerializable() noexcept override{};
 
diff --git a/cppcache/src/DataOutput.cpp b/cppcache/src/DataOutput.cpp
index 4c1388f..7bafb6c 100644
--- a/cppcache/src/DataOutput.cpp
+++ b/cppcache/src/DataOutput.cpp
@@ -131,6 +131,10 @@ void DataOutput::writeObjectInternal(const Serializable* ptr, bool isDelta)
{
   getSerializationRegistry().serialize(ptr, *this, isDelta);
 }
 
+void DataOutput::writeObjectInternal(const std::shared_ptr<Serializable>& ptr,
bool isDelta) {
+  getSerializationRegistry().serialize(ptr, *this, isDelta);
+}
+
 void DataOutput::acquireLock() { g_bigBufferLock.acquire(); }
 
 void DataOutput::releaseLock() { g_bigBufferLock.release(); }
diff --git a/cppcache/src/PdxHelper.cpp b/cppcache/src/PdxHelper.cpp
index 5e4ef4c..c231185 100644
--- a/cppcache/src/PdxHelper.cpp
+++ b/cppcache/src/PdxHelper.cpp
@@ -45,12 +45,6 @@ PdxHelper::PdxHelper() {}
 
 PdxHelper::~PdxHelper() {}
 
-void PdxHelper::serializePdx(DataOutput& output,
-                             const PdxSerializable& pdxObject) {
-  serializePdx(output, std::const_pointer_cast<PdxSerializable>(
-                           pdxObject.shared_from_this()));
-}
-
 void PdxHelper::serializePdx(
     DataOutput& output, const std::shared_ptr<PdxSerializable>& pdxObject)
{
   auto pdxII = std::dynamic_pointer_cast<PdxInstanceImpl>(pdxObject);
diff --git a/cppcache/src/PdxHelper.hpp b/cppcache/src/PdxHelper.hpp
index f472a8d..006c6e8 100644
--- a/cppcache/src/PdxHelper.hpp
+++ b/cppcache/src/PdxHelper.hpp
@@ -44,9 +44,6 @@ class PdxHelper {
   virtual ~PdxHelper();
 
   static void serializePdx(DataOutput& output,
-                           const PdxSerializable& pdxObject);
-
-  static void serializePdx(DataOutput& output,
                            const std::shared_ptr<PdxSerializable>& pdxObject);
 
   static std::shared_ptr<PdxSerializable> deserializePdx(DataInput& dataInput,
diff --git a/cppcache/src/SerializationRegistry.cpp b/cppcache/src/SerializationRegistry.cpp
index cb6eaec..55ea50c 100644
--- a/cppcache/src/SerializationRegistry.cpp
+++ b/cppcache/src/SerializationRegistry.cpp
@@ -266,9 +266,9 @@ void SerializationRegistry::deserialize(
       "SerializationRegistry::deserialize<PdxSerializable> not implemented");
 }
 
-void SerializationRegistry::serializeWithoutHeader(const PdxSerializable* obj,
+void SerializationRegistry::serializeWithoutHeader(const std::shared_ptr<PdxSerializable>&
obj,
                                                    DataOutput& output) const {
-  pdxTypeHandler->serialize(*obj, output);
+  pdxTypeHandler->serialize(obj, output);
 }
 
 void SerializationRegistry::addType(TypeFactoryMethod func) {
@@ -523,7 +523,7 @@ void TheTypeMap::unbindPdxType(const std::string& objFullName) {
   m_pdxTypemap->unbind(objFullName);
 }
 
-void PdxTypeHandler::serialize(const PdxSerializable& pdxSerializable,
+void PdxTypeHandler::serialize(const std::shared_ptr<PdxSerializable>& pdxSerializable,
                                DataOutput& dataOutput) const {
   PdxHelper::serializePdx(dataOutput, pdxSerializable);
 }
diff --git a/cppcache/src/SerializationRegistry.hpp b/cppcache/src/SerializationRegistry.hpp
index 5b9531f..50b2ced 100644
--- a/cppcache/src/SerializationRegistry.hpp
+++ b/cppcache/src/SerializationRegistry.hpp
@@ -143,7 +143,7 @@ class Pool;
 class PdxTypeHandler {
  public:
   virtual ~PdxTypeHandler() noexcept = default;
-  virtual void serialize(const PdxSerializable& pdxSerializable,
+  virtual void serialize(const std::shared_ptr<PdxSerializable>& pdxSerializable,
                          DataOutput& dataOutput) const;
   virtual std::shared_ptr<PdxSerializable> deserialize(
       DataInput& dataInput) const;
@@ -170,9 +170,6 @@ class APACHE_GEODE_EXPORT SerializationRegistry {
     } else if (const auto dataSerializable =
                    dynamic_cast<const DataSerializable*>(obj)) {
       serialize(dataSerializable, output, isDelta);
-    } else if (const auto pdxSerializable =
-                   dynamic_cast<const PdxSerializable*>(obj)) {
-      serialize(pdxSerializable, output);
     } else if (const auto dataSerializableInternal =
                    dynamic_cast<const DataSerializableInternal*>(obj)) {
       serialize(dataSerializableInternal, output);
@@ -183,6 +180,18 @@ class APACHE_GEODE_EXPORT SerializationRegistry {
     }
   }
 
+  inline void serialize(const std::shared_ptr<Serializable>& obj, DataOutput&
output,
+                        bool isDelta = false) const {
+    if (obj == nullptr) {
+      output.write(static_cast<int8_t>(GeodeTypeIds::NullObj));
+    } else if (auto&& pdxSerializable =
+        std::dynamic_pointer_cast<PdxSerializable>(obj)) {
+      serialize(pdxSerializable, output);
+    } else {
+      serialize(obj.get(), output, isDelta);
+    }
+  }
+
   inline void serializeWithoutHeader(const Serializable* obj,
                                      DataOutput& output) const {
     if (const auto dataSerializableFixedId =
@@ -207,6 +216,16 @@ class APACHE_GEODE_EXPORT SerializationRegistry {
     }
   }
 
+  inline void serializeWithoutHeader(const std::shared_ptr<Serializable>& obj,
DataOutput& output
+                        ) const {
+    if (auto&& pdxSerializable =
+        std::dynamic_pointer_cast<PdxSerializable>(obj)) {
+      serializeWithoutHeader(pdxSerializable, output);
+    } else {
+      serializeWithoutHeader(obj.get(), output);
+    }
+  }
+
   inline void serialize(const std::shared_ptr<Serializable>& obj,
                         DataOutput& output) const {
     serialize(obj.get(), output);
@@ -334,13 +353,13 @@ class APACHE_GEODE_EXPORT SerializationRegistry {
     obj->toData(output);
   }
 
-  inline void serialize(const PdxSerializable* obj, DataOutput& output) const {
+  inline void serialize(const std::shared_ptr<PdxSerializable>& obj, DataOutput&
output) const {
     output.write(static_cast<int8_t>(GeodeTypeIdsImpl::PDX));
 
     serializeWithoutHeader(obj, output);
   }
 
-  void serializeWithoutHeader(const PdxSerializable* obj,
+  void serializeWithoutHeader(const std::shared_ptr<PdxSerializable>& obj,
                               DataOutput& output) const;
 
   inline void serialize(const DataSerializableInternal* obj,


Mime
View raw message