diff options
-rw-r--r-- | sc/inc/document.hxx | 6 | ||||
-rw-r--r-- | sc/inc/validat.hxx | 8 | ||||
-rw-r--r-- | sc/source/core/data/documen2.cxx | 20 | ||||
-rw-r--r-- | sc/source/core/data/documen4.cxx | 8 | ||||
-rw-r--r-- | sc/source/core/data/validat.cxx | 6 |
5 files changed, 18 insertions, 30 deletions
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index 4fcee74748ca..7d34bd38a6a4 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -357,7 +357,7 @@ private: VclPtr<VirtualDevice> mpVirtualDevice_100th_mm; std::unique_ptr<ScDrawLayer> mpDrawLayer; // SdrModel rtl::Reference<XColorList> pColorList; - ScValidationDataList* pValidationList; // validity + std::unique_ptr<ScValidationDataList> pValidationList; // validity SvNumberFormatterIndexTable* pFormatExchangeList; // for application of number formats TableContainer maTabs; std::vector<OUString> maTabNames; // for undo document, we need the information tab name <-> index @@ -1703,8 +1703,8 @@ public: SC_DLLPUBLIC ScConditionalFormatList* GetCondFormList( SCTAB nTab ) const; - const ScValidationDataList* GetValidationList() const { return pValidationList;} - ScValidationDataList* GetValidationList() { return pValidationList;} + const ScValidationDataList* GetValidationList() const { return pValidationList.get();} + ScValidationDataList* GetValidationList() { return pValidationList.get();} SC_DLLPUBLIC void ApplyAttr( SCCOL nCol, SCROW nRow, SCTAB nTab, const SfxPoolItem& rAttr ); diff --git a/sc/inc/validat.hxx b/sc/inc/validat.hxx index dc694069fca0..945cd9e6bc0e 100644 --- a/sc/inc/validat.hxx +++ b/sc/inc/validat.hxx @@ -190,13 +190,13 @@ private: struct CompareScValidationDataPtr { - bool operator()( ScValidationData* const& lhs, ScValidationData* const& rhs ) const { return (*lhs)<(*rhs); } + bool operator()( std::unique_ptr<ScValidationData> const& lhs, std::unique_ptr<ScValidationData> const& rhs ) const { return (*lhs)<(*rhs); } }; class ScValidationDataList { private: - typedef std::set<ScValidationData*, CompareScValidationDataPtr> ScValidationDataListDataType; + typedef std::set<std::unique_ptr<ScValidationData>, CompareScValidationDataPtr> ScValidationDataListDataType; ScValidationDataListDataType maData; public: @@ -212,8 +212,8 @@ public: iterator end(); const_iterator end() const; - void InsertNew( ScValidationData* pNew ) - { if (!maData.insert(pNew).second) delete pNew; } + void InsertNew( std::unique_ptr<ScValidationData> pNew ) + { maData.insert(std::move(pNew)); } ScValidationData* GetData( sal_uInt32 nKey ); diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx index f3f63f2811f3..082a5e164532 100644 --- a/sc/source/core/data/documen2.cxx +++ b/sc/source/core/data/documen2.cxx @@ -405,13 +405,7 @@ ScDocument::~ScDocument() Clear( true ); // true = from destructor (needed for SdrModel::ClearModel) - if (pValidationList) - { - for( ScValidationDataList::iterator it = pValidationList->begin(); it != pValidationList->end(); ++it ) - delete *it; - pValidationList->clear(); - DELETEZ(pValidationList); - } + pValidationList.reset(); pRangeName.reset(); pDBCollection.reset(); pSelectionAttr.reset(); @@ -455,13 +449,7 @@ void ScDocument::InitClipPtrs( ScDocument* pSourceDoc ) ScMutationGuard aGuard(this, ScMutationGuardFlags::CORE); - if (pValidationList) - { - for(ScValidationDataList::iterator it = pValidationList->begin(); it != pValidationList->end(); ++it ) - delete *it; - pValidationList->clear(); - DELETEZ(pValidationList); - } + pValidationList.reset(); Clear(); @@ -469,9 +457,9 @@ void ScDocument::InitClipPtrs( ScDocument* pSourceDoc ) // conditional Formats / validations // TODO: Copy Templates? - const ScValidationDataList* pSourceValid = pSourceDoc->pValidationList; + const ScValidationDataList* pSourceValid = pSourceDoc->pValidationList.get(); if ( pSourceValid ) - pValidationList = new ScValidationDataList(this, *pSourceValid); + pValidationList.reset(new ScValidationDataList(this, *pSourceValid)); // store Links in Stream pClipData.reset(); diff --git a/sc/source/core/data/documen4.cxx b/sc/source/core/data/documen4.cxx index 3c1dab1ff103..7e7372a40b9d 100644 --- a/sc/source/core/data/documen4.cxx +++ b/sc/source/core/data/documen4.cxx @@ -744,13 +744,13 @@ sal_uLong ScDocument::AddValidationEntry( const ScValidationData& rNew ) if (!pValidationList) { ScMutationGuard aGuard(this, ScMutationGuardFlags::CORE); - pValidationList = new ScValidationDataList; + pValidationList.reset(new ScValidationDataList); } sal_uLong nMax = 0; for( ScValidationDataList::iterator it = pValidationList->begin(); it != pValidationList->end(); ++it ) { - const ScValidationData* pData = *it; + const ScValidationData* pData = it->get(); sal_uLong nKey = pData->GetKey(); if ( pData->EqualEntries( rNew ) ) return nKey; @@ -761,10 +761,10 @@ sal_uLong ScDocument::AddValidationEntry( const ScValidationData& rNew ) // might be called from ScPatternAttr::PutInPool; thus clone (real copy) sal_uLong nNewKey = nMax + 1; - ScValidationData* pInsert = rNew.Clone(this); + std::unique_ptr<ScValidationData> pInsert(rNew.Clone(this)); pInsert->SetKey( nNewKey ); ScMutationGuard aGuard(this, ScMutationGuardFlags::CORE); - pValidationList->InsertNew( pInsert ); + pValidationList->InsertNew( std::move(pInsert) ); return nNewKey; } diff --git a/sc/source/core/data/validat.cxx b/sc/source/core/data/validat.cxx index 97c9effbb954..9736d74ac00a 100644 --- a/sc/source/core/data/validat.cxx +++ b/sc/source/core/data/validat.cxx @@ -966,7 +966,7 @@ ScValidationDataList::ScValidationDataList(const ScValidationDataList& rList) for (const_iterator it = rList.begin(); it != rList.end(); ++it) { - InsertNew( (*it)->Clone() ); + InsertNew( std::unique_ptr<ScValidationData>((*it)->Clone()) ); } //TODO: faster insert for sorted entries from rList ??? @@ -979,7 +979,7 @@ ScValidationDataList::ScValidationDataList(ScDocument* pNewDoc, for (const_iterator it = rList.begin(); it != rList.end(); ++it) { - InsertNew( (*it)->Clone(pNewDoc) ); + InsertNew( std::unique_ptr<ScValidationData>((*it)->Clone(pNewDoc)) ); } //TODO: faster insert for sorted entries from rList ??? @@ -991,7 +991,7 @@ ScValidationData* ScValidationDataList::GetData( sal_uInt32 nKey ) for( iterator it = begin(); it != end(); ++it ) if( (*it)->GetKey() == nKey ) - return *it; + return it->get(); OSL_FAIL("ScValidationDataList: Entry not found"); return nullptr; |