http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/MapSegment.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/MapSegment.cpp b/src/cppcache/src/MapSegment.cpp
index 0eb333a..cd4731c 100644
--- a/src/cppcache/src/MapSegment.cpp
+++ b/src/cppcache/src/MapSegment.cpp
@@ -30,7 +30,7 @@ using namespace apache::geode::client;
 
 #define _GF_GUARD_SEGMENT SpinLockGuard mapGuard(m_spinlock)
 #define _VERSION_TAG_NULL_CHK \
-  (versionTag != NULLPTR && versionTag.ptr() != NULL)
+  (versionTag != nullptr && versionTag.get() != NULL)
 bool MapSegment::boolVal = false;
 MapSegment::~MapSegment() {
   delete m_map;
@@ -84,9 +84,9 @@ GfErrType MapSegment::create(const CacheableKeyPtr& key,
         return err;
       }
     } else {
-      MapEntryImpl* entryImpl = entry->getImplPtr();
+      MapEntryImplPtr entryImpl = entry->getImplPtr();
       entryImpl->getValueI(oldValue);
-      if (oldValue == NULLPTR || CacheableToken::isTombstone(oldValue)) {
+      if (oldValue == nullptr || CacheableToken::isTombstone(oldValue)) {
         // pass the version stamp
         VersionStamp versionStamp;
         if (m_concurrencyChecksEnabled) {
@@ -99,7 +99,7 @@ GfErrType MapSegment::create(const CacheableKeyPtr& key,
           }
         }
         // good case; go ahead with the create
-        if (oldValue == NULLPTR) {
+        if (oldValue == nullptr) {
           err = putForTrackedEntry(key, newValue, entry, entryImpl, 
updateCount,
                                    versionStamp);
         } else {
@@ -108,7 +108,7 @@ GfErrType MapSegment::create(const CacheableKeyPtr& key,
                            versionTag, &versionStamp);
         }
 
-        oldValue = NULLPTR;
+        oldValue = nullptr;
 
       } else {
         err = GF_CACHE_ENTRY_EXISTS;
@@ -154,7 +154,7 @@ GfErrType MapSegment::put(const CacheableKeyPtr& key,
       err = putNoEntry(key, newValue, me, updateCount, destroyTracker,
                        versionTag);
     } else {
-      MapEntryImpl* entryImpl = entry->getImplPtr();
+      MapEntryImplPtr entryImpl = entry->getImplPtr();
       CacheablePtr meOldValue;
       entryImpl->getValueI(meOldValue);
       // pass the version stamp
@@ -178,14 +178,14 @@ GfErrType MapSegment::put(const CacheableKeyPtr& key,
         unguardedRemoveActualEntryWithoutCancelTask(key, handler, taskid);
         err = putNoEntry(key, newValue, me, updateCount, destroyTracker,
                          versionTag, &versionStamp);
-        meOldValue = NULLPTR;
+        meOldValue = nullptr;
         isUpdate = false;
       } else if ((err = putForTrackedEntry(key, newValue, entry, entryImpl,
                                            updateCount, versionStamp, delta)) 
==
                  GF_NOERR) {
         me = entryImpl;
         oldValue = meOldValue;
-        isUpdate = (meOldValue != NULLPTR);
+        isUpdate = (meOldValue != nullptr);
       }
     }
   }
@@ -214,10 +214,10 @@ GfErrType MapSegment::invalidate(const CacheableKeyPtr& 
key,
         versionStamp.setVersions(versionTag);
       }
     }
-    MapEntryImpl* entryImpl = entry->getImplPtr();
+    MapEntryImplPtr entryImpl = entry->getImplPtr();
     entryImpl->getValueI(oldValue);
     if (CacheableToken::isTombstone(oldValue)) {
-      oldValue = NULLPTR;
+      oldValue = nullptr;
       return GF_CACHE_ENTRY_NOT_FOUND;
     }
     entryImpl->setValueI(CacheableToken::invalid());
@@ -225,7 +225,7 @@ GfErrType MapSegment::invalidate(const CacheableKeyPtr& key,
       entryImpl->getVersionStamp().setVersions(versionStamp);
     }
     (void)incrementUpdateCount(key, entry);
-    if (oldValue != NULLPTR) {
+    if (oldValue != nullptr) {
       me = entryImpl;
     }
   } else {
@@ -267,10 +267,10 @@ GfErrType MapSegment::removeWhenConcurrencyEnabled(
       versionStamp.setVersions(versionTag);
     }
     // Get the old value for returning
-    MapEntryImpl* entryImpl = entry->getImplPtr();
+    MapEntryImplPtr entryImpl = entry->getImplPtr();
     entryImpl->getValueI(oldValue);
 
-    if (oldValue != NULLPTR) me = entryImpl;
+    if (oldValue) me = entryImpl;
 
     if ((err = putForTrackedEntry(key, CacheableToken::tombstone(), entry,
                                   entryImpl, updateCount, versionStamp)) ==
@@ -279,7 +279,7 @@ GfErrType MapSegment::removeWhenConcurrencyEnabled(
       expTaskSet = true;
     }
     if (CacheableToken::isTombstone(oldValue)) {
-      oldValue = NULLPTR;
+      oldValue = nullptr;
       if (afterRemote) {
         return GF_NOERR;  // We are here because a remote op succeeded, no need
                           // to throw an error
@@ -298,7 +298,7 @@ GfErrType MapSegment::removeWhenConcurrencyEnabled(
                            expiryTaskID);
       expTaskSet = true;
     }
-    oldValue = NULLPTR;
+    oldValue = nullptr;
     isEntryFound = false;
     if (afterRemote) {
       err = GF_NOERR;  // We are here because a remote op succeeded, no need to
@@ -344,7 +344,7 @@ GfErrType MapSegment::remove(const CacheableKeyPtr& key, 
CacheablePtr& oldValue,
   CacheablePtr value;
   if ((status = m_map->unbind(key, entry)) == -1) {
     // didn't unbind, probably no entry...
-    oldValue = NULLPTR;
+    oldValue = nullptr;
     volatile int destroyTrackers = *m_numDestroyTrackers;
     if (destroyTrackers > 0) {
       m_destroyedKeys[key] = destroyTrackers + 1;
@@ -356,10 +356,10 @@ GfErrType MapSegment::remove(const CacheableKeyPtr& key, 
CacheablePtr& oldValue,
     // this is the case when entry has been updated while being tracked
     return GF_CACHE_ENTRY_UPDATED;
   }
-  MapEntryImpl* entryImpl = entry->getImplPtr();
+  MapEntryImplPtr entryImpl = entry->getImplPtr();
   entryImpl->getValueI(oldValue);
-  if (CacheableToken::isTombstone(oldValue)) oldValue = NULLPTR;
-  if (oldValue != NULLPTR) {
+  if (CacheableToken::isTombstone(oldValue)) oldValue = nullptr;
+  if (oldValue) {
     me = entryImpl;
   }
   return GF_NOERR;
@@ -401,17 +401,17 @@ bool MapSegment::getEntry(const CacheableKeyPtr& key, 
MapEntryImplPtr& result,
   int status;
   MapEntryPtr entry;
   if ((status = m_map->find(key, entry)) == -1) {
-    result = NULLPTR;
-    value = NULLPTR;
+    result = nullptr;
+    value = nullptr;
     return false;
   }
 
   // If the value is a tombstone return not found
-  MapEntryImpl* mePtr = entry->getImplPtr();
+  MapEntryImplPtr mePtr = entry->getImplPtr();
   mePtr->getValueI(value);
-  if (value == NULLPTR || CacheableToken::isTombstone(value)) {
-    result = NULLPTR;
-    value = NULLPTR;
+  if (value == nullptr || CacheableToken::isTombstone(value)) {
+    result = nullptr;
+    value = nullptr;
     return false;
   }
   result = mePtr;
@@ -430,9 +430,9 @@ bool MapSegment::containsKey(const CacheableKeyPtr& key) {
   }
   // If the value is a tombstone return not found
   CacheablePtr value;
-  MapEntryImpl* mePtr1 = mePtr->getImplPtr();
+  MapEntryImplPtr mePtr1 = mePtr->getImplPtr();
   mePtr1->getValueI(value);
-  if (value != NULLPTR && CacheableToken::isTombstone(value)) return false;
+  if (value != nullptr && CacheableToken::isTombstone(value)) return false;
 
   return true;
 }
@@ -463,11 +463,11 @@ void MapSegment::entries(VectorOfRegionEntry& result) {
        iter != m_map->end(); iter++) {
     CacheableKeyPtr keyPtr;
     CacheablePtr valuePtr;
-    MapEntryImpl* me = ((*iter).int_id_)->getImplPtr();
+    MapEntryImplPtr me = ((*iter).int_id_)->getImplPtr();
     me->getValueI(valuePtr);
-    if (valuePtr != NULLPTR && !CacheableToken::isTombstone(valuePtr)) {
+    if (valuePtr != nullptr && !CacheableToken::isTombstone(valuePtr)) {
       if (CacheableToken::isInvalid(valuePtr)) {
-        valuePtr = NULLPTR;
+        valuePtr = nullptr;
       }
       me->getKeyI(keyPtr);
       RegionEntryPtr rePtr = m_region->createRegionEntry(keyPtr, valuePtr);
@@ -493,8 +493,8 @@ void MapSegment::values(VectorOfCacheable& result) {
     status = m_map->find(keyPtr, entry);
 
     if (status != -1) {
-      MapEntryImpl* entryImpl = entry->getImplPtr();
-      if (valuePtr != NULLPTR && !CacheableToken::isInvalid(valuePtr) &&
+      MapEntryImplPtr entryImpl = entry->getImplPtr();
+      if (valuePtr != nullptr && !CacheableToken::isInvalid(valuePtr) &&
           !CacheableToken::isDestroyed(valuePtr) &&
           !CacheableToken::isTombstone(valuePtr)) {
         if (CacheableToken::isOverflowed(valuePtr)) {  // get Value from disc.
@@ -519,7 +519,7 @@ int MapSegment::addTrackerForEntry(const CacheableKeyPtr& 
key,
   MapEntryPtr newEntry;
   int status;
   if ((status = m_map->find(key, entry)) == -1) {
-    oldValue = NULLPTR;
+    oldValue = nullptr;
     if (addIfAbsent) {
       MapEntryImplPtr entryImpl;
       // add a new entry with value as destroyed
@@ -546,7 +546,7 @@ int MapSegment::addTrackerForEntry(const CacheableKeyPtr& 
key,
   } else {
     updateCount = entry->addTracker(newEntry);
   }
-  if (newEntry != NULLPTR) {
+  if (newEntry != nullptr) {
     if (status == -1) {
       m_map->bind(key, newEntry);
     } else {
@@ -565,7 +565,8 @@ void MapSegment::removeTrackerForEntry(const 
CacheableKeyPtr& key) {
   MapEntryPtr entry;
   int status;
   if ((status = m_map->find(key, entry)) != -1) {
-    removeTrackerForEntry(key, entry, NULL);
+    auto impl = entry->getImplPtr();
+    removeTrackerForEntry(key, entry, impl);
   }
 }
 
@@ -582,7 +583,7 @@ void MapSegment::addTrackerForAllEntries(
        iter != m_map->end(); ++iter) {
     (*iter).int_id_->getKey(key);
     int updateCount = (*iter).int_id_->addTracker(newEntry);
-    if (newEntry != NULLPTR) {
+    if (newEntry != nullptr) {
       m_map->rebind(key, newEntry);
     }
     updateCounterMap.insert(std::make_pair(key, updateCount));
@@ -625,14 +626,15 @@ void MapSegment::rehash() {  // Only called from put, 
segment must already be
 }
 
 CacheablePtr MapSegment::getFromDisc(CacheableKeyPtr key,
-                                     MapEntryImpl* entryImpl) {
+                                     MapEntryImplPtr& entryImpl) {
   LocalRegion* lregion = static_cast<LocalRegion*>(m_region);
   EntriesMap* em = lregion->getEntryMap();
   return em->getFromDisk(key, entryImpl);
 }
+
 GfErrType MapSegment::putForTrackedEntry(
     const CacheableKeyPtr& key, const CacheablePtr& newValue,
-    MapEntryPtr& entry, MapEntryImpl* entryImpl, int updateCount,
+    MapEntryPtr& entry, MapEntryImplPtr& entryImpl, int updateCount,
     VersionStamp& versionStamp, DataInput* delta) {
   if (updateCount < 0 || m_concurrencyChecksEnabled) {
     // for a non-tracked put (e.g. from notification) go ahead with the
@@ -645,7 +647,7 @@ GfErrType MapSegment::putForTrackedEntry(
     if (delta != NULL) {
       CacheablePtr oldValue;
       entryImpl->getValueI(oldValue);
-      if (oldValue == NULLPTR || CacheableToken::isDestroyed(oldValue) ||
+      if (oldValue == nullptr || CacheableToken::isDestroyed(oldValue) ||
           CacheableToken::isInvalid(oldValue) ||
           CacheableToken::isTombstone(oldValue)) {
         if (m_poolDM) m_poolDM->updateNotificationStats(false, 0);
@@ -653,12 +655,12 @@ GfErrType MapSegment::putForTrackedEntry(
       } else if (CacheableToken::isOverflowed(
                      oldValue)) {  // get Value from disc.
         oldValue = getFromDisc(key, entryImpl);
-        if (oldValue == NULLPTR) {
+        if (oldValue == nullptr) {
           if (m_poolDM) m_poolDM->updateNotificationStats(false, 0);
           return GF_INVALID_DELTA;
         }
       }
-      DeltaPtr valueWithDelta(dynCast<DeltaPtr>(oldValue));
+      auto valueWithDelta = std::dynamic_pointer_cast<Delta>(oldValue);
       CacheablePtr& newValue1 = const_cast<CacheablePtr&>(newValue);
       try {
         if (m_region->getAttributes()->getCloningEnabled()) {
@@ -670,18 +672,19 @@ GfErrType MapSegment::putForTrackedEntry(
                 true,
                 ((ACE_OS::gettimeofday() - currTimeBefore).msec()) * 1000000);
           }
-          newValue1 = tempVal;
+          newValue1 = std::dynamic_pointer_cast<Serializable>(tempVal);
           entryImpl->setValueI(newValue1);
         } else {
           ACE_Time_Value currTimeBefore = ACE_OS::gettimeofday();
           valueWithDelta->fromDelta(*delta);
-          newValue1 = valueWithDelta;
+          newValue1 = std::dynamic_pointer_cast<Serializable>(valueWithDelta);
           if (m_poolDM) {
             m_poolDM->updateNotificationStats(
                 true,
                 ((ACE_OS::gettimeofday() - currTimeBefore).msec()) * 1000000);
           }
-          entryImpl->setValueI(valueWithDelta);
+          entryImpl->setValueI(
+              std::dynamic_pointer_cast<Serializable>(valueWithDelta));
         }
       } catch (InvalidDeltaException&) {
         return GF_INVALID_DELTA;
@@ -721,7 +724,7 @@ GfErrType MapSegment::isTombstone(CacheableKeyPtr key, 
MapEntryImplPtr& me,
                                   bool& result) {
   CacheablePtr value;
   MapEntryPtr entry;
-  MapEntryImpl* mePtr;
+  MapEntryImplPtr mePtr;
   if (m_map->find(key, entry) == -1) {
     result = false;
     return GF_NOERR;
@@ -734,15 +737,13 @@ GfErrType MapSegment::isTombstone(CacheableKeyPtr key, 
MapEntryImplPtr& me,
    * Fix : Aded a check for null ptr
    */
 
-  if (mePtr == (MapEntryImpl*)0) {
+  if (!mePtr) {
     result = false;
     return GF_NOERR;
   }
 
   mePtr->getValueI(value);
-  result = mePtr;
-
-  if (value == NULLPTR || value.ptr() == NULL) {
+  if (!value) {
     result = false;
     return GF_NOERR;
   }
@@ -751,7 +752,7 @@ GfErrType MapSegment::isTombstone(CacheableKeyPtr key, 
MapEntryImplPtr& me,
     if (m_tombstoneList->getEntryFromTombstoneList(key)) {
       MapEntryPtr entry;
       if (m_map->find(key, entry) != -1) {
-        MapEntryImpl* mePtr = entry->getImplPtr();
+        auto mePtr = entry->getImplPtr();
         me = mePtr;
       }
       result = true;

http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/MapSegment.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/MapSegment.hpp b/src/cppcache/src/MapSegment.hpp
index 6b91c93..2ed6f66 100644
--- a/src/cppcache/src/MapSegment.hpp
+++ b/src/cppcache/src/MapSegment.hpp
@@ -107,7 +107,7 @@ class CPPCACHE_EXPORT MapSegment {
     if (m_concurrencyChecksEnabled) return false;
     MapEntryPtr newEntry;
     entry->incrementUpdateCount(newEntry);
-    if (newEntry != NULLPTR) {
+    if (newEntry != nullptr) {
       m_map->rebind(key, newEntry);
       entry = newEntry;
       return true;
@@ -118,7 +118,7 @@ class CPPCACHE_EXPORT MapSegment {
   // remove a tracker for the given entry
   inline void removeTrackerForEntry(const CacheableKeyPtr& key,
                                     MapEntryPtr& entry,
-                                    MapEntryImpl* entryImpl) {
+                                    MapEntryImplPtr& entryImpl) {
     // This function is disabled if concurrency checks are enabled. The
     // versioning
     // changes takes care of the version and no need for tracking the entry
@@ -130,14 +130,14 @@ class CPPCACHE_EXPORT MapSegment {
         entryImpl = entry->getImplPtr();
       }
       entryImpl->getValueI(value);
-      if (value == NULLPTR) {
+      if (value == nullptr) {
         // get rid of an entry marked as destroyed
         m_map->unbind(key);
         return;
       }
     }
     if (trackerPair.first) {
-      entry = (entryImpl != NULL ? entryImpl : entry->getImplPtr());
+      entry = entryImpl ? entryImpl : entry->getImplPtr();
       m_map->rebind(key, entry);
     }
   }
@@ -164,7 +164,7 @@ class CPPCACHE_EXPORT MapSegment {
     m_entryFactory->newMapEntry(key, newEntry);
     newEntry->setValueI(newValue);
     if (m_concurrencyChecksEnabled) {
-      if (versionTag != NULLPTR && versionTag.ptr() != NULL) {
+      if (versionTag != nullptr && versionTag.get() != NULL) {
         newEntry->getVersionStamp().setVersions(versionTag);
       } else if (versionStamp != NULL) {
         newEntry->getVersionStamp().setVersions(*versionStamp);
@@ -176,11 +176,11 @@ class CPPCACHE_EXPORT MapSegment {
 
   GfErrType putForTrackedEntry(const CacheableKeyPtr& key,
                                const CacheablePtr& newValue, MapEntryPtr& 
entry,
-                               MapEntryImpl* entryImpl, int updateCount,
+                               MapEntryImplPtr& entryImpl, int updateCount,
                                VersionStamp& versionStamp,
                                DataInput* delta = NULL);
 
-  CacheablePtr getFromDisc(CacheableKeyPtr key, MapEntryImpl* entryImpl);
+  CacheablePtr getFromDisc(CacheableKeyPtr key, MapEntryImplPtr& entryImpl);
 
   GfErrType removeWhenConcurrencyEnabled(
       const CacheableKeyPtr& key, CacheablePtr& oldValue, MapEntryImplPtr& me,
@@ -192,7 +192,7 @@ class CPPCACHE_EXPORT MapSegment {
   MapSegment()
       : m_map(NULL),
         m_entryFactory(NULL),
-        m_region(NULL),
+        m_region(nullptr),
         m_primeIndex(0),
         m_spinlock(),
         m_segmentMutex(),
@@ -200,7 +200,7 @@ class CPPCACHE_EXPORT MapSegment {
         m_numDestroyTrackers(NULL),
         m_rehashCount(0)  // COVERITY  --> 30303 Uninitialized scalar field
   {
-    m_tombstoneList = new TombstoneList(this);
+    m_tombstoneList = std::make_shared<TombstoneList>(this);
   }
 
   ~MapSegment();

http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/MapWithLock.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/MapWithLock.hpp b/src/cppcache/src/MapWithLock.hpp
index 32d259c..d8e4500 100644
--- a/src/cppcache/src/MapWithLock.hpp
+++ b/src/cppcache/src/MapWithLock.hpp
@@ -49,7 +49,7 @@ template <>
 struct equal_to<apache::geode::client::CacheableKeyPtr> {
   size_t operator()(const apache::geode::client::CacheableKeyPtr& key1,
                     const apache::geode::client::CacheableKeyPtr& key2) const {
-    return (*key1.ptr() == *key2.ptr());
+    return (*key1.get() == *key2.get());
   }
 };
 }  // namespace std

http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/MemberListForVersionStamp.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/MemberListForVersionStamp.cpp 
b/src/cppcache/src/MemberListForVersionStamp.cpp
index 025d021..210db09 100644
--- a/src/cppcache/src/MemberListForVersionStamp.cpp
+++ b/src/cppcache/src/MemberListForVersionStamp.cpp
@@ -50,5 +50,5 @@ DSMemberForVersionStampPtr 
MemberListForVersionStamp::getDSMember(
   std::unordered_map<uint32_t, DSMemberForVersionStampPtr>::iterator it =
       m_members1.find(memberId);
   if (it != m_members1.end()) return (*it).second;
-  return NULLPTR;
+  return nullptr;
 }

http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/MemberListForVersionStamp.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/MemberListForVersionStamp.hpp 
b/src/cppcache/src/MemberListForVersionStamp.hpp
index 3f21988..de759fd 100644
--- a/src/cppcache/src/MemberListForVersionStamp.hpp
+++ b/src/cppcache/src/MemberListForVersionStamp.hpp
@@ -33,7 +33,7 @@ namespace client {
 struct DistributedMemberWithIntIdentifier {
  public:
   DistributedMemberWithIntIdentifier(
-      DSMemberForVersionStampPtr dsmember = NULLPTR, uint16_t id = 0) {
+      DSMemberForVersionStampPtr dsmember = nullptr, uint16_t id = 0) {
     this->m_member = dsmember;
     this->m_identifier = id;
   }

http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/PdxEnumInstantiator.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/PdxEnumInstantiator.cpp 
b/src/cppcache/src/PdxEnumInstantiator.cpp
index 16e3964..8584186 100644
--- a/src/cppcache/src/PdxEnumInstantiator.cpp
+++ b/src/cppcache/src/PdxEnumInstantiator.cpp
@@ -43,7 +43,7 @@ void PdxEnumInstantiator::toData(DataOutput& output) const {
 Serializable* PdxEnumInstantiator::fromData(DataInput& input) {
   m_enumObject = CacheableEnum::create(" ", " ", 0);
   m_enumObject->fromData(input);
-  return m_enumObject.ptr();
+  return m_enumObject.get();
 }
 
 CacheableStringPtr PdxEnumInstantiator::toString() const {

http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/PdxFieldType.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/PdxFieldType.cpp 
b/src/cppcache/src/PdxFieldType.cpp
index 72f20cf..5652d64 100644
--- a/src/cppcache/src/PdxFieldType.cpp
+++ b/src/cppcache/src/PdxFieldType.cpp
@@ -102,9 +102,9 @@ Serializable* PdxFieldType::fromData(DataInput& input) {
 }
 
 bool PdxFieldType::equals(PdxFieldTypePtr otherObj) {
-  if (otherObj == NULLPTR) return false;
+  if (otherObj == nullptr) return false;
 
-  PdxFieldType* otherFieldType = dynamic_cast<PdxFieldType*>(otherObj.ptr());
+  PdxFieldType* otherFieldType = dynamic_cast<PdxFieldType*>(otherObj.get());
 
   if (otherFieldType == NULL) return false;
 

http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/PdxHelper.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/PdxHelper.cpp b/src/cppcache/src/PdxHelper.cpp
index 200fb69..1055e5b 100644
--- a/src/cppcache/src/PdxHelper.cpp
+++ b/src/cppcache/src/PdxHelper.cpp
@@ -46,138 +46,61 @@ PdxHelper::~PdxHelper() {}
 
 CacheImpl* PdxHelper::getCacheImpl() {
   CachePtr cache = CacheFactory::getAnyInstance();
-  if (cache == NULLPTR) {
+  if (cache == nullptr) {
     throw IllegalStateException("cache has not been created yet.");
     ;
   }
   if (cache->isClosed()) {
     throw IllegalStateException("cache has been closed. ");
   }
-  return CacheRegionHelper::getCacheImpl(cache.ptr());
+  return CacheRegionHelper::getCacheImpl(cache.get());
 }
 
 void PdxHelper::serializePdx(DataOutput& output,
                              const PdxSerializable& pdxObject) {
+  serializePdx(
+      output,
+      std::static_pointer_cast<PdxSerializable>(
+          
std::const_pointer_cast<Serializable>(pdxObject.shared_from_this())));
+}
+
+void PdxHelper::serializePdx(DataOutput& output,
+                             const PdxSerializablePtr& pdxObject) {
   const char* pdxClassname = NULL;
 
-  PdxSerializable& pdx = const_cast<PdxSerializable&>(pdxObject);
-  PdxInstanceImpl* pdxII = dynamic_cast<PdxInstanceImpl*>(&pdx /*.ptr()*/);
+  auto pdxII = std::dynamic_pointer_cast<PdxInstanceImpl>(pdxObject);
 
   if (pdxII != NULL) {
     PdxTypePtr piPt = pdxII->getPdxType();
-    if (piPt != NULLPTR &&
+    if (piPt != nullptr &&
         piPt->getTypeId() ==
             0)  // from pdxInstance factory need to get typeid from server
     {
       int typeId = PdxTypeRegistry::getPDXIdForType(piPt, 
output.getPoolName());
       pdxII->setPdxId(typeId);
     }
-    PdxLocalWriterPtr plw(new PdxLocalWriter(output, piPt));
+    auto plw = std::make_shared<PdxLocalWriter>(output, piPt);
     pdxII->toData(plw);
     plw->endObjectWriting();  // now write typeid
     int len = 0;
     uint8_t* pdxStream = plw->getPdxStream(len);
     pdxII->updatePdxStream(pdxStream, len);
 
-    /*
-    ==18904== 265,458 bytes in 2 blocks are definitely lost in loss record 928
-    of 932
-    ==18904==    at 0x400791A: operator new[](unsigned int)
-    (vg_replace_malloc.c:378)
-    ==18904==    by 0x4324354:
-    apache::geode::client::PdxLocalWriter::getPdxStream(int&)
-    (DataOutput.hpp:744)
-    ==18904==    by 0x4303E6F:
-    
apache::geode::client::PdxHelper::serializePdx(apache::geode::client::DataOutput&,
-    apache::geode::client::PdxSerializable const&) (PdxHelper.cpp:64)
-    ==18904==    by 0x4377028:
-    
apache::geode::client::TcrMessage::writeObjectPart(apache::geode::client::SharedPtr<apache::geode::client::Serializable>
-    const&, bool, bool, apache::geode::client::VectorOfCacheableKey const*)
-    (DataOutput.hpp:580)
-    ==18904==    by 0x437BB9E:
-    
apache::geode::client::TcrMessage::TcrMessage(apache::geode::client::TcrMessage::MsgType,
-    apache::geode::client::Region const*,
-    apache::geode::client::SharedPtr<apache::geode::client::CacheableKey>
-    const&,
-    apache::geode::client::SharedPtr<apache::geode::client::Serializable>
-    const&,
-    apache::geode::client::SharedPtr<apache::geode::client::Serializable>
-    const&, bool,
-    apache::geode::client::ThinClientBaseDM*, bool, bool, char const*)
-    (TcrMessage.cpp:2216)
-    ==18904==    by 0x43B9EE5:
-    
apache::geode::client::ThinClientRegion::putNoThrow_remote(apache::geode::client::SharedPtr<apache::geode::client::CacheableKey>
-    const&,
-    apache::geode::client::SharedPtr<apache::geode::client::Serializable>
-    const&,
-    apache::geode::client::SharedPtr<apache::geode::client::Serializable>
-    const&,
-    apache::geode::client::SharedPtr<apache::geode::client::VersionTag>&, bool)
-    (ThinClientRegion.cpp:909)
-    ==18904==    by 0x42EFCEF: GfErrType
-    
apache::geode::client::LocalRegion::updateNoThrow<apache::geode::client::PutActions>(apache::geode::client::SharedPtr<apache::geode::client::CacheableKey>
-    const&,
-    apache::geode::client::SharedPtr<apache::geode::client::Serializable>
-    const&,
-    apache::geode::client::SharedPtr<apache::geode::client::Serializable>
-    const&,
-    apache::geode::client::SharedPtr<apache::geode::client::Serializable>&, 
int,
-    apache::geode::client::CacheEventFlags,
-    apache::geode::client::SharedPtr<apache::geode::client::VersionTag>,
-    apache::geode::client::DataInput*,
-    apache::geode::client::SharedPtr<apache::geode::client::EventId>)
-    (LocalRegion.cpp:1097)
-    ==18904==    by 0x42E4DC6:
-    
apache::geode::client::LocalRegion::putNoThrow(apache::geode::client::SharedPtr<apache::geode::client::CacheableKey>
-    const&,
-    apache::geode::client::SharedPtr<apache::geode::client::Serializable>
-    const&,
-    apache::geode::client::SharedPtr<apache::geode::client::Serializable>
-    const&,
-    apache::geode::client::SharedPtr<apache::geode::client::Serializable>&, 
int,
-    apache::geode::client::CacheEventFlags,
-    apache::geode::client::SharedPtr<apache::geode::client::VersionTag>,
-    apache::geode::client::DataInput*,
-    apache::geode::client::SharedPtr<apache::geode::client::EventId>)
-    (LocalRegion.cpp:1799)
-    ==18904==    by 0x42DBEB4:
-    
apache::geode::client::LocalRegion::put(apache::geode::client::SharedPtr<apache::geode::client::CacheableKey>
-    const&,
-    apache::geode::client::SharedPtr<apache::geode::client::Serializable>
-    const&,
-    apache::geode::client::SharedPtr<apache::geode::client::Serializable>
-    const&) (LocalRegion.cpp:342)
-    ==18904==    by 0x8069744: void
-    
apache::geode::client::Region::put<apache::geode::client::SharedPtr<apache::geode::client::WritablePdxInstance>
-    >(apache::geode::client::SharedPtr<apache::geode::client::CacheableKey>
-    const&,
-    
apache::geode::client::SharedPtr<apache::geode::client::WritablePdxInstance>
-    const&,
-    apache::geode::client::SharedPtr<apache::geode::client::Serializable>
-    const&) (in
-    
/export/pnq-gst-dev01a/users/adongre/cedar_dev_Nov12/build-artifacts/linux/tests/cppcache/testThinClientPdxInstance)
-    ==18904==    by 0x808D107: Task_modifyPdxInstance::doTask() (in
-    
/export/pnq-gst-dev01a/users/adongre/cedar_dev_Nov12/build-artifacts/linux/tests/cppcache/testThinClientPdxInstance)
-    ==18904==    by 0x80986CA: dunit::TestSlave::begin() (in
-    
/export/pnq-gst-dev01a/users/adongre/cedar_dev_Nov12/build-artifacts/linux/tests/cppcache/testThinClientPdxInstance)
-    ==18904==
-    */
     delete[] pdxStream;
 
     return;
   }
 
-  const char* pdxType = pdx.getClassName();
+  const char* pdxType = pdxObject->getClassName();
   pdxClassname = pdxType;
   PdxTypePtr localPdxType = PdxTypeRegistry::getLocalPdxType(pdxType);
 
-  if (localPdxType == NULLPTR) {
+  if (localPdxType == nullptr) {
     // need to grab type info, as fromdata is not called yet
 
-    PdxWriterWithTypeCollectorPtr ptc(
-        new PdxWriterWithTypeCollector(output, pdxType));
-    PdxWriterPtr pwp(dynCast<PdxWriterPtr>(ptc));
-    pdx.toData(pwp);
+    PdxWriterWithTypeCollectorPtr ptc =
+        std::make_shared<PdxWriterWithTypeCollector>(output, pdxType);
+    pdxObject->toData(std::dynamic_pointer_cast<PdxWriter>(ptc));
     PdxTypePtr nType = ptc->getPdxLocalType();
 
     nType->InitializeType();
@@ -206,25 +129,21 @@ void PdxHelper::serializePdx(DataOutput& output,
     // if object got from server than create instance of RemoteWriter otherwise
     // local writer.
 
-    PdxSerializablePtr pdxObjptr = NULLPTR;
-    pdxObjptr = PdxSerializablePtr(&pdx);
-
-    PdxRemotePreservedDataPtr pd = PdxTypeRegistry::getPreserveData(pdxObjptr);
+    PdxRemotePreservedDataPtr pd = PdxTypeRegistry::getPreserveData(pdxObject);
 
     // now always remotewriter as we have API Read/WriteUnreadFields
     // so we don't know whether user has used those or not;; Can we do some
     // trick here?
-    PdxRemoteWriterPtr prw = NULLPTR;
+    PdxRemoteWriterPtr prw = nullptr;
 
-    if (pd != NULLPTR) {
+    if (pd != nullptr) {
       PdxTypePtr mergedPdxType =
           PdxTypeRegistry::getPdxType(pd->getMergedTypeId());
-      prw = PdxRemoteWriterPtr(new PdxRemoteWriter(output, mergedPdxType, pd));
+      prw = std::make_shared<PdxRemoteWriter>(output, mergedPdxType, pd);
     } else {
-      prw = PdxRemoteWriterPtr(new PdxRemoteWriter(output, pdxClassname));
+      prw = std::make_shared<PdxRemoteWriter>(output, pdxClassname);
     }
-    PdxWriterPtr pwptr(dynCast<PdxWriterPtr>(prw));
-    pdx.toData(pwptr);
+    pdxObject->toData(std::dynamic_pointer_cast<PdxWriter>(prw));
     prw->endObjectWriting();
 
     //[ToDo] need to write bytes for stats
@@ -243,15 +162,15 @@ PdxSerializablePtr PdxHelper::deserializePdx(DataInput& 
dataInput,
                                              bool forceDeserialize,
                                              int32_t typeId, int32_t length) {
   char* pdxClassname = NULL;
-  PdxSerializablePtr pdxObjectptr = NULLPTR;
-  PdxTypePtr pdxLocalType = NULLPTR;
+  PdxSerializablePtr pdxObjectptr = nullptr;
+  PdxTypePtr pdxLocalType = nullptr;
 
   PdxTypePtr pType = PdxTypeRegistry::getPdxType(typeId);
-  if (pType != NULLPTR) {  // this may happen with PdxInstanceFactory {
+  if (pType != nullptr) {  // this may happen with PdxInstanceFactory {
     pdxLocalType = PdxTypeRegistry::getLocalPdxType(
         pType->getPdxClassName());  // this should be fine for IPdxTypeMapper
   }
-  if (pType != NULLPTR && pdxLocalType != NULLPTR)  // type found
+  if (pType != nullptr && pdxLocalType != nullptr)  // type found
   {
     pdxClassname = pType->getPdxClassName();
     LOGDEBUG("deserializePdx ClassName = %s, isLocal = %d ",
@@ -260,20 +179,20 @@ PdxSerializablePtr PdxHelper::deserializePdx(DataInput& 
dataInput,
     pdxObjectptr = SerializationRegistry::getPdxType(pdxClassname);
     if (pType->isLocal())  // local type no need to read Unread data
     {
-      PdxLocalReaderPtr plr(new PdxLocalReader(dataInput, pType, length));
-      PdxReaderPtr prp(dynCast<PdxReaderPtr>(plr));
-      pdxObjectptr->fromData(prp);
+      PdxLocalReaderPtr plr =
+          std::make_shared<PdxLocalReader>(dataInput, pType, length);
+      pdxObjectptr->fromData(std::dynamic_pointer_cast<PdxReader>(plr));
       plr->MoveStream();
     } else {
-      PdxRemoteReaderPtr prr(new PdxRemoteReader(dataInput, pType, length));
-      PdxReaderPtr prp(dynCast<PdxReaderPtr>(prr));
-      pdxObjectptr->fromData(prp);
+      PdxRemoteReaderPtr prr =
+          std::make_shared<PdxRemoteReader>(dataInput, pType, length);
+      pdxObjectptr->fromData(std::dynamic_pointer_cast<PdxReader>(prr));
       PdxTypePtr mergedVersion =
           PdxTypeRegistry::getMergedType(pType->getTypeId());
 
       PdxRemotePreservedDataPtr preserveData =
           prr->getPreservedData(mergedVersion, pdxObjectptr);
-      if (preserveData != NULLPTR) {
+      if (preserveData != nullptr) {
         PdxTypeRegistry::setPreserveData(
             pdxObjectptr, preserveData);  // it will set data in weakhashmap
       }
@@ -281,9 +200,10 @@ PdxSerializablePtr PdxHelper::deserializePdx(DataInput& 
dataInput,
     }
   } else {
     // type not found; need to get from server
-    if (pType == NULLPTR) {
-      pType = SerializationRegistry::GetPDXTypeById(dataInput.getPoolName(),
-                                                    typeId);
+    if (pType == nullptr) {
+      pType = std::static_pointer_cast<PdxType>(
+          SerializationRegistry::GetPDXTypeById(dataInput.getPoolName(),
+                                                typeId));
       pdxLocalType = 
PdxTypeRegistry::getLocalPdxType(pType->getPdxClassName());
     }
     /* adongre  - Coverity II
@@ -295,12 +215,12 @@ PdxSerializablePtr PdxHelper::deserializePdx(DataInput& 
dataInput,
     // pdxClassname = pType->getPdxClassName();
     pdxObjectptr = SerializationRegistry::getPdxType(pType->getPdxClassName());
     PdxSerializablePtr pdxRealObject = pdxObjectptr;
-    if (pdxLocalType == NULLPTR)  // need to know local type
+    if (pdxLocalType == nullptr)  // need to know local type
     {
-      PdxReaderWithTypeCollectorPtr prtc(
-          new PdxReaderWithTypeCollector(dataInput, pType, length));
-      PdxReaderPtr prp(dynCast<PdxReaderPtr>(prtc));
-      pdxObjectptr->fromData(prp);
+      PdxReaderWithTypeCollectorPtr prtc =
+          std::make_shared<PdxReaderWithTypeCollector>(dataInput, pType,
+                                                       length);
+      pdxObjectptr->fromData(std::dynamic_pointer_cast<PdxReader>(prtc));
 
       // Check for the PdxWrapper
 
@@ -333,7 +253,7 @@ PdxSerializablePtr PdxHelper::deserializePdx(DataInput& 
dataInput,
 
         PdxRemotePreservedDataPtr preserveData =
             prtc->getPreservedData(mergedVersion, pdxObjectptr);
-        if (preserveData != NULLPTR) {
+        if (preserveData != nullptr) {
           PdxTypeRegistry::setPreserveData(pdxObjectptr, preserveData);
         }
       }
@@ -343,9 +263,9 @@ PdxSerializablePtr PdxHelper::deserializePdx(DataInput& 
dataInput,
       LOGDEBUG("Adding type %d ", pType->getTypeId());
       PdxTypeRegistry::addPdxType(pType->getTypeId(),
                                   pType);  // adding remote type
-      PdxRemoteReaderPtr prr(new PdxRemoteReader(dataInput, pType, length));
-      PdxReaderPtr prp(dynCast<PdxReaderPtr>(prr));
-      pdxObjectptr->fromData(prp);
+      PdxRemoteReaderPtr prr =
+          std::make_shared<PdxRemoteReader>(dataInput, pType, length);
+      pdxObjectptr->fromData(std::dynamic_pointer_cast<PdxReader>(prr));
 
       // Check for PdxWrapper to getObject.
 
@@ -356,7 +276,7 @@ PdxSerializablePtr PdxHelper::deserializePdx(DataInput& 
dataInput,
 
       PdxRemotePreservedDataPtr preserveData =
           prr->getPreservedData(mergedVersion, pdxObjectptr);
-      if (preserveData != NULLPTR) {
+      if (preserveData != nullptr) {
         PdxTypeRegistry::setPreserveData(pdxObjectptr, preserveData);
       }
       prr->MoveStream();
@@ -381,8 +301,8 @@ PdxSerializablePtr PdxHelper::deserializePdx(DataInput& 
dataInput,
       cacheImpl->m_cacheStats->incPdxDeSerialization(len +
                                                      9);  // pdxLen + 1 + 2*4
     }
-    return PdxHelper::deserializePdx(dataInput, forceDeserialize, 
(int32_t)typeId,
-                                     (int32_t)len);
+    return PdxHelper::deserializePdx(dataInput, forceDeserialize,
+                                     (int32_t)typeId, (int32_t)len);
 
   } else {
     // Read Length
@@ -395,73 +315,18 @@ PdxSerializablePtr PdxHelper::deserializePdx(DataInput& 
dataInput,
 
     PdxTypePtr pType = PdxTypeRegistry::getPdxType(typeId);
 
-    if (pType == NULLPTR) {
-      PdxTypePtr pType = SerializationRegistry::GetPDXTypeById(
-          dataInput.getPoolName(), typeId);
+    if (pType == nullptr) {
+      // TODO shared_ptr why redef?
+      PdxTypePtr pType = std::static_pointer_cast<PdxType>(
+          SerializationRegistry::GetPDXTypeById(dataInput.getPoolName(),
+                                                typeId));
       PdxTypeRegistry::addLocalPdxType(pType->getPdxClassName(), pType);
       PdxTypeRegistry::addPdxType(pType->getTypeId(), pType);
     }
 
-    /*
-    ==2018== 398,151 bytes in 3 blocks are definitely lost in loss record 707 
of
-    710
-    ==2018==    at 0x400791A: operator new[](unsigned int)
-    (vg_replace_malloc.c:378)
-    ==2018==    by 0x4303969:
-    
apache::geode::client::PdxHelper::deserializePdx(apache::geode::client::DataInput&,
-    bool)
-    (DataInput.hpp:1007)
-    ==2018==    by 0x43210D4:
-    
apache::geode::client::PdxInstantiator::fromData(apache::geode::client::DataInput&)
-    (PdxInstantiator.cpp:30)
-    ==2018==    by 0x434A72E:
-    
apache::geode::client::SerializationRegistry::deserialize(apache::geode::client::DataInput&,
-    signed
-    char) (SerializationRegistry.cpp:378)
-    ==2018==    by 0x42280FB:
-    
apache::geode::client::DataInput::readObjectInternal(apache::geode::client::SharedPtr<apache::geode::client::Serializable>&,
-    signed char) (DataInput.cpp:9)
-    ==2018==    by 0x438107E:
-    
apache::geode::client::TcrMessage::readObjectPart(apache::geode::client::DataInput&,
-    bool)
-    (DataInput.hpp:694)
-    ==2018==    by 0x4375638:
-    apache::geode::client::TcrMessage::handleByteArrayResponse(char
-    const*, int, unsigned short) (TcrMessage.cpp:1087)
-    ==2018==    by 0x4375B2E: apache::geode::client::TcrMessage::setData(char
-    const*, int,
-    unsigned short) (TcrMessage.cpp:3933)
-    ==2018==    by 0x4367EE6:
-    
apache::geode::client::TcrEndpoint::sendRequestConn(apache::geode::client::TcrMessage
-    const&,
-    apache::geode::client::TcrMessage&, apache::geode::client::TcrConnection*,
-    stlp_std::basic_string<char,
-    stlp_std::char_traits<char>, stlp_std::allocator<char> >&)
-    (TcrEndpoint.cpp:764)
-    ==2018==    by 0x43682E3:
-    
apache::geode::client::TcrEndpoint::sendRequestWithRetry(apache::geode::client::TcrMessage
-    const&,
-    apache::geode::client::TcrMessage&, apache::geode::client::TcrConnection*&,
-    bool&,
-    stlp_std::basic_string<char, stlp_std::char_traits<char>,
-    stlp_std::allocator<char> >&, int, bool, long long, bool)
-    (TcrEndpoint.cpp:869)
-    ==2018==    by 0x4368EBA:
-    
apache::geode::client::TcrEndpoint::sendRequestConnWithRetry(apache::geode::client::TcrMessage
-    const&,
-    apache::geode::client::TcrMessage&, apache::geode::client::TcrConnection*&,
-    bool) (TcrEndpoint.cpp:1060)
-    ==2018==    by 0x4393D2D:
-    
apache::geode::client::ThinClientPoolDM::sendSyncRequest(apache::geode::client::TcrMessage&,
-    apache::geode::client::TcrMessage&, bool, bool,
-    
apache::geode::client::SharedPtr<apache::geode::client::BucketServerLocation>
-    const&)
-    (ThinClientPoolDM.cpp:1408)
-    ==2018==
-    */
     // TODO::Enable it once the PdxInstanceImple is CheckedIn.
-    PdxSerializablePtr pdxObject(new PdxInstanceImpl(
-        const_cast<uint8_t*>(dataInput.currentBufferPosition()), len, typeId));
+    auto pdxObject = std::make_shared<PdxInstanceImpl>(
+        const_cast<uint8_t*>(dataInput.currentBufferPosition()), len, typeId);
 
     dataInput.advanceCursor(len);
 
@@ -550,8 +415,8 @@ int32_t PdxHelper::readInt(uint8_t* offsetPosition, int 
size) {
 }
 
 int32_t PdxHelper::getEnumValue(const char* enumClassName, const char* 
enumName,
-                              int hashcode) {
-  EnumInfoPtr ei(new EnumInfo(enumClassName, enumName, hashcode));
+                                int hashcode) {
+  auto ei = std::make_shared<EnumInfo>(enumClassName, enumName, hashcode);
   return PdxTypeRegistry::getEnumValue(ei);
 }
 

http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/PdxHelper.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/PdxHelper.hpp b/src/cppcache/src/PdxHelper.hpp
index 9a84ef4..546278e 100644
--- a/src/cppcache/src/PdxHelper.hpp
+++ b/src/cppcache/src/PdxHelper.hpp
@@ -50,6 +50,9 @@ class PdxHelper {
   static void serializePdx(DataOutput& output,
                            const PdxSerializable& pdxObject);
 
+  static void serializePdx(DataOutput& output,
+                           const PdxSerializablePtr& pdxObject);
+
   static PdxSerializablePtr deserializePdx(DataInput& dataInput,
                                            bool forceDeserialize);
 
@@ -74,7 +77,7 @@ class PdxHelper {
   static int32_t readInt(uint8_t* offsetPosition, int size);
 
   static int32_t getEnumValue(const char* enumClassName, const char* enumName,
-                            int hashcode);
+                              int hashcode);
 
   static EnumInfoPtr getEnum(int enumId);
 

http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/PdxInstanceFactoryImpl.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/PdxInstanceFactoryImpl.cpp 
b/src/cppcache/src/PdxInstanceFactoryImpl.cpp
index 6342ec0..171b889 100644
--- a/src/cppcache/src/PdxInstanceFactoryImpl.cpp
+++ b/src/cppcache/src/PdxInstanceFactoryImpl.cpp
@@ -31,16 +31,17 @@ PdxInstanceFactoryImpl::PdxInstanceFactoryImpl(const char* 
className) {
       *className == '\0') {  // COVERITY ---> 30289 Same on both sides
     throw IllegalStateException("className should not be null.");
   }
-  m_pdxType = new PdxType(className, false);
+  m_pdxType = std::make_shared<PdxType>(className, false);
   m_created = false;
 }
 
-PdxInstancePtr PdxInstanceFactoryImpl::create() {
+std::unique_ptr<PdxInstance> PdxInstanceFactoryImpl::create() {
   if (m_created) {
     throw IllegalStateException(
         "The PdxInstanceFactory.Create() method can only be called once.");
   }
-  PdxInstancePtr pi(new PdxInstanceImpl(m_FieldVsValues, m_pdxType));
+  auto pi = std::unique_ptr<PdxInstance>(
+      new PdxInstanceImpl(m_FieldVsValues, m_pdxType));
   m_created = true;
   return pi;
 }
@@ -53,7 +54,7 @@ PdxInstanceFactoryPtr PdxInstanceFactoryImpl::writeWideChar(
   CacheablePtr cacheableObject = CacheableWideChar::create(value);
   m_FieldVsValues.insert(
       std::pair<const char*, CacheablePtr>(fieldName, cacheableObject));
-  return PdxInstanceFactoryPtr(this);
+  return shared_from_this();
 }
 
 PdxInstanceFactoryPtr PdxInstanceFactoryImpl::writeChar(const char* fieldName,
@@ -65,7 +66,7 @@ PdxInstanceFactoryPtr PdxInstanceFactoryImpl::writeChar(const 
char* fieldName,
   CacheablePtr cacheableObject = CacheableWideChar::create(tempWideChar);
   m_FieldVsValues.insert(
       std::pair<const char*, CacheablePtr>(fieldName, cacheableObject));
-  return PdxInstanceFactoryPtr(this);
+  return shared_from_this();
 }
 
 PdxInstanceFactoryPtr PdxInstanceFactoryImpl::writeBoolean(
@@ -76,7 +77,7 @@ PdxInstanceFactoryPtr PdxInstanceFactoryImpl::writeBoolean(
   CacheablePtr cacheableObject = CacheableBoolean::create(value);
   m_FieldVsValues.insert(
       std::pair<const char*, CacheablePtr>(fieldName, cacheableObject));
-  return PdxInstanceFactoryPtr(this);
+  return shared_from_this();
 }
 
 PdxInstanceFactoryPtr PdxInstanceFactoryImpl::writeByte(const char* fieldName,
@@ -87,7 +88,7 @@ PdxInstanceFactoryPtr PdxInstanceFactoryImpl::writeByte(const 
char* fieldName,
   CacheablePtr cacheableObject = CacheableByte::create(value);
   m_FieldVsValues.insert(
       std::pair<const char*, CacheablePtr>(fieldName, cacheableObject));
-  return PdxInstanceFactoryPtr(this);
+  return shared_from_this();
 }
 
 PdxInstanceFactoryPtr PdxInstanceFactoryImpl::writeShort(const char* fieldName,
@@ -98,7 +99,7 @@ PdxInstanceFactoryPtr 
PdxInstanceFactoryImpl::writeShort(const char* fieldName,
   CacheablePtr cacheableObject = CacheableInt16::create(value);
   m_FieldVsValues.insert(
       std::pair<const char*, CacheablePtr>(fieldName, cacheableObject));
-  return PdxInstanceFactoryPtr(this);
+  return shared_from_this();
 }
 
 PdxInstanceFactoryPtr PdxInstanceFactoryImpl::writeInt(const char* fieldName,
@@ -109,7 +110,7 @@ PdxInstanceFactoryPtr 
PdxInstanceFactoryImpl::writeInt(const char* fieldName,
   CacheablePtr cacheableObject = CacheableInt32::create(value);
   m_FieldVsValues.insert(
       std::pair<const char*, CacheablePtr>(fieldName, cacheableObject));
-  return PdxInstanceFactoryPtr(this);
+  return shared_from_this();
 }
 
 PdxInstanceFactoryPtr PdxInstanceFactoryImpl::writeLong(const char* fieldName,
@@ -120,7 +121,7 @@ PdxInstanceFactoryPtr 
PdxInstanceFactoryImpl::writeLong(const char* fieldName,
   CacheablePtr cacheableObject = CacheableInt64::create(value);
   m_FieldVsValues.insert(
       std::pair<const char*, CacheablePtr>(fieldName, cacheableObject));
-  return PdxInstanceFactoryPtr(this);
+  return shared_from_this();
 }
 
 PdxInstanceFactoryPtr PdxInstanceFactoryImpl::writeFloat(const char* fieldName,
@@ -131,7 +132,7 @@ PdxInstanceFactoryPtr 
PdxInstanceFactoryImpl::writeFloat(const char* fieldName,
   CacheablePtr cacheableObject = CacheableFloat::create(value);
   m_FieldVsValues.insert(
       std::pair<const char*, CacheablePtr>(fieldName, cacheableObject));
-  return PdxInstanceFactoryPtr(this);
+  return shared_from_this();
 }
 
 PdxInstanceFactoryPtr PdxInstanceFactoryImpl::writeDouble(const char* 
fieldName,
@@ -142,7 +143,7 @@ PdxInstanceFactoryPtr 
PdxInstanceFactoryImpl::writeDouble(const char* fieldName,
   CacheablePtr cacheableObject = CacheableDouble::create(value);
   m_FieldVsValues.insert(
       std::pair<const char*, CacheablePtr>(fieldName, cacheableObject));
-  return PdxInstanceFactoryPtr(this);
+  return shared_from_this();
 }
 
 PdxInstanceFactoryPtr PdxInstanceFactoryImpl::writeWideString(
@@ -153,7 +154,7 @@ PdxInstanceFactoryPtr 
PdxInstanceFactoryImpl::writeWideString(
   CacheablePtr cacheableObject = CacheableString::create(value);
   m_FieldVsValues.insert(
       std::pair<const char*, CacheablePtr>(fieldName, cacheableObject));
-  return PdxInstanceFactoryPtr(this);
+  return shared_from_this();
 }
 
 PdxInstanceFactoryPtr PdxInstanceFactoryImpl::writeString(const char* 
fieldName,
@@ -164,7 +165,7 @@ PdxInstanceFactoryPtr 
PdxInstanceFactoryImpl::writeString(const char* fieldName,
   CacheablePtr cacheableObject = CacheableString::create(value);
   m_FieldVsValues.insert(
       std::pair<const char*, CacheablePtr>(fieldName, cacheableObject));
-  return PdxInstanceFactoryPtr(this);
+  return shared_from_this();
 }
 
 PdxInstanceFactoryPtr PdxInstanceFactoryImpl::writeObject(const char* 
fieldName,
@@ -174,7 +175,7 @@ PdxInstanceFactoryPtr 
PdxInstanceFactoryImpl::writeObject(const char* fieldName,
                                         PdxFieldTypes::OBJECT);
   m_FieldVsValues.insert(
       std::pair<const char*, CacheablePtr>(fieldName, value));
-  return PdxInstanceFactoryPtr(this);
+  return shared_from_this();
 }
 
 PdxInstanceFactoryPtr PdxInstanceFactoryImpl::writeObjectArray(
@@ -184,7 +185,7 @@ PdxInstanceFactoryPtr 
PdxInstanceFactoryImpl::writeObjectArray(
                                         PdxFieldTypes::OBJECT_ARRAY);
   m_FieldVsValues.insert(
       std::pair<const char*, CacheablePtr>(fieldName, value));
-  return PdxInstanceFactoryPtr(this);
+  return shared_from_this();
 }
 
 PdxInstanceFactoryPtr PdxInstanceFactoryImpl::writeBooleanArray(
@@ -195,7 +196,7 @@ PdxInstanceFactoryPtr 
PdxInstanceFactoryImpl::writeBooleanArray(
   CacheablePtr cacheableObject = BooleanArray::create(value, length);
   m_FieldVsValues.insert(
       std::pair<std::string, CacheablePtr>(fieldName, cacheableObject));
-  return PdxInstanceFactoryPtr(this);
+  return shared_from_this();
 }
 
 PdxInstanceFactoryPtr PdxInstanceFactoryImpl::writeWideCharArray(
@@ -206,7 +207,7 @@ PdxInstanceFactoryPtr 
PdxInstanceFactoryImpl::writeWideCharArray(
   CacheablePtr cacheableObject = CharArray::create(value, length);
   m_FieldVsValues.insert(
       std::pair<const char*, CacheablePtr>(fieldName, cacheableObject));
-  return PdxInstanceFactoryPtr(this);
+  return shared_from_this();
 }
 
 PdxInstanceFactoryPtr PdxInstanceFactoryImpl::writeCharArray(
@@ -221,7 +222,7 @@ PdxInstanceFactoryPtr 
PdxInstanceFactoryImpl::writeCharArray(
   m_FieldVsValues.insert(
       std::pair<const char*, CacheablePtr>(fieldName, cacheableObject));
   delete[] tempWideCharArray;
-  return PdxInstanceFactoryPtr(this);
+  return shared_from_this();
 }
 
 PdxInstanceFactoryPtr PdxInstanceFactoryImpl::writeByteArray(
@@ -233,7 +234,7 @@ PdxInstanceFactoryPtr 
PdxInstanceFactoryImpl::writeByteArray(
       CacheableBytes::create(reinterpret_cast<uint8_t*>(value), length);
   m_FieldVsValues.insert(
       std::pair<const char*, CacheablePtr>(fieldName, cacheableObject));
-  return PdxInstanceFactoryPtr(this);
+  return shared_from_this();
 }
 
 PdxInstanceFactoryPtr PdxInstanceFactoryImpl::writeShortArray(
@@ -244,7 +245,7 @@ PdxInstanceFactoryPtr 
PdxInstanceFactoryImpl::writeShortArray(
   CacheablePtr cacheableObject = CacheableInt16Array::create(value, length);
   m_FieldVsValues.insert(
       std::pair<const char*, CacheablePtr>(fieldName, cacheableObject));
-  return PdxInstanceFactoryPtr(this);
+  return shared_from_this();
 }
 
 PdxInstanceFactoryPtr PdxInstanceFactoryImpl::writeIntArray(
@@ -255,7 +256,7 @@ PdxInstanceFactoryPtr PdxInstanceFactoryImpl::writeIntArray(
   CacheablePtr cacheableObject = CacheableInt32Array::create(value, length);
   m_FieldVsValues.insert(
       std::pair<const char*, CacheablePtr>(fieldName, cacheableObject));
-  return PdxInstanceFactoryPtr(this);
+  return shared_from_this();
 }
 
 PdxInstanceFactoryPtr PdxInstanceFactoryImpl::writeLongArray(
@@ -266,7 +267,7 @@ PdxInstanceFactoryPtr 
PdxInstanceFactoryImpl::writeLongArray(
   CacheablePtr cacheableObject = CacheableInt64Array::create(value, length);
   m_FieldVsValues.insert(
       std::pair<const char*, CacheablePtr>(fieldName, cacheableObject));
-  return PdxInstanceFactoryPtr(this);
+  return shared_from_this();
 }
 
 PdxInstanceFactoryPtr PdxInstanceFactoryImpl::writeFloatArray(
@@ -277,7 +278,7 @@ PdxInstanceFactoryPtr 
PdxInstanceFactoryImpl::writeFloatArray(
   CacheablePtr cacheableObject = CacheableFloatArray::create(value, length);
   m_FieldVsValues.insert(
       std::pair<const char*, CacheablePtr>(fieldName, cacheableObject));
-  return PdxInstanceFactoryPtr(this);
+  return shared_from_this();
 }
 
 PdxInstanceFactoryPtr PdxInstanceFactoryImpl::writeDoubleArray(
@@ -288,7 +289,7 @@ PdxInstanceFactoryPtr 
PdxInstanceFactoryImpl::writeDoubleArray(
   CacheablePtr cacheableObject = CacheableDoubleArray::create(value, length);
   m_FieldVsValues.insert(
       std::pair<const char*, CacheablePtr>(fieldName, cacheableObject));
-  return PdxInstanceFactoryPtr(this);
+  return shared_from_this();
 }
 
 PdxInstanceFactoryPtr PdxInstanceFactoryImpl::writeStringArray(
@@ -314,7 +315,7 @@ PdxInstanceFactoryPtr 
PdxInstanceFactoryImpl::writeStringArray(
   if (ptrArr) {
     delete[] ptrArr;
   }
-  return PdxInstanceFactoryPtr(this);
+  return shared_from_this();
 }
 
 PdxInstanceFactoryPtr PdxInstanceFactoryImpl::writeWideStringArray(
@@ -340,7 +341,7 @@ PdxInstanceFactoryPtr 
PdxInstanceFactoryImpl::writeWideStringArray(
   if (ptrArr) {
     delete[] ptrArr;
   }
-  return PdxInstanceFactoryPtr(this);
+  return shared_from_this();
 }
 
 PdxInstanceFactoryPtr PdxInstanceFactoryImpl::writeDate(
@@ -350,7 +351,7 @@ PdxInstanceFactoryPtr PdxInstanceFactoryImpl::writeDate(
                                      PdxTypes::DATE_SIZE /*+ 1*/);
   m_FieldVsValues.insert(
       std::pair<const char*, CacheablePtr>(fieldName, value));
-  return PdxInstanceFactoryPtr(this);
+  return shared_from_this();
 }
 
 PdxInstanceFactoryPtr PdxInstanceFactoryImpl::writeArrayOfByteArrays(
@@ -367,18 +368,18 @@ PdxInstanceFactoryPtr 
PdxInstanceFactoryImpl::writeArrayOfByteArrays(
   }
   m_FieldVsValues.insert(
       std::pair<const char*, CacheablePtr>(fieldName, cacheableObject));
-  return PdxInstanceFactoryPtr(this);
+  return shared_from_this();
 }
 
 PdxInstanceFactoryPtr PdxInstanceFactoryImpl::markIdentityField(
     const char* fieldName) {
   PdxFieldTypePtr pfType = m_pdxType->getPdxField(fieldName);
-  if (pfType == NULLPTR) {
+  if (pfType == nullptr) {
     throw IllegalStateException(
         "Field must be added before calling MarkIdentityField ");
   }
   pfType->setIdentityField(true);
-  return PdxInstanceFactoryPtr(this);
+  return shared_from_this();
 }
 
 void PdxInstanceFactoryImpl::isFieldAdded(const char* fieldName) {

http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/PdxInstanceFactoryImpl.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/PdxInstanceFactoryImpl.hpp 
b/src/cppcache/src/PdxInstanceFactoryImpl.hpp
index 228a34e..fe49eb8 100644
--- a/src/cppcache/src/PdxInstanceFactoryImpl.hpp
+++ b/src/cppcache/src/PdxInstanceFactoryImpl.hpp
@@ -42,7 +42,9 @@ typedef std::map<std::string, CacheablePtr> FieldVsValues;
 * multiple factories or use {@link PdxInstance#createWriter} to create
 * subsequent instances.
 */
-class CPPCACHE_EXPORT PdxInstanceFactoryImpl : public PdxInstanceFactory {
+class CPPCACHE_EXPORT PdxInstanceFactoryImpl
+    : public PdxInstanceFactory,
+      public std::enable_shared_from_this<PdxInstanceFactoryImpl> {
  public:
   /**
   * @brief destructor
@@ -56,7 +58,7 @@ class CPPCACHE_EXPORT PdxInstanceFactoryImpl : public 
PdxInstanceFactory {
   * @return the created Pdxinstance
   * @throws IllegalStateException if called more than once
   */
-  virtual PdxInstancePtr create();
+  virtual std::unique_ptr<PdxInstance> create();
 
   /**
   * Writes the named field with the given value to the serialized form.

Reply via email to