http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/LRUEntriesMap.cpp ---------------------------------------------------------------------- diff --git a/src/cppcache/src/LRUEntriesMap.cpp b/src/cppcache/src/LRUEntriesMap.cpp index 4b30513..29a0aff 100644 --- a/src/cppcache/src/LRUEntriesMap.cpp +++ b/src/cppcache/src/LRUEntriesMap.cpp @@ -63,16 +63,14 @@ LRUEntriesMap::LRUEntriesMap(EntryFactory* entryFactory, RegionInternal* region, concurrency), m_lruList(), m_limit(limit), - m_pmPtr(NULLPTR), + m_pmPtr(nullptr), m_validEntries(0), m_heapLRUEnabled(heapLRUEnabled) { m_currentMapSize = 0; m_action = NULL; m_evictionControllerPtr = NULL; // translate action type to an instance. - if (region == NULL) { - m_action = new TestMapAction(this); - } else { + if (region) { m_action = LRUAction::newLRUAction(lruAction, region, this); m_name = region->getName(); CacheImpl* cImpl = region->getCacheImpl(); @@ -84,6 +82,8 @@ LRUEntriesMap::LRUEntriesMap(EntryFactory* entryFactory, RegionInternal* region, m_name.c_str()); } } + } else { + m_action = new TestMapAction(this); } } @@ -131,7 +131,7 @@ GfErrType LRUEntriesMap::create(const CacheableKeyPtr& key, } CacheablePtr tmpValue; segmentRPtr->getEntry(key, mePtr, tmpValue); - if (mePtr == NULLPTR) { + if (mePtr == nullptr) { return err; } m_lruList.appendEntry(mePtr); @@ -141,7 +141,7 @@ GfErrType LRUEntriesMap::create(const CacheableKeyPtr& key, int64_t newSize = static_cast<int64_t>(Utils::checkAndGetObjectSize(newValue)); newSize += static_cast<int64_t>(Utils::checkAndGetObjectSize(key)); - if (oldValue != NULLPTR) { + if (oldValue != nullptr) { newSize -= static_cast<int64_t>(oldValue->objectSize()); } else { newSize -= static_cast<int64_t>(sizeof(void*)); @@ -165,7 +165,7 @@ GfErrType LRUEntriesMap::evictionHelper() { // ACE_Guard< ACE_Recursive_Thread_Mutex > guard( m_mutex ); MapEntryImplPtr lruEntryPtr; m_lruList.getLRUEntry(lruEntryPtr); - if (lruEntryPtr == NULLPTR) { + if (lruEntryPtr == nullptr) { err = GF_ENOENT; return err; } @@ -225,7 +225,7 @@ GfErrType LRUEntriesMap::invalidate(const CacheableKeyPtr& key, // need to assess the effect of this; also assess the affect of above // mentioned race oldValue = m_pmPtr->read(key, persistenceInfo); - if (oldValue != NULLPTR) { + if (oldValue != nullptr) { m_pmPtr->destroy(key, persistenceInfo); } } @@ -233,7 +233,7 @@ GfErrType LRUEntriesMap::invalidate(const CacheableKeyPtr& key, --m_validEntries; me->getLRUProperties().setEvicted(); newSize = CacheableToken::invalid()->objectSize(); - if (oldValue != NULLPTR) { + if (oldValue != nullptr) { newSize -= oldValue->objectSize(); } else { newSize -= sizeof(void*); @@ -292,7 +292,7 @@ GfErrType LRUEntriesMap::put(const CacheableKeyPtr& key, } void* persistenceInfo = me->getLRUProperties().getPersistenceInfo(); oldValue = m_pmPtr->read(key, persistenceInfo); - if (oldValue != NULLPTR) { + if (oldValue != nullptr) { m_pmPtr->destroy(key, persistenceInfo); } } @@ -315,7 +315,7 @@ GfErrType LRUEntriesMap::put(const CacheableKeyPtr& key, segmentRPtr->getEntry(key, mePtr, tmpValue); // mePtr cannot be null, we just put it... // must convert to an LRUMapEntryImplPtr... - GF_D_ASSERT(mePtr != NULLPTR); + GF_D_ASSERT(mePtr != nullptr); m_lruList.appendEntry(mePtr); me = mePtr; } else { @@ -342,7 +342,7 @@ GfErrType LRUEntriesMap::put(const CacheableKeyPtr& key, if (isUpdate == false) { newSize += static_cast<int64_t>(Utils::checkAndGetObjectSize(key)); } else { - if (oldValue != NULLPTR) { + if (oldValue != nullptr) { newSize -= static_cast<int64_t>(oldValue->objectSize()); } else { newSize -= static_cast<int64_t>(sizeof(void*)); @@ -377,7 +377,7 @@ bool LRUEntriesMap::get(const CacheableKeyPtr& key, CacheablePtr& returnPtr, segmentLocked = true; } { - returnPtr = NULLPTR; + returnPtr = nullptr; MapEntryImplPtr mePtr; if (false == segmentRPtr->getEntry(key, mePtr, returnPtr)) { if (segmentLocked == true) segmentRPtr->release(); @@ -386,7 +386,7 @@ bool LRUEntriesMap::get(const CacheableKeyPtr& key, CacheablePtr& returnPtr, // segmentRPtr->get(key, returnPtr, mePtr); MapEntryImplPtr nodeToMark = mePtr; LRUEntryProperties& lruProps = nodeToMark->getLRUProperties(); - if (returnPtr != NULLPTR && CacheableToken::isOverflowed(returnPtr)) { + if (returnPtr != nullptr && CacheableToken::isOverflowed(returnPtr)) { void* persistenceInfo = lruProps.getPersistenceInfo(); CacheablePtr tmpObj; try { @@ -396,8 +396,8 @@ bool LRUEntriesMap::get(const CacheableKeyPtr& key, CacheablePtr& returnPtr, if (segmentLocked == true) segmentRPtr->release(); return false; } - (m_region->getRegionStats())->incRetrieves(); - (m_region->getCacheImpl())->m_cacheStats->incRetrieves(); + m_region->getRegionStats()->incRetrieves(); + m_region->getCacheImpl()->m_cacheStats->incRetrieves(); returnPtr = tmpObj; @@ -415,7 +415,7 @@ bool LRUEntriesMap::get(const CacheableKeyPtr& key, CacheablePtr& returnPtr, doProcessLRU = true; if (m_evictionControllerPtr != NULL) { int64_t newSize = 0; - if (tmpObj != NULLPTR) { + if (tmpObj != nullptr) { newSize += static_cast<int64_t>( tmpObj->objectSize() - CacheableToken::invalid()->objectSize()); } else { @@ -453,7 +453,7 @@ GfErrType LRUEntriesMap::remove(const CacheableKeyPtr& key, if ((err = segmentRPtr->remove(key, result, me, updateCount, versionTag, afterRemote, isEntryFound)) == GF_NOERR) { // ACE_Guard<MapSegment> _guard(*segmentRPtr); - if (result != NULLPTR && me != NULLPTR) { + if (result != nullptr && me != nullptr) { LRUEntryProperties& lruProps = me->getLRUProperties(); lruProps.setEvicted(); if (isEntryFound) --m_size; @@ -471,7 +471,7 @@ GfErrType LRUEntriesMap::remove(const CacheableKeyPtr& key, // need to assess the effect of this; also assess the affect of above // mentioned race result = m_pmPtr->read(key, persistenceInfo); - if (result != NULLPTR) { + if (result != nullptr) { m_pmPtr->destroy(key, persistenceInfo); } } @@ -498,7 +498,7 @@ void LRUEntriesMap::updateMapSize(int64_t size) { } CacheablePtr LRUEntriesMap::getFromDisk(const CacheableKeyPtr& key, - MapEntryImpl* me) const { + MapEntryImplPtr& me) const { void* persistenceInfo = me->getLRUProperties().getPersistenceInfo(); CacheablePtr tmpObj; try { @@ -507,7 +507,7 @@ CacheablePtr LRUEntriesMap::getFromDisk(const CacheableKeyPtr& key, tmpObj = m_pmPtr->read(key, persistenceInfo); } catch (Exception& ex) { LOGERROR("read on the persistence layer failed - %s", ex.getMessage()); - return NULLPTR; + return nullptr; } return tmpObj; }
http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/LRUEntriesMap.hpp ---------------------------------------------------------------------- diff --git a/src/cppcache/src/LRUEntriesMap.hpp b/src/cppcache/src/LRUEntriesMap.hpp index 3efcbeb..a50658f 100644 --- a/src/cppcache/src/LRUEntriesMap.hpp +++ b/src/cppcache/src/LRUEntriesMap.hpp @@ -94,7 +94,7 @@ class CPPCACHE_EXPORT LRUEntriesMap : public ConcurrentEntriesMap, virtual bool get(const CacheableKeyPtr& key, CacheablePtr& returnPtr, MapEntryImplPtr& me); virtual CacheablePtr getFromDisk(const CacheableKeyPtr& key, - MapEntryImpl* me) const; + MapEntryImplPtr& me) const; GfErrType processLRU(); void processLRU(int32_t numEntriesToEvict); GfErrType evictionHelper(); http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/LRUList.cpp ---------------------------------------------------------------------- diff --git a/src/cppcache/src/LRUList.cpp b/src/cppcache/src/LRUList.cpp index c752faa..c8d9fbd 100644 --- a/src/cppcache/src/LRUList.cpp +++ b/src/cppcache/src/LRUList.cpp @@ -24,7 +24,7 @@ using namespace apache::geode::client; template <typename TEntry, typename TCreateEntry> LRUList<TEntry, TCreateEntry>::LRUList() : m_headLock(), m_tailLock() { - LRUListEntryPtr headEntry(TCreateEntry::create(NULLPTR)); + LRUListEntryPtr headEntry(TCreateEntry::create(nullptr)); headEntry->getLRUProperties().setEvicted(); // create empty evicted entry. m_headNode = new LRUListNode(headEntry); m_tailNode = m_headNode; @@ -68,7 +68,7 @@ void LRUList<TEntry, TCreateEntry>::getLRUEntry(LRUListEntryPtr& result) { while (true) { aNode = getHeadNode(isLast); if (aNode == NULL) { - result = NULLPTR; + result = nullptr; break; } aNode->getEntry(result); @@ -88,7 +88,7 @@ void LRUList<TEntry, TCreateEntry>::getLRUEntry(LRUListEntryPtr& result) { break; // found unused entry } } else { - result = NULLPTR; // remove the reference to entry + result = nullptr; // remove the reference to entry delete aNode; // drop the entry to the floor ... } } http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/LRULocalDestroyAction.cpp ---------------------------------------------------------------------- diff --git a/src/cppcache/src/LRULocalDestroyAction.cpp b/src/cppcache/src/LRULocalDestroyAction.cpp index 633c5cc..e0cc06d 100644 --- a/src/cppcache/src/LRULocalDestroyAction.cpp +++ b/src/cppcache/src/LRULocalDestroyAction.cpp @@ -30,7 +30,7 @@ bool LRULocalDestroyAction::evict(const MapEntryImplPtr& mePtr) { LOGDEBUG("LRULocalDestroy: evicting entry with key [%s]", Utils::getCacheableKeyString(keyPtr)->asChar()); GfErrType err = m_regionPtr->destroyNoThrow( - keyPtr, NULLPTR, -1, CacheEventFlags::EVICTION | CacheEventFlags::LOCAL, + keyPtr, nullptr, -1, CacheEventFlags::EVICTION | CacheEventFlags::LOCAL, versionTag); return (err == GF_NOERR); } http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/LocalRegion.cpp ---------------------------------------------------------------------- diff --git a/src/cppcache/src/LocalRegion.cpp b/src/cppcache/src/LocalRegion.cpp index 5e61580..6de7774 100644 --- a/src/cppcache/src/LocalRegion.cpp +++ b/src/cppcache/src/LocalRegion.cpp @@ -37,7 +37,7 @@ using namespace apache::geode::client; LocalRegion::LocalRegion(const std::string& name, CacheImpl* cache, - RegionInternal* rPtr, + const RegionInternalPtr& rPtr, const RegionAttributesPtr& attributes, const CacheStatisticsPtr& stats, bool shared) : RegionInternal(attributes), @@ -45,17 +45,17 @@ LocalRegion::LocalRegion(const std::string& name, CacheImpl* cache, m_parentRegion(rPtr), m_cacheImpl(cache), m_destroyPending(false), - m_listener(NULLPTR), - m_writer(NULLPTR), - m_loader(NULLPTR), + m_listener(nullptr), + m_writer(nullptr), + m_loader(nullptr), m_released(false), m_entries(NULL), m_cacheStatistics(stats), m_transactionEnabled(false), m_isPRSingleHopEnabled(false), - m_attachedPool(NULLPTR), - m_persistenceManager(NULLPTR) { - if (m_parentRegion != NULLPTR) { + m_attachedPool(nullptr), + m_persistenceManager(nullptr) { + if (m_parentRegion != nullptr) { ((m_fullPath = m_parentRegion->getFullPath()) += "/") += m_name; } else { (m_fullPath = "/") += m_name; @@ -76,7 +76,7 @@ LocalRegion::LocalRegion(const std::string& name, CacheImpl* cache, cldptr = m_regionAttributes->getCacheLoader(); m_loader = cldptr; - if (m_parentRegion != NULLPTR) { + if (m_parentRegion != nullptr) { ((m_fullPath = m_parentRegion->getFullPath()) += "/") += m_name; } else { (m_fullPath = "/") += m_name; @@ -110,7 +110,7 @@ void LocalRegion::updateAccessAndModifiedTime(bool modified) { m_cacheStatistics->setLastModifiedTime(static_cast<uint32_t>(currTime)); } // TODO: should we really touch the parent region?? - RegionInternal* ri = dynamic_cast<RegionInternal*>(m_parentRegion.ptr()); + RegionInternal* ri = dynamic_cast<RegionInternal*>(m_parentRegion.get()); if (ri != NULL) { ri->updateAccessAndModifiedTime(modified); } @@ -164,17 +164,18 @@ void LocalRegion::tombstoneOperationNoThrow( if (!cachingEnabled) return; - if (tombstoneVersions.ptr() != NULL) { + if (tombstoneVersions.get() != NULL) { std::map<uint16_t, int64_t> gcVersions; for (HashMapT<CacheableKeyPtr, CacheablePtr>::Iterator itr = tombstoneVersions->begin(); itr != tombstoneVersions->end(); ++itr) { try { - DSMemberForVersionStampPtr member = - dynCast<DSMemberForVersionStampPtr>(itr.first()); + auto member = + std::dynamic_pointer_cast<DSMemberForVersionStamp>(itr.first()); uint16_t memberId = getCacheImpl()->getMemberListForVersionStamp()->add(member); - int64_t version = (dynCast<CacheableInt64Ptr>(itr.second()))->value(); + int64_t version = + (std::dynamic_pointer_cast<CacheableInt64>(itr.second()))->value(); gcVersions[memberId] = version; } catch (const ClassCastException&) { LOGERROR( @@ -240,9 +241,11 @@ RegionPtr LocalRegion::createSubregion( "LocalRegion::createSubregion: named region exists in the region"); } - CacheStatisticsPtr csptr(new CacheStatistics); - RegionInternal* rPtr = m_cacheImpl->createRegion_internal( - subregionName, this, aRegionAttributes, csptr, false); + auto csptr = std::make_shared<CacheStatistics>(); + RegionInternalPtr rPtr = m_cacheImpl->createRegion_internal( + subregionName, + std::static_pointer_cast<RegionInternal>(shared_from_this()), + aRegionAttributes, csptr, false); region_ptr = rPtr; if (!rPtr) { throw OutOfMemoryException("createSubregion: failed to create region"); @@ -251,7 +254,7 @@ RegionPtr LocalRegion::createSubregion( // Instantiate a PersistenceManager object if DiskPolicy is overflow if (aRegionAttributes->getDiskPolicy() == DiskPolicyType::OVERFLOWS) { PersistenceManagerPtr pmPtr = aRegionAttributes->getPersistenceManager(); - if (pmPtr == NULLPTR) { + if (pmPtr == nullptr) { throw NullPointerException( "PersistenceManager could not be instantiated"); } @@ -285,14 +288,14 @@ RegionEntryPtr LocalRegion::getEntry(const CacheableKeyPtr& key) { RegionEntryPtr rptr; CacheablePtr valuePtr; getEntry(key, valuePtr); - if (valuePtr != NULLPTR) { + if (valuePtr != nullptr) { rptr = createRegionEntry(key, valuePtr); } return rptr; } void LocalRegion::getEntry(const CacheableKeyPtr& key, CacheablePtr& valuePtr) { - if (key == NULLPTR) { + if (key == nullptr) { throw IllegalArgumentException("LocalRegion::getEntry: null key"); } @@ -329,7 +332,7 @@ void LocalRegion::put(const CacheableKeyPtr& key, const CacheablePtr& value, Utils::updateStatOpTime(m_regionStats->getStat(), RegionStatType::getInstance()->getPutTimeId(), sampleStartNanos); - // handleReplay(err, NULLPTR); + // handleReplay(err, nullptr); GfErrTypeToException("Region::put", err); } @@ -355,7 +358,7 @@ void LocalRegion::putAll(const HashMapOfCacheable& map, uint32_t timeout, Utils::updateStatOpTime(m_regionStats->getStat(), RegionStatType::getInstance()->getPutAllTimeId(), sampleStartNanos); - // handleReplay(err, NULLPTR); + // handleReplay(err, nullptr); GfErrTypeToException("Region::putAll", err); } @@ -377,7 +380,7 @@ void LocalRegion::create(const CacheableKeyPtr& key, const CacheablePtr& value, VersionTagPtr versionTag; GfErrType err = createNoThrow(key, value, aCallbackArgument, -1, CacheEventFlags::NORMAL, versionTag); - // handleReplay(err, NULLPTR); + // handleReplay(err, nullptr); GfErrTypeToException("Region::create", err); } @@ -395,7 +398,7 @@ void LocalRegion::invalidate(const CacheableKeyPtr& key, VersionTagPtr versionTag; GfErrType err = invalidateNoThrow(key, aCallbackArgument, -1, CacheEventFlags::NORMAL, versionTag); - // handleReplay(err, NULLPTR); + // handleReplay(err, nullptr); GfErrTypeToException("Region::invalidate", err); } @@ -413,7 +416,7 @@ void LocalRegion::destroy(const CacheableKeyPtr& key, GfErrType err = destroyNoThrow(key, aCallbackArgument, -1, CacheEventFlags::NORMAL, versionTag); - // handleReplay(err, NULLPTR); + // handleReplay(err, nullptr); GfErrTypeToException("Region::destroy", err); } @@ -532,7 +535,7 @@ void LocalRegion::getAll(const VectorOfCacheableKey& keys, throw IllegalArgumentException("Region::getAll: zero keys provided"); } // check for the combination which will result in no action - if (values == NULLPTR && + if (values == nullptr && !(addToLocalCache && m_regionAttributes->getCachingEnabled())) { throw IllegalArgumentException( "Region::getAll: either output \"values\"" @@ -547,7 +550,7 @@ void LocalRegion::getAll(const VectorOfCacheableKey& keys, Utils::updateStatOpTime(m_regionStats->getStat(), RegionStatType::getInstance()->getGetAllTimeId(), sampleStartNanos); - // handleReplay(err, NULLPTR); + // handleReplay(err, nullptr); GfErrTypeToException("Region::getAll", err); } uint32_t LocalRegion::size_remote() { @@ -572,10 +575,10 @@ uint32_t LocalRegion::size() { RegionServicePtr LocalRegion::getRegionService() const { CHECK_DESTROY_PENDING(TryReadGuard, LocalRegion::getRegionService); - return RegionServicePtr(m_cacheImpl->getCache()); + return m_cacheImpl->getCache()->shared_from_this(); } -CacheImpl* LocalRegion::getCacheImpl() { +CacheImpl* LocalRegion::getCacheImpl() const { CHECK_DESTROY_PENDING(TryReadGuard, LocalRegion::getCache); return m_cacheImpl; } @@ -589,14 +592,14 @@ bool LocalRegion::containsValueForKey_remote( CacheablePtr valuePtr; MapEntryImplPtr mePtr; m_entries->getEntry(keyPtr, mePtr, valuePtr); - if (mePtr == NULLPTR) { + if (mePtr == nullptr) { return false; } - return (valuePtr != NULLPTR && !CacheableToken::isInvalid(valuePtr)); + return (valuePtr != nullptr && !CacheableToken::isInvalid(valuePtr)); } bool LocalRegion::containsValueForKey(const CacheableKeyPtr& keyPtr) const { - if (keyPtr == NULLPTR) { + if (keyPtr == nullptr) { throw IllegalArgumentException( "LocalRegion::containsValueForKey: " "key is null"); @@ -624,7 +627,7 @@ void LocalRegion::getInterestListRegex(VectorOfCacheableString& vregex) const { } bool LocalRegion::containsKey(const CacheableKeyPtr& keyPtr) const { - if (keyPtr == NULLPTR) { + if (keyPtr == nullptr) { throw IllegalArgumentException( "LocalRegion::containsKey: " "key is null"); @@ -644,7 +647,8 @@ void LocalRegion::setPersistenceManager(PersistenceManagerPtr& pmPtr) { void LocalRegion::setRegionExpiryTask() { if (regionExpiryEnabled()) { - RegionInternalPtr rptr(this); + RegionInternalPtr rptr = + std::static_pointer_cast<RegionInternal>(shared_from_this()); uint32_t duration = getRegionExpiryDuration(); RegionExpiryHandler* handler = new RegionExpiryHandler(rptr, getRegionExpiryAction(), duration); @@ -663,7 +667,8 @@ void LocalRegion::registerEntryExpiryTask(MapEntryImplPtr& entry) { // the entry will register the expiry task for that entry ExpEntryProperties& expProps = entry->getExpProperties(); expProps.initStartTime(); - RegionInternalPtr rptr(this); + RegionInternalPtr rptr = + std::static_pointer_cast<RegionInternal>(shared_from_this()); uint32_t duration = getEntryExpiryDuration(); EntryExpiryHandler* handler = new EntryExpiryHandler(rptr, entry, getEntryExpirationAction(), duration); @@ -686,9 +691,9 @@ LocalRegion::~LocalRegion() { if (!m_destroyPending) { release(false); } - m_listener = NULLPTR; - m_writer = NULLPTR; - m_loader = NULLPTR; + m_listener = nullptr; + m_writer = nullptr; + m_loader = nullptr; GF_SAFE_DELETE(m_entries); GF_SAFE_DELETE(m_regionStats); @@ -709,11 +714,11 @@ void LocalRegion::release(bool invokeCallbacks) { } if (invokeCallbacks) { try { - if (m_loader != NULLPTR) { - m_loader->close(RegionPtr(this)); + if (m_loader != nullptr) { + m_loader->close(shared_from_this()); } - if (m_writer != NULLPTR) { - m_writer->close(RegionPtr(this)); + if (m_writer != nullptr) { + m_writer->close(shared_from_this()); } // TODO: shouldn't listener also be here instead of // during CacheImpl.close() @@ -724,9 +729,9 @@ void LocalRegion::release(bool invokeCallbacks) { } } - if (m_persistenceManager != NULLPTR) { + if (m_persistenceManager != nullptr) { m_persistenceManager->close(); - m_persistenceManager = NULLPTR; + m_persistenceManager = nullptr; } if (m_entries != NULL && m_regionAttributes->getCachingEnabled()) { m_entries->close(); @@ -745,7 +750,7 @@ void LocalRegion::release(bool invokeCallbacks) { *@throw NotConnectedException, if not connected to geode system. */ bool LocalRegion::containsKey_internal(const CacheableKeyPtr& keyPtr) const { - if (keyPtr == NULLPTR) { + if (keyPtr == nullptr) { throw IllegalArgumentException("Region::containsKey: key is null"); } if (!m_regionAttributes->getCachingEnabled()) { @@ -774,7 +779,7 @@ void LocalRegion::subregions_internal(const bool recursive, if (recursive == true) { // decend... for (int32_t i = 0; i < subRegions.size(); i++) { - dynamic_cast<LocalRegion*>(subRegions.at(i).ptr()) + dynamic_cast<LocalRegion*>(subRegions.at(i).get()) ->subregions_internal(true, sr); } } @@ -785,7 +790,7 @@ GfErrType LocalRegion::getNoThrow(const CacheableKeyPtr& keyPtr, const UserDataPtr& aCallbackArgument) { CHECK_DESTROY_PENDING_NOTHROW(TryReadGuard); GfErrType err = GF_NOERR; - if (keyPtr == NULLPTR) { + if (keyPtr == nullptr) { return GF_CACHE_ILLEGAL_ARGUMENT_EXCEPTION; } TXState* txState = getTXState(); @@ -800,7 +805,7 @@ GfErrType LocalRegion::getNoThrow(const CacheableKeyPtr& keyPtr, } if (CacheableToken::isInvalid(value) || CacheableToken::isTombstone(value)) { - value = NULLPTR; + value = nullptr; } return err; } @@ -816,10 +821,10 @@ GfErrType LocalRegion::getNoThrow(const CacheableKeyPtr& keyPtr, bool isLoaderInvoked = false; bool isLocal = false; bool cachingEnabled = m_regionAttributes->getCachingEnabled(); - CacheablePtr localValue = NULLPTR; + CacheablePtr localValue = nullptr; if (cachingEnabled) { isLocal = m_entries->get(keyPtr, value, me); - if (isLocal && (value != NULLPTR && !CacheableToken::isInvalid(value))) { + if (isLocal && (value != nullptr && !CacheableToken::isInvalid(value))) { m_regionStats->incHits(); m_cacheImpl->m_cacheStats->incHits(); updateAccessAndModifiedTimeForEntry(me, false); @@ -827,7 +832,7 @@ GfErrType LocalRegion::getNoThrow(const CacheableKeyPtr& keyPtr, return err; // found it in local cache... } localValue = value; - value = NULLPTR; + value = nullptr; // start tracking the entry if (!m_regionAttributes->getConcurrencyChecksEnabled()) { updateCount = @@ -871,14 +876,14 @@ GfErrType LocalRegion::getNoThrow(const CacheableKeyPtr& keyPtr, // Its a cache missor it is invalid token then Check if we have a local // loader. - if ((value == NULLPTR || CacheableToken::isInvalid(value) || + if ((value == nullptr || CacheableToken::isInvalid(value) || CacheableToken::isTombstone(value)) && - m_loader != NULLPTR) { + m_loader != nullptr) { try { isLoaderInvoked = true; /*Update the statistics*/ int64_t sampleStartNanos = Utils::startStatOpTime(); - value = m_loader->load(RegionPtr(this), keyPtr, aCallbackArgument); + value = m_loader->load(shared_from_this(), keyPtr, aCallbackArgument); Utils::updateStatOpTime( m_regionStats->getStat(), RegionStatType::getInstance()->getLoaderCallTimeId(), @@ -899,10 +904,10 @@ GfErrType LocalRegion::getNoThrow(const CacheableKeyPtr& keyPtr, CacheablePtr oldValue; // Found it somehow, so store it. - if (value != NULLPTR /*&& value != CacheableToken::invalid( )*/ && + if (value != nullptr /*&& value != CacheableToken::invalid( )*/ && cachingEnabled && !(CacheableToken::isTombstone(value) && - (localValue == NULLPTR || CacheableToken::isInvalid(localValue)))) { + (localValue == nullptr || CacheableToken::isInvalid(localValue)))) { // try to create the entry and if that returns an existing value // (e.g. from another thread or notification) then return that LOGDEBUG( @@ -919,7 +924,7 @@ GfErrType LocalRegion::getNoThrow(const CacheableKeyPtr& keyPtr, Utils::getCacheableKeyString(keyPtr)->asChar()); if (CacheableToken::isInvalid(value) || CacheableToken::isTombstone(value)) { - value = NULLPTR; + value = nullptr; } // don't do anything and exit return GF_NOERR; @@ -928,7 +933,7 @@ GfErrType LocalRegion::getNoThrow(const CacheableKeyPtr& keyPtr, LOGDEBUG("Region::get: putLocal for key [%s] failed with error %d", Utils::getCacheableKeyString(keyPtr)->asChar(), err); err = GF_NOERR; - if (oldValue != NULLPTR && !CacheableToken::isInvalid(oldValue)) { + if (oldValue != nullptr && !CacheableToken::isInvalid(oldValue)) { LOGDEBUG("Region::get: returning updated value [%s] for key [%s]", Utils::getCacheableString(oldValue)->asChar(), Utils::getCacheableKeyString(keyPtr)->asChar()); @@ -940,14 +945,14 @@ GfErrType LocalRegion::getNoThrow(const CacheableKeyPtr& keyPtr, } if (CacheableToken::isInvalid(value) || CacheableToken::isTombstone(value)) { - value = NULLPTR; + value = nullptr; } // invokeCacheListenerForEntryEvent method has the check that if oldValue // is a CacheableToken then it sets it to NULL; also determines if it // should be AFTER_UPDATE or AFTER_CREATE depending on oldValue, so don't // check here. - if (isLoaderInvoked == false && err == GF_NOERR && value != NULLPTR) { + if (isLoaderInvoked == false && err == GF_NOERR && value != nullptr) { err = invokeCacheListenerForEntryEvent( keyPtr, oldValue, value, aCallbackArgument, CacheEventFlags::NORMAL, AFTER_UPDATE, isLocal); @@ -972,17 +977,17 @@ GfErrType LocalRegion::getAllNoThrow(const VectorOfCacheableKey& keys, } // if(!txState->isReplay()) // { - // VectorOfCacheablePtr args(new VectorOfCacheable()); + // auto args = std::make_shared<VectorOfCacheable>(); // args->push_back(VectorOfCacheableKeyPtr(new // VectorOfCacheableKey(keys))); // args->push_back(values); // args->push_back(exceptions); // args->push_back(CacheableBoolean::create(addToLocalCache)); // txState->recordTXOperation(GF_GET_ALL, getFullPath(), - // NULLPTR, + // nullptr, // args); // } - err = getAllNoThrow_remote(&keys, values, exceptions, NULLPTR, false, + err = getAllNoThrow_remote(&keys, values, exceptions, nullptr, false, aCallbackArgument); if (err == GF_NOERR) { txState->setDirty(); @@ -999,11 +1004,11 @@ GfErrType LocalRegion::getAllNoThrow(const VectorOfCacheableKey& keys, for (int32_t index = 0; index < keys.size(); ++index) { const CacheableKeyPtr& key = keys[index]; MapEntryImplPtr me; - value = NULLPTR; + value = nullptr; m_regionStats->incGets(); m_cacheImpl->m_cacheStats->incGets(); - if (values != NULLPTR && cachingEnabled) { - if (m_entries->get(key, value, me) && value != NULLPTR && + if (values != nullptr && cachingEnabled) { + if (m_entries->get(key, value, me) && value != nullptr && !CacheableToken::isInvalid(value)) { m_regionStats->incHits(); m_cacheImpl->m_cacheStats->incHits(); @@ -1011,10 +1016,10 @@ GfErrType LocalRegion::getAllNoThrow(const VectorOfCacheableKey& keys, regionAccessed = true; values->insert(key, value); } else { - value = NULLPTR; + value = nullptr; } } - if (value == NULLPTR) { + if (value == nullptr) { // Add to missed keys list. serverKeys.push_back(key); @@ -1027,7 +1032,7 @@ GfErrType LocalRegion::getAllNoThrow(const VectorOfCacheableKey& keys, updateAccessAndModifiedTime(false); } if (serverKeys.size() > 0) { - err = getAllNoThrow_remote(&serverKeys, values, exceptions, NULLPTR, + err = getAllNoThrow_remote(&serverKeys, values, exceptions, nullptr, addToLocalCache, aCallbackArgument); } m_regionStats->incGetAll(); @@ -1055,7 +1060,7 @@ class PutActions { inline static GfErrType checkArgs(const CacheableKeyPtr& key, const CacheablePtr& value, DataInput* delta = NULL) { - if (key == NULLPTR || (value == NULLPTR && delta == NULL)) { + if (key == nullptr || (value == nullptr && delta == NULL)) { return GF_CACHE_ILLEGAL_ARGUMENT_EXCEPTION; } return GF_NOERR; @@ -1072,7 +1077,7 @@ class PutActions { inline static void logCacheWriterFailure(const CacheableKeyPtr& key, const CacheablePtr& oldValue) { - bool isUpdate = (oldValue != NULLPTR); + bool isUpdate = (oldValue != nullptr); LOGFINER("Cache writer vetoed %s for key %s", (isUpdate ? "update" : "create"), Utils::getCacheableKeyString(key)->asChar()); @@ -1084,7 +1089,7 @@ class PutActions { VersionTagPtr& versionTag) { // if(m_txState != NULL && !m_txState->isReplay()) // { - // VectorOfCacheablePtr args(new VectorOfCacheable()); + // auto args = std::make_shared<VectorOfCacheable>(); // args->push_back(value); // args->push_back(aCallbackArgument); // m_txState->recordTXOperation(GF_PUT, @@ -1101,7 +1106,7 @@ class PutActions { const CacheEventFlags eventFlags, int updateCount, VersionTagPtr versionTag, DataInput* delta = NULL, - EventIdPtr eventId = NULLPTR, + EventIdPtr eventId = nullptr, bool afterRemote = false) { return m_region.putLocal(name(), false, key, value, oldValue, cachingEnabled, updateCount, 0, versionTag, delta, @@ -1121,7 +1126,7 @@ class PutActionsTx : public PutActions { inline static GfErrType checkArgs(const CacheableKeyPtr& key, const CacheablePtr& value, DataInput* delta = NULL) { - if (key == NULLPTR) { + if (key == nullptr) { return GF_CACHE_ILLEGAL_ARGUMENT_EXCEPTION; } return GF_NOERR; @@ -1146,7 +1151,7 @@ class CreateActions { inline static GfErrType checkArgs(const CacheableKeyPtr& key, const CacheablePtr& value, DataInput* delta) { - if (key == NULLPTR) { + if (key == nullptr) { return GF_CACHE_ILLEGAL_ARGUMENT_EXCEPTION; } return GF_NOERR; @@ -1170,7 +1175,7 @@ class CreateActions { // propagate the create to remote server, if any // if(m_txState != NULL && !m_txState->isReplay()) // { - // VectorOfCacheablePtr args(new VectorOfCacheable()); + // auto args = std::make_shared<VectorOfCacheable>(); // args->push_back(value); // args->push_back(aCallbackArgument); // m_txState->recordTXOperation(GF_CREATE, @@ -1186,7 +1191,7 @@ class CreateActions { const CacheEventFlags eventFlags, int updateCount, VersionTagPtr versionTag, DataInput* delta = NULL, - EventIdPtr eventId = NULLPTR, + EventIdPtr eventId = nullptr, bool afterRemote = false) { return m_region.putLocal(name(), true, key, value, oldValue, cachingEnabled, updateCount, 0, versionTag); @@ -1214,7 +1219,7 @@ class DestroyActions { inline static GfErrType checkArgs(const CacheableKeyPtr& key, const CacheablePtr& value, DataInput* delta) { - if (key == NULLPTR) { + if (key == nullptr) { return GF_CACHE_ILLEGAL_ARGUMENT_EXCEPTION; } return GF_NOERR; @@ -1242,7 +1247,7 @@ class DestroyActions { // propagate the destroy to remote server, if any // if(m_txState != NULL && !m_txState->isReplay()) // { - // VectorOfCacheablePtr args(new VectorOfCacheable()); + // auto args = std::make_shared<VectorOfCacheable>(); // args->push_back(aCallbackArgument); // m_txState->recordTXOperation(GF_DESTROY, // m_region.getFullPath(), key, args); @@ -1257,7 +1262,7 @@ class DestroyActions { const CacheEventFlags eventFlags, int updateCount, VersionTagPtr versionTag, DataInput* delta = NULL, - EventIdPtr eventId = NULLPTR, + EventIdPtr eventId = nullptr, bool afterRemote = false) { if (cachingEnabled) { MapEntryImplPtr entry; @@ -1281,14 +1286,14 @@ class DestroyActions { } return err; } - if (oldValue != NULLPTR) { + if (oldValue != nullptr) { LOGDEBUG( "Region::destroy: region [%s] destroyed key [%s] having " "value [%s]", m_region.getFullPath(), Utils::getCacheableKeyString(key)->asChar(), Utils::getCacheableString(oldValue)->asChar()); // any cleanup required for the entry (e.g. removing from LRU list) - if (entry != NULLPTR) { + if (entry != nullptr) { entry->cleanup(eventFlags); } // entry/region expiration @@ -1331,7 +1336,7 @@ class RemoveActions { inline static GfErrType checkArgs(const CacheableKeyPtr& key, const CacheablePtr& value, DataInput* delta) { - if (key == NULLPTR) { + if (key == nullptr) { return GF_CACHE_ILLEGAL_ARGUMENT_EXCEPTION; } return GF_NOERR; @@ -1364,7 +1369,7 @@ class RemoveActions { DataOutput out1; DataOutput out2; - if (valuePtr != NULLPTR && value != NULLPTR) { + if (valuePtr != nullptr && value != nullptr) { if (valuePtr->classId() != value->classId() || valuePtr->typeId() != value->typeId()) { err = GF_ENOENT; @@ -1381,7 +1386,7 @@ class RemoveActions { err = GF_ENOENT; return err; } - } else if ((valuePtr == NULLPTR || CacheableToken::isInvalid(valuePtr))) { + } else if ((valuePtr == nullptr || CacheableToken::isInvalid(valuePtr))) { // if(m_txState != NULL && !m_txState->isReplay()) // { // VectorOfCacheablePtr args(new @@ -1396,14 +1401,14 @@ class RemoveActions { key, value, aCallbackArgument, versionTag); return m_ServerResponse; - } else if (valuePtr != NULLPTR && value == NULLPTR) { + } else if (valuePtr != nullptr && value == nullptr) { err = GF_ENOENT; return err; } } // if(m_txState != NULL && !m_txState->isReplay()) // { - // VectorOfCacheablePtr args(new VectorOfCacheable()); + // auto args = std::make_shared<VectorOfCacheable>(); // args->push_back(value); // args->push_back(aCallbackArgument); // m_txState->recordTXOperation(GF_REMOVE, @@ -1426,7 +1431,7 @@ class RemoveActions { const CacheEventFlags eventFlags, int updateCount, VersionTagPtr versionTag, DataInput* delta = NULL, - EventIdPtr eventId = NULLPTR, + EventIdPtr eventId = nullptr, bool afterRemote = false) { CacheablePtr valuePtr; GfErrType err = GF_NOERR; @@ -1434,7 +1439,7 @@ class RemoveActions { m_region.getEntry(key, valuePtr); DataOutput out1; DataOutput out2; - if (valuePtr != NULLPTR && value != NULLPTR) { + if (valuePtr != nullptr && value != nullptr) { if (valuePtr->classId() != value->classId() || valuePtr->typeId() != value->typeId()) { err = GF_ENOENT; @@ -1451,9 +1456,9 @@ class RemoveActions { err = GF_ENOENT; return err; } - } else if (value == NULLPTR && (!CacheableToken::isInvalid(valuePtr) || - valuePtr == NULLPTR)) { - err = (m_ServerResponse == 0 && valuePtr == NULLPTR) ? GF_NOERR + } else if (value == nullptr && (!CacheableToken::isInvalid(valuePtr) || + valuePtr == nullptr)) { + err = (m_ServerResponse == 0 && valuePtr == nullptr) ? GF_NOERR : GF_ENOENT; if (updateCount >= 0 && !m_region.getAttributes() @@ -1466,7 +1471,7 @@ class RemoveActions { m_region.m_entries->removeTrackerForEntry(key); } return err; - } else if (valuePtr == NULLPTR && value != NULLPTR && + } else if (valuePtr == nullptr && value != nullptr && m_ServerResponse != 0) { err = GF_ENOENT; return err; @@ -1495,14 +1500,14 @@ class RemoveActions { } return err; } - if (oldValue != NULLPTR) { + if (oldValue != nullptr) { LOGDEBUG( "Region::remove: region [%s] removed key [%s] having " "value [%s]", m_region.getFullPath(), Utils::getCacheableKeyString(key)->asChar(), Utils::getCacheableString(oldValue)->asChar()); // any cleanup required for the entry (e.g. removing from LRU list) - if (entry != NULLPTR) { + if (entry != nullptr) { entry->cleanup(eventFlags); } // entry/region expiration @@ -1550,7 +1555,7 @@ class InvalidateActions { inline static GfErrType checkArgs(const CacheableKeyPtr& key, const CacheablePtr& value, DataInput* delta = NULL) { - if (key == NULLPTR) { + if (key == nullptr) { return GF_CACHE_ILLEGAL_ARGUMENT_EXCEPTION; } return GF_NOERR; @@ -1567,7 +1572,7 @@ class InvalidateActions { inline static void logCacheWriterFailure(const CacheableKeyPtr& key, const CacheablePtr& oldValue) { - bool isUpdate = (oldValue != NULLPTR); + bool isUpdate = (oldValue != nullptr); LOGFINER("Cache writer vetoed %s for key %s", (isUpdate ? "update" : "invalidate"), Utils::getCacheableKeyString(key)->asChar()); @@ -1579,7 +1584,7 @@ class InvalidateActions { VersionTagPtr& versionTag) { // if(m_txState != NULL && !m_txState->isReplay()) // { - // VectorOfCacheablePtr args(new VectorOfCacheable()); + // auto args = std::make_shared<VectorOfCacheable>(); // args->push_back(aCallbackArgument); // m_txState->recordTXOperation(GF_INVALIDATE, // m_region.getFullPath(), key, args); @@ -1595,7 +1600,7 @@ class InvalidateActions { const CacheEventFlags eventFlags, int updateCount, VersionTagPtr versionTag, DataInput* delta = NULL, - EventIdPtr eventId = NULLPTR, + EventIdPtr eventId = nullptr, bool afterRemote = false) { return m_region.invalidateLocal(name(), key, value, eventFlags, versionTag); } @@ -1645,7 +1650,7 @@ GfErrType LocalRegion::updateNoThrow(const CacheableKeyPtr& key, // do not invoke the writer in case of notification/eviction // or expiration - if (m_writer != NULLPTR && eventFlags.invokeCacheWriter()) { + if (m_writer != nullptr && eventFlags.invokeCacheWriter()) { action.getCallbackOldValue(cachingEnabled, key, entry, oldValue); // invokeCacheWriterForEntryEvent method has the check that if oldValue // is a CacheableToken then it sets it to NULL; also determines if it @@ -1671,7 +1676,7 @@ GfErrType LocalRegion::updateNoThrow(const CacheableKeyPtr& key, if ((updateCount = m_entries->addTrackerForEntry( key, oldValue, TAction::s_addIfAbsent, TAction::s_failIfPresent, true)) < 0) { - if (oldValue != NULLPTR) { + if (oldValue != nullptr) { // fail for "create" when entry exists return GF_CACHE_ENTRY_EXISTS; } @@ -1715,9 +1720,9 @@ GfErrType LocalRegion::updateNoThrow(const CacheableKeyPtr& key, CacheablePtr& newValue1 = const_cast<CacheablePtr&>(value); VersionTagPtr versionTag1; err = getNoThrow_FullObject(eventId, newValue1, versionTag1); - if (err == GF_NOERR && newValue1 != NULLPTR) { + if (err == GF_NOERR && newValue1 != nullptr) { err = m_entries->put(key, newValue1, entry, oldValue, updateCount, 0, - versionTag1 != NULLPTR ? versionTag1 : versionTag); + versionTag1 != nullptr ? versionTag1 : versionTag); if (err == GF_CACHE_CONCURRENT_MODIFICATION_EXCEPTION) { LOGDEBUG( "Region::localUpdate: updateNoThrow<%s> for key [%s] failed because the cache already contains \ @@ -1846,7 +1851,7 @@ GfErrType LocalRegion::destroyNoThrow(const CacheableKeyPtr& key, const CacheEventFlags eventFlags, VersionTagPtr versionTag) { CacheablePtr oldValue; - return updateNoThrow<DestroyActions>(key, NULLPTR, aCallbackArgument, + return updateNoThrow<DestroyActions>(key, nullptr, aCallbackArgument, oldValue, updateCount, eventFlags, versionTag); } @@ -1857,7 +1862,7 @@ GfErrType LocalRegion::destroyNoThrowTX(const CacheableKeyPtr& key, const CacheEventFlags eventFlags, VersionTagPtr versionTag) { CacheablePtr oldValue; - return updateNoThrowTX<DestroyActions>(key, NULLPTR, aCallbackArgument, + return updateNoThrowTX<DestroyActions>(key, nullptr, aCallbackArgument, oldValue, updateCount, eventFlags, versionTag); } @@ -1879,7 +1884,7 @@ GfErrType LocalRegion::removeNoThrowEx(const CacheableKeyPtr& key, const CacheEventFlags eventFlags, VersionTagPtr versionTag) { CacheablePtr oldValue; - return updateNoThrow<RemoveActionsEx>(key, NULLPTR, aCallbackArgument, + return updateNoThrow<RemoveActionsEx>(key, nullptr, aCallbackArgument, oldValue, updateCount, eventFlags, versionTag); } @@ -1890,7 +1895,7 @@ GfErrType LocalRegion::invalidateNoThrow(const CacheableKeyPtr& key, const CacheEventFlags eventFlags, VersionTagPtr versionTag) { CacheablePtr oldValue; - return updateNoThrow<InvalidateActions>(key, NULLPTR, aCallbackArgument, + return updateNoThrow<InvalidateActions>(key, nullptr, aCallbackArgument, oldValue, updateCount, eventFlags, versionTag); } @@ -1901,7 +1906,7 @@ GfErrType LocalRegion::invalidateNoThrowTX(const CacheableKeyPtr& key, const CacheEventFlags eventFlags, VersionTagPtr versionTag) { CacheablePtr oldValue; - return updateNoThrowTX<InvalidateActions>(key, NULLPTR, aCallbackArgument, + return updateNoThrowTX<InvalidateActions>(key, nullptr, aCallbackArgument, oldValue, updateCount, eventFlags, versionTag); } @@ -1921,10 +1926,10 @@ GfErrType LocalRegion::putAllNoThrow(const HashMapOfCacheable& map, } // if(!txState->isReplay()) //{ - // VectorOfCacheablePtr args(new VectorOfCacheable()); + // auto args = std::make_shared<VectorOfCacheable>(); // args->push_back(HashMapOfCacheablePtr(new HashMapOfCacheable(map))); // args->push_back(CacheableInt32::create(timeout)); - // txState->recordTXOperation(GF_PUT_ALL, getFullPath(), NULLPTR, args); + // txState->recordTXOperation(GF_PUT_ALL, getFullPath(), nullptr, args); //} err = putAllNoThrow_remote(map, /*versionTag*/ versionedObjPartListPtr, timeout, aCallbackArgument); @@ -1960,7 +1965,7 @@ GfErrType LocalRegion::putAllNoThrow(const HashMapOfCacheable& map, } } _removeTracking(oldValueMap, *this); - if (cachingEnabled || m_writer != NULLPTR) { + if (cachingEnabled || m_writer != nullptr) { CacheablePtr oldValue; for (HashMapOfCacheable::Iterator iter = map.begin(); iter != map.end(); ++iter) { @@ -1972,7 +1977,7 @@ GfErrType LocalRegion::putAllNoThrow(const HashMapOfCacheable& map, oldValueMap.insert( std::make_pair(key, std::make_pair(oldValue, updateCount))); } - if (m_writer != NULLPTR) { + if (m_writer != nullptr) { // invokeCacheWriterForEntryEvent method has the check that if oldValue // is a CacheableToken then it sets it to NULL; also determines if it // should be BEFORE_UPDATE or BEFORE_CREATE depending on oldValue @@ -2000,11 +2005,11 @@ GfErrType LocalRegion::putAllNoThrow(const HashMapOfCacheable& map, for (int keyIndex = 0; keyIndex < versionedObjPartListPtr->getSucceededKeys()->size(); keyIndex++) { - const CacheablePtr valPtr = + const CacheableKeyPtr valPtr = versionedObjPartListPtr->getSucceededKeys()->at(keyIndex); HashMapOfCacheable::Iterator mapIter = map.find(valPtr); - CacheableKeyPtr key = NULLPTR; - CacheablePtr value = NULLPTR; + CacheableKeyPtr key = nullptr; + CacheablePtr value = nullptr; if (mapIter != map.end()) { key = mapIter.first(); @@ -2016,8 +2021,8 @@ GfErrType LocalRegion::putAllNoThrow(const HashMapOfCacheable& map, "usermap"); } - if (versionedObjPartListPtr != NULLPTR && - versionedObjPartListPtr.ptr() != NULL) { + if (versionedObjPartListPtr != nullptr && + versionedObjPartListPtr.get() != NULL) { LOGDEBUG("versionedObjPartListPtr->getVersionedTagptr().size() = %d ", versionedObjPartListPtr->getVersionedTagptr().size()); if (versionedObjPartListPtr->getVersionedTagptr().size() > 0) { @@ -2055,8 +2060,8 @@ GfErrType LocalRegion::putAllNoThrow(const HashMapOfCacheable& map, const CacheablePtr& value = iter.second(); std::pair<CacheablePtr, int>& p = oldValueMap[key]; - if (versionedObjPartListPtr != NULLPTR && - versionedObjPartListPtr.ptr() != NULL) { + if (versionedObjPartListPtr != nullptr && + versionedObjPartListPtr.get() != NULL) { LOGDEBUG("versionedObjPartListPtr->getVersionedTagptr().size() = %d ", versionedObjPartListPtr->getVersionedTagptr().size()); if (versionedObjPartListPtr->getVersionedTagptr().size() > 0) { @@ -2120,21 +2125,21 @@ GfErrType LocalRegion::removeAllNoThrow(const VectorOfCacheableKey& keys, if (cachingEnabled) { VectorOfCacheableKey* keysPtr; if (m_isPRSingleHopEnabled) { - keysPtr = versionedObjPartListPtr->getSucceededKeys().ptr(); + keysPtr = versionedObjPartListPtr->getSucceededKeys().get(); } else { keysPtr = const_cast<VectorOfCacheableKey*>(&keys); } for (int keyIndex = 0; keyIndex < keysPtr->size(); keyIndex++) { CacheableKeyPtr key = keysPtr->at(keyIndex); - if (versionedObjPartListPtr != NULLPTR && - versionedObjPartListPtr.ptr() != NULL) { + if (versionedObjPartListPtr != nullptr && + versionedObjPartListPtr.get() != NULL) { LOGDEBUG("versionedObjPartListPtr->getVersionedTagptr().size() = %d ", versionedObjPartListPtr->getVersionedTagptr().size()); if (versionedObjPartListPtr->getVersionedTagptr().size() > 0) { versionTag = versionedObjPartListPtr->getVersionedTagptr()[keyIndex]; } - if (versionTag == NULLPTR) { + if (versionTag == nullptr) { LOGDEBUG( "RemoveAll hits EntryNotFoundException at server side for key " "[%s], not to destroy it from local cache.", @@ -2208,7 +2213,7 @@ GfErrType LocalRegion::invalidateLocal(const char* name, const CacheablePtr& value, const CacheEventFlags eventFlags, VersionTagPtr versionTag) { - if (keyPtr == NULLPTR) { + if (keyPtr == nullptr) { return GF_CACHE_ILLEGAL_ARGUMENT_EXCEPTION; } CHECK_DESTROY_PENDING_NOTHROW(TryReadGuard); @@ -2306,7 +2311,7 @@ GfErrType LocalRegion::invalidateRegionNoThrow( for (MapOfRegionWithLock::iterator p = m_subRegions.begin(); p != m_subRegions.end(); ++p) { RegionInternal* subRegion = - dynamic_cast<RegionInternal*>((*p).int_id_.ptr()); + dynamic_cast<RegionInternal*>((*p).int_id_.get()); if (subRegion != NULL) { err = subRegion->invalidateRegionNoThrow(aCallbackArgument, eventFlags); if (err != GF_NOERR) { @@ -2385,7 +2390,7 @@ GfErrType LocalRegion::destroyRegionNoThrow( // TODO: remove unnecessary dynamic_cast by having m_subRegions hold // RegionInternal and invoke the destroy method in that RegionInternal* subRegion = - dynamic_cast<RegionInternal*>((*p).int_id_.ptr()); + dynamic_cast<RegionInternal*>((*p).int_id_.get()); if (subRegion != NULL) { // for subregions never remove from parent since that will cause // the region to be destroyed and SEGV; unbind_all takes care of that @@ -2423,10 +2428,10 @@ GfErrType LocalRegion::destroyRegionNoThrow( GF_D_ASSERT(m_destroyPending); if (removeFromParent) { - if (m_parentRegion == NULLPTR) { + if (m_parentRegion == nullptr) { m_cacheImpl->removeRegion(m_name.c_str()); } else { - LocalRegion* parent = dynamic_cast<LocalRegion*>(m_parentRegion.ptr()); + LocalRegion* parent = dynamic_cast<LocalRegion*>(m_parentRegion.get()); if (parent != NULL) { parent->removeRegion(m_name); if (!eventFlags.isEvictOrExpire()) { @@ -2464,10 +2469,10 @@ GfErrType LocalRegion::putLocal(const char* name, bool isCreate, CacheablePtr& newValue1 = const_cast<CacheablePtr&>(value); VersionTagPtr versionTag1; err = getNoThrow_FullObject(eventId, newValue1, versionTag1); - if (err == GF_NOERR && newValue1 != NULLPTR) { + if (err == GF_NOERR && newValue1 != nullptr) { err = m_entries->put( key, newValue1, entry, oldValue, updateCount, destroyTracker, - versionTag1 != NULLPTR ? versionTag1 : versionTag, isUpdate); + versionTag1 != nullptr ? versionTag1 : versionTag, isUpdate); } } if (delta != NULL && @@ -2527,7 +2532,7 @@ void LocalRegion::entries_internal(VectorOfRegionEntry& me, MapOfRegionGuard guard(m_subRegions.mutex()); for (MapOfRegionWithLock::iterator p = m_subRegions.begin(); p != m_subRegions.end(); ++p) { - dynamic_cast<LocalRegion*>((*p).int_id_.ptr()) + dynamic_cast<LocalRegion*>((*p).int_id_.get()) ->entries_internal(me, true); } } @@ -2546,11 +2551,11 @@ bool LocalRegion::invokeCacheWriterForEntryEvent( CacheEventFlags eventFlags, EntryEventType type) { // Check if we have a local cache writer. If so, invoke and return. bool bCacheWriterReturn = true; - if (m_writer != NULLPTR) { - if (oldValue != NULLPTR && CacheableToken::isInvalid(oldValue)) { - oldValue = NULLPTR; + if (m_writer != nullptr) { + if (oldValue != nullptr && CacheableToken::isInvalid(oldValue)) { + oldValue = nullptr; } - EntryEvent event(RegionPtr(this), key, oldValue, newValue, + EntryEvent event(shared_from_this(), key, oldValue, newValue, aCallbackArgument, eventFlags.isNotification()); const char* eventStr = "unknown"; try { @@ -2559,7 +2564,7 @@ bool LocalRegion::invokeCacheWriterForEntryEvent( int64_t sampleStartNanos = Utils::startStatOpTime(); switch (type) { case BEFORE_UPDATE: { - if (oldValue != NULLPTR) { + if (oldValue != nullptr) { eventStr = "beforeUpdate"; bCacheWriterReturn = m_writer->beforeUpdate(event); break; @@ -2607,8 +2612,8 @@ bool LocalRegion::invokeCacheWriterForRegionEvent( RegionEventType type) { // Check if we have a local cache writer. If so, invoke and return. bool bCacheWriterReturn = true; - if (m_writer != NULLPTR) { - RegionEvent event(RegionPtr(this), aCallbackArgument, + if (m_writer != nullptr) { + RegionEvent event(shared_from_this(), aCallbackArgument, eventFlags.isNotification()); const char* eventStr = "unknown"; try { @@ -2657,11 +2662,11 @@ GfErrType LocalRegion::invokeCacheListenerForEntryEvent( GfErrType err = GF_NOERR; // Check if we have a local cache listener. If so, invoke and return. - if (m_listener != NULLPTR) { - if (oldValue != NULLPTR && CacheableToken::isInvalid(oldValue)) { - oldValue = NULLPTR; + if (m_listener != nullptr) { + if (oldValue != nullptr && CacheableToken::isInvalid(oldValue)) { + oldValue = nullptr; } - EntryEvent event(RegionPtr(this), key, oldValue, newValue, + EntryEvent event(shared_from_this(), key, oldValue, newValue, aCallbackArgument, eventFlags.isNotification()); const char* eventStr = "unknown"; try { @@ -2672,7 +2677,7 @@ GfErrType LocalRegion::invokeCacheListenerForEntryEvent( case AFTER_UPDATE: { // when CREATE is received from server for notification // then force an afterUpdate even if key is not present in cache. - if (oldValue != NULLPTR || eventFlags.isNotificationUpdate() || + if (oldValue != nullptr || eventFlags.isNotificationUpdate() || isLocal) { eventStr = "afterUpdate"; m_listener->afterUpdate(event); @@ -2728,8 +2733,8 @@ GfErrType LocalRegion::invokeCacheListenerForRegionEvent( GfErrType err = GF_NOERR; // Check if we have a local cache listener. If so, invoke and return. - if (m_listener != NULLPTR) { - RegionEvent event(RegionPtr(this), aCallbackArgument, + if (m_listener != nullptr) { + RegionEvent event(shared_from_this(), aCallbackArgument, eventFlags.isNotification()); const char* eventStr = "unknown"; try { @@ -2743,7 +2748,7 @@ GfErrType LocalRegion::invokeCacheListenerForRegionEvent( m_cacheImpl->m_cacheStats->incListenerCalls(); if (eventFlags.isCacheClose()) { eventStr = "close"; - m_listener->close(RegionPtr(this)); + m_listener->close(shared_from_this()); m_cacheImpl->m_cacheStats->incListenerCalls(); } break; @@ -2788,7 +2793,7 @@ GfErrType LocalRegion::invokeCacheListenerForRegionEvent( void LocalRegion::updateAccessAndModifiedTimeForEntry(MapEntryImplPtr& ptr, bool modified) { // locking is not required since setters use atomic operations - if (ptr != NULLPTR && entryExpiryEnabled()) { + if (ptr != nullptr && entryExpiryEnabled()) { ExpEntryProperties& expProps = ptr->getExpProperties(); uint32_t currTime = static_cast<uint32_t>(ACE_OS::gettimeofday().sec()); CacheableStringPtr keyStr; @@ -3116,10 +3121,10 @@ void LocalRegion::evict(int32_t percentage) { } } void LocalRegion::invokeAfterAllEndPointDisconnected() { - if (m_listener != NULLPTR) { + if (m_listener != nullptr) { int64_t sampleStartNanos = Utils::startStatOpTime(); try { - m_listener->afterRegionDisconnected(RegionPtr(this)); + m_listener->afterRegionDisconnected(shared_from_this()); } catch (const Exception& ex) { LOGERROR("Exception in CacheListener::afterRegionDisconnected: %s: %s", ex.getName(), ex.getMessage()); http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/LocalRegion.hpp ---------------------------------------------------------------------- diff --git a/src/cppcache/src/LocalRegion.hpp b/src/cppcache/src/LocalRegion.hpp index 0d0fa58..c3c6b05 100644 --- a/src/cppcache/src/LocalRegion.hpp +++ b/src/cppcache/src/LocalRegion.hpp @@ -119,6 +119,8 @@ typedef std::unordered_map<CacheableKeyPtr, std::pair<CacheablePtr, int> > * is used to concatenate all the region names together from the root, starting * with the root's subregions. */ +typedef SharedPtr<LocalRegion> LocalRegionPtr; + class CPPCACHE_EXPORT LocalRegion : public RegionInternal { /** * @brief Public Methods for Region @@ -127,7 +129,8 @@ class CPPCACHE_EXPORT LocalRegion : public RegionInternal { /** * @brief constructor/destructor */ - LocalRegion(const std::string& name, CacheImpl* cache, RegionInternal* rPtr, + LocalRegion(const std::string& name, CacheImpl* cache, + const RegionInternalPtr& rPtr, const RegionAttributesPtr& attributes, const CacheStatisticsPtr& stats, bool shared = false); virtual ~LocalRegion(); @@ -137,19 +140,21 @@ class CPPCACHE_EXPORT LocalRegion : public RegionInternal { RegionPtr getParentRegion() const; RegionAttributesPtr getAttributes() const { return m_regionAttributes; } AttributesMutatorPtr getAttributesMutator() const { - return AttributesMutatorPtr(new AttributesMutator(RegionPtr(this))); + return std::make_shared<AttributesMutator>( + std::const_pointer_cast<LocalRegion>( + std::static_pointer_cast<const LocalRegion>(shared_from_this()))); } void updateAccessAndModifiedTime(bool modified); CacheStatisticsPtr getStatistics() const; - virtual void clear(const UserDataPtr& aCallbackArgument = NULLPTR); - virtual void localClear(const UserDataPtr& aCallbackArgument = NULLPTR); + virtual void clear(const UserDataPtr& aCallbackArgument = nullptr); + virtual void localClear(const UserDataPtr& aCallbackArgument = nullptr); GfErrType localClearNoThrow( - const UserDataPtr& aCallbackArgument = NULLPTR, + const UserDataPtr& aCallbackArgument = nullptr, const CacheEventFlags eventFlags = CacheEventFlags::NORMAL); - void invalidateRegion(const UserDataPtr& aCallbackArgument = NULLPTR); - void localInvalidateRegion(const UserDataPtr& aCallbackArgument = NULLPTR); - void destroyRegion(const UserDataPtr& aCallbackArgument = NULLPTR); - void localDestroyRegion(const UserDataPtr& aCallbackArgument = NULLPTR); + void invalidateRegion(const UserDataPtr& aCallbackArgument = nullptr); + void localInvalidateRegion(const UserDataPtr& aCallbackArgument = nullptr); + void destroyRegion(const UserDataPtr& aCallbackArgument = nullptr); + void localDestroyRegion(const UserDataPtr& aCallbackArgument = nullptr); RegionPtr getSubregion(const char* path); RegionPtr createSubregion(const char* subregionName, const RegionAttributesPtr& aRegionAttributes); @@ -159,41 +164,41 @@ class CPPCACHE_EXPORT LocalRegion : public RegionInternal { CacheablePtr get(const CacheableKeyPtr& key, const UserDataPtr& aCallbackArgument); void put(const CacheableKeyPtr& key, const CacheablePtr& value, - const UserDataPtr& aCallbackArgument = NULLPTR); + const UserDataPtr& aCallbackArgument = nullptr); void localPut(const CacheableKeyPtr& key, const CacheablePtr& value, - const UserDataPtr& aCallbackArgument = NULLPTR); + const UserDataPtr& aCallbackArgument = nullptr); void create(const CacheableKeyPtr& key, const CacheablePtr& value, - const UserDataPtr& aCallbackArgument = NULLPTR); + const UserDataPtr& aCallbackArgument = nullptr); void localCreate(const CacheableKeyPtr& key, const CacheablePtr& value, - const UserDataPtr& aCallbackArgument = NULLPTR); + const UserDataPtr& aCallbackArgument = nullptr); void invalidate(const CacheableKeyPtr& key, - const UserDataPtr& aCallbackArgument = NULLPTR); + const UserDataPtr& aCallbackArgument = nullptr); void localInvalidate(const CacheableKeyPtr& key, - const UserDataPtr& aCallbackArgument = NULLPTR); + const UserDataPtr& aCallbackArgument = nullptr); void destroy(const CacheableKeyPtr& key, - const UserDataPtr& aCallbackArgument = NULLPTR); + const UserDataPtr& aCallbackArgument = nullptr); void localDestroy(const CacheableKeyPtr& key, - const UserDataPtr& aCallbackArgument = NULLPTR); + const UserDataPtr& aCallbackArgument = nullptr); bool remove(const CacheableKeyPtr& key, const CacheablePtr& value, - const UserDataPtr& aCallbackArgument = NULLPTR); + const UserDataPtr& aCallbackArgument = nullptr); bool removeEx(const CacheableKeyPtr& key, - const UserDataPtr& aCallbackArgument = NULLPTR); + const UserDataPtr& aCallbackArgument = nullptr); bool localRemove(const CacheableKeyPtr& key, const CacheablePtr& value, - const UserDataPtr& aCallbackArgument = NULLPTR); + const UserDataPtr& aCallbackArgument = nullptr); bool localRemoveEx(const CacheableKeyPtr& key, - const UserDataPtr& aCallbackArgument = NULLPTR); + const UserDataPtr& aCallbackArgument = nullptr); void keys(VectorOfCacheableKey& v); void serverKeys(VectorOfCacheableKey& v); void values(VectorOfCacheable& vc); void entries(VectorOfRegionEntry& me, bool recursive); void getAll(const VectorOfCacheableKey& keys, HashMapOfCacheablePtr values, HashMapOfExceptionPtr exceptions, bool addToLocalCache, - const UserDataPtr& aCallbackArgument = NULLPTR); + const UserDataPtr& aCallbackArgument = nullptr); void putAll(const HashMapOfCacheable& map, uint32_t timeout = DEFAULT_RESPONSE_TIMEOUT, - const UserDataPtr& aCallbackArgument = NULLPTR); + const UserDataPtr& aCallbackArgument = nullptr); void removeAll(const VectorOfCacheableKey& keys, - const UserDataPtr& aCallbackArgument = NULLPTR); + const UserDataPtr& aCallbackArgument = nullptr); uint32_t size(); virtual uint32_t size_remote(); RegionServicePtr getRegionService() const; @@ -215,7 +220,7 @@ class CPPCACHE_EXPORT LocalRegion : public RegionInternal { virtual GfErrType getAllNoThrow( const VectorOfCacheableKey& keys, const HashMapOfCacheablePtr& values, const HashMapOfExceptionPtr& exceptions, bool addToLocalCache, - const UserDataPtr& aCallbackArgument = NULLPTR); + const UserDataPtr& aCallbackArgument = nullptr); virtual GfErrType putNoThrow(const CacheableKeyPtr& key, const CacheablePtr& value, const UserDataPtr& aCallbackArgument, @@ -223,7 +228,7 @@ class CPPCACHE_EXPORT LocalRegion : public RegionInternal { const CacheEventFlags eventFlags, VersionTagPtr versionTag, DataInput* delta = NULL, - EventIdPtr eventId = NULLPTR); + EventIdPtr eventId = nullptr); virtual GfErrType putNoThrowTX(const CacheableKeyPtr& key, const CacheablePtr& value, const UserDataPtr& aCallbackArgument, @@ -231,7 +236,7 @@ class CPPCACHE_EXPORT LocalRegion : public RegionInternal { const CacheEventFlags eventFlags, VersionTagPtr versionTag, DataInput* delta = NULL, - EventIdPtr eventId = NULLPTR); + EventIdPtr eventId = nullptr); virtual GfErrType createNoThrow(const CacheableKeyPtr& key, const CacheablePtr& value, const UserDataPtr& aCallbackArgument, @@ -262,10 +267,10 @@ class CPPCACHE_EXPORT LocalRegion : public RegionInternal { virtual GfErrType putAllNoThrow( const HashMapOfCacheable& map, uint32_t timeout = DEFAULT_RESPONSE_TIMEOUT, - const UserDataPtr& aCallbackArgument = NULLPTR); + const UserDataPtr& aCallbackArgument = nullptr); virtual GfErrType removeAllNoThrow( const VectorOfCacheableKey& keys, - const UserDataPtr& aCallbackArgument = NULLPTR); + const UserDataPtr& aCallbackArgument = nullptr); virtual GfErrType invalidateNoThrow(const CacheableKeyPtr& keyPtr, const UserDataPtr& aCallbackArgument, int updateCount, @@ -292,7 +297,7 @@ class CPPCACHE_EXPORT LocalRegion : public RegionInternal { const CacheablePtr& valuePtr, CacheablePtr& oldValue, bool cachingEnabled, int updateCount, int destroyTracker, VersionTagPtr versionTag, DataInput* delta = NULL, - EventIdPtr eventId = NULLPTR); + EventIdPtr eventId = nullptr); GfErrType invalidateLocal(const char* name, const CacheableKeyPtr& keyPtr, const CacheablePtr& value, const CacheEventFlags eventFlags, @@ -315,7 +320,7 @@ class CPPCACHE_EXPORT LocalRegion : public RegionInternal { RegionStats* getRegionStats() { return m_regionStats; } inline bool cacheEnabled() { return m_regionAttributes->getCachingEnabled(); } inline bool cachelessWithListener() { - return !m_regionAttributes->getCachingEnabled() && (m_listener != NULLPTR); + return !m_regionAttributes->getCachingEnabled() && (m_listener != nullptr); } virtual bool isDestroyed() const { return m_destroyPending; } /* above public methods are inherited from RegionInternal */ @@ -329,7 +334,7 @@ class CPPCACHE_EXPORT LocalRegion : public RegionInternal { virtual void adjustCacheWriter(const CacheWriterPtr& aWriter); virtual void adjustCacheWriter(const char* libpath, const char* factoryFuncName); - virtual CacheImpl* getCacheImpl(); + virtual CacheImpl* getCacheImpl() const; virtual void evict(int32_t percentage); virtual void acquireGlobals(bool isFailover){}; @@ -408,7 +413,7 @@ class CPPCACHE_EXPORT LocalRegion : public RegionInternal { CacheablePtr& oldValue, int updateCount, const CacheEventFlags eventFlags, VersionTagPtr versionTag, DataInput* delta = NULL, - EventIdPtr eventId = NULLPTR); + EventIdPtr eventId = nullptr); template <typename TAction> GfErrType updateNoThrowTX(const CacheableKeyPtr& key, @@ -417,7 +422,7 @@ class CPPCACHE_EXPORT LocalRegion : public RegionInternal { CacheablePtr& oldValue, int updateCount, const CacheEventFlags eventFlags, VersionTagPtr versionTag, DataInput* delta = NULL, - EventIdPtr eventId = NULLPTR); + EventIdPtr eventId = nullptr); /* protected attributes */ std::string m_name; http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/MapEntry.cpp ---------------------------------------------------------------------- diff --git a/src/cppcache/src/MapEntry.cpp b/src/cppcache/src/MapEntry.cpp index 98e5ba0..4222c80 100644 --- a/src/cppcache/src/MapEntry.cpp +++ b/src/cppcache/src/MapEntry.cpp @@ -20,7 +20,7 @@ using namespace apache::geode::client; EntryFactory* EntryFactory::singleton = NULL; -MapEntryPtr MapEntry::MapEntry_NullPointer(NULLPTR); +MapEntryPtr MapEntry::MapEntry_NullPointer(nullptr); /** * @brief called when library is initialized... see CppCacheLibrary. http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/MapEntry.hpp ---------------------------------------------------------------------- diff --git a/src/cppcache/src/MapEntry.hpp b/src/cppcache/src/MapEntry.hpp index 4e05652..e177298 100644 --- a/src/cppcache/src/MapEntry.hpp +++ b/src/cppcache/src/MapEntry.hpp @@ -112,7 +112,7 @@ class CPPCACHE_EXPORT MapEntry : public SharedBase { virtual void getKey(CacheableKeyPtr& result) const = 0; virtual void getValue(CacheablePtr& result) const = 0; virtual void setValue(const CacheablePtr& value) = 0; - virtual MapEntryImpl* getImplPtr() = 0; + virtual MapEntryImplPtr getImplPtr() = 0; virtual LRUEntryProperties& getLRUProperties() = 0; virtual ExpEntryProperties& getExpProperties() = 0; @@ -185,16 +185,17 @@ class CPPCACHE_EXPORT MapEntry : public SharedBase { * @brief Hold region mapped entry value. subclass will hold lru flags. * Another holds expiration timestamps. */ -class MapEntryImpl : public MapEntry { +class MapEntryImpl : public MapEntry, + public std::enable_shared_from_this<MapEntryImpl> { public: virtual ~MapEntryImpl() {} inline void getKeyI(CacheableKeyPtr& result) const { result = m_key; } inline void getValueI(CacheablePtr& result) const { - // If value is destroyed, then this returns NULLPTR + // If value is destroyed, then this returns nullptr if (CacheableToken::isDestroyed(m_value)) { - result = NULLPTR; + result = nullptr; } else { result = m_value; } @@ -208,7 +209,7 @@ class MapEntryImpl : public MapEntry { virtual void setValue(const CacheablePtr& value) { setValueI(value); } - virtual MapEntryImpl* getImplPtr() { return this; } + virtual MapEntryImplPtr getImplPtr() { return shared_from_this(); } virtual LRUEntryProperties& getLRUProperties() { throw FatalInternalException( @@ -231,7 +232,7 @@ class MapEntryImpl : public MapEntry { protected: inline explicit MapEntryImpl(bool noInit) - : MapEntry(true), m_value(true), m_key(true) {} + : MapEntry(true), m_value(nullptr), m_key(nullptr) {} inline MapEntryImpl(const CacheableKeyPtr& key) : MapEntry(), m_key(key) {} http://git-wip-us.apache.org/repos/asf/geode-native/blob/c0098121/src/cppcache/src/MapEntryT.hpp ---------------------------------------------------------------------- diff --git a/src/cppcache/src/MapEntryT.hpp b/src/cppcache/src/MapEntryT.hpp index 474abdc..86db403 100644 --- a/src/cppcache/src/MapEntryT.hpp +++ b/src/cppcache/src/MapEntryT.hpp @@ -112,10 +112,8 @@ class MapEntryT : public TBase { virtual int getUpdateCount() const { return UPDATE_COUNT; } - inline static MapEntryT* create(const CacheableKeyPtr& key) { - MapEntryT* entry; - GF_NEW(entry, MapEntryT(key)); - return entry; + inline static std::shared_ptr<MapEntryT> create(const CacheableKeyPtr& key) { + return std::make_shared<MapEntryT>(key); } protected: @@ -125,6 +123,8 @@ class MapEntryT : public TBase { // disabled MapEntryT(const MapEntryT&); MapEntryT& operator=(const MapEntryT&); + + FRIEND_STD_SHARED_PTR(MapEntryT) }; // specialization of MapEntryT to terminate the recursive template definition @@ -148,7 +148,8 @@ class MapEntryT<TBase, NUM_TRACKERS, GF_UPDATE_MAX> : public TBase { virtual int incrementUpdateCount(MapEntryPtr& newEntry) { // fallback to TrackedMapEntry - GF_NEW(newEntry, TrackedMapEntry(this, NUM_TRACKERS, GF_UPDATE_MAX + 1)); + newEntry = std::make_shared<TrackedMapEntry>( + this->shared_from_this(), NUM_TRACKERS, GF_UPDATE_MAX + 1); return (GF_UPDATE_MAX + 1); } @@ -173,7 +174,8 @@ class MapEntryT<TBase, GF_TRACK_MAX, UPDATE_COUNT> : public TBase { virtual int addTracker(MapEntryPtr& newEntry) { // fallback to TrackedMapEntry - GF_NEW(newEntry, TrackedMapEntry(this, GF_TRACK_MAX + 1, UPDATE_COUNT)); + newEntry = std::make_shared<TrackedMapEntry>( + this->shared_from_this(), GF_TRACK_MAX + 1, UPDATE_COUNT); return UPDATE_COUNT; } @@ -208,7 +210,8 @@ class MapEntryT<TBase, GF_TRACK_MAX, GF_UPDATE_MAX> : public TBase { virtual int addTracker(MapEntryPtr& newEntry) { // fallback to TrackedMapEntry - GF_NEW(newEntry, TrackedMapEntry(this, GF_TRACK_MAX + 1, GF_UPDATE_MAX)); + newEntry = std::make_shared<TrackedMapEntry>( + this->shared_from_this(), GF_TRACK_MAX + 1, GF_UPDATE_MAX); return GF_UPDATE_MAX; } @@ -220,7 +223,8 @@ class MapEntryT<TBase, GF_TRACK_MAX, GF_UPDATE_MAX> : public TBase { virtual int incrementUpdateCount(MapEntryPtr& newEntry) { // fallback to TrackedMapEntry - GF_NEW(newEntry, TrackedMapEntry(this, GF_TRACK_MAX, GF_UPDATE_MAX + 1)); + newEntry = std::make_shared<TrackedMapEntry>( + this->shared_from_this(), GF_TRACK_MAX, GF_UPDATE_MAX + 1); return (GF_UPDATE_MAX + 1); }