summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-06-04 15:01:43 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-06-11 08:26:14 +0200
commiteec9f6c8b928de38dd9e683f46bfab00f3243048 (patch)
tree75838981f5c73c9799d139179f880b172981cb00
parent32604a3da226a4e340d6e7844153e7d854fb7f2e (diff)
loplugin:useuniqueptr in FmEntryDataList
Change-Id: I7c9ec3bb26c6c329c66d684437bf934b9c2ad0e5 Reviewed-on: https://gerrit.libreoffice.org/55519 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--svx/source/form/fmexpl.cxx37
-rw-r--r--svx/source/form/navigatortree.cxx4
-rw-r--r--svx/source/form/navigatortreemodel.cxx4
-rw-r--r--svx/source/inc/fmexpl.hxx14
4 files changed, 26 insertions, 33 deletions
diff --git a/svx/source/form/fmexpl.cxx b/svx/source/form/fmexpl.cxx
index 0ad2377088bb..8fec9e0f5798 100644
--- a/svx/source/form/fmexpl.cxx
+++ b/svx/source/form/fmexpl.cxx
@@ -132,41 +132,34 @@ FmEntryDataList::~FmEntryDataList()
}
-FmEntryData* FmEntryDataList::remove( FmEntryData* pItem )
+void FmEntryDataList::remove( FmEntryData* pItem )
{
- FmEntryDataBaseList::const_iterator aEnd = maEntryDataList.end();
- for ( FmEntryDataBaseList::iterator it = maEntryDataList.begin();
- it != aEnd;
- ++it
- )
+ auto aEnd = maEntryDataList.end();
+ for ( auto it = maEntryDataList.begin(); it != aEnd; ++it )
{
- if ( *it == pItem )
+ if ( it->get() == pItem )
{
maEntryDataList.erase( it );
- break;
+ return;
}
}
- return pItem;
+ assert(false);
}
-void FmEntryDataList::insert( FmEntryData* pItem, size_t Index )
+void FmEntryDataList::insert( std::unique_ptr<FmEntryData> pItem, size_t Index )
{
if ( Index < maEntryDataList.size() )
{
- FmEntryDataBaseList::iterator it = maEntryDataList.begin();
- ::std::advance( it, Index );
- maEntryDataList.insert( it, pItem );
+ maEntryDataList.insert( maEntryDataList.begin() + Index, std::move(pItem) );
}
else
- maEntryDataList.push_back( pItem );
+ maEntryDataList.push_back( std::move(pItem) );
}
void FmEntryDataList::clear()
{
- for (FmEntryData* p : maEntryDataList)
- delete p;
maEntryDataList.clear();
}
@@ -207,8 +200,8 @@ FmEntryData::FmEntryData( const FmEntryData& rEntryData )
for( size_t i = 0; i < nEntryCount; i++ )
{
pChildData = rEntryData.GetChildList()->at( i );
- FmEntryData* pNewChildData = pChildData->Clone();
- pChildList->insert( pNewChildData, size_t(-1) );
+ std::unique_ptr<FmEntryData> pNewChildData = pChildData->Clone();
+ pChildList->insert( std::move(pNewChildData), size_t(-1) );
}
m_xNormalizedIFace = rEntryData.m_xNormalizedIFace;
@@ -276,9 +269,9 @@ FmFormData::FmFormData( const FmFormData& rFormData )
}
-FmEntryData* FmFormData::Clone()
+std::unique_ptr<FmEntryData> FmFormData::Clone()
{
- return new FmFormData( *this );
+ return std::unique_ptr<FmEntryData>(new FmFormData( *this ));
}
@@ -325,9 +318,9 @@ FmControlData::FmControlData( const FmControlData& rControlData )
}
-FmEntryData* FmControlData::Clone()
+std::unique_ptr<FmEntryData> FmControlData::Clone()
{
- return new FmControlData( *this );
+ return std::unique_ptr<FmEntryData>(new FmControlData( *this ));
}
diff --git a/svx/source/form/navigatortree.cxx b/svx/source/form/navigatortree.cxx
index 6d114087ac73..8f8101410bf5 100644
--- a/svx/source/form/navigatortree.cxx
+++ b/svx/source/form/navigatortree.cxx
@@ -1127,9 +1127,9 @@ namespace svxform
// give parent the new child
if (pTargetData)
- pTargetData->GetChildList()->insert( pCurrentUserData, nIndex );
+ pTargetData->GetChildList()->insert( std::unique_ptr<FmEntryData>(pCurrentUserData), nIndex );
else
- GetNavModel()->GetRootList()->insert( pCurrentUserData, nIndex );
+ GetNavModel()->GetRootList()->insert( std::unique_ptr<FmEntryData>(pCurrentUserData), nIndex );
// announce to myself and reselect
SvTreeListEntry* pNew = Insert( pCurrentUserData, nIndex );
diff --git a/svx/source/form/navigatortreemodel.cxx b/svx/source/form/navigatortreemodel.cxx
index 01136bf189b0..9ae59cf81908 100644
--- a/svx/source/form/navigatortreemodel.cxx
+++ b/svx/source/form/navigatortreemodel.cxx
@@ -333,9 +333,9 @@ namespace svxform
}
if (pFolder)
- pFolder->GetChildList()->insert( pEntry, nRelPos );
+ pFolder->GetChildList()->insert( std::unique_ptr<FmEntryData>(pEntry), nRelPos );
else
- GetRootList()->insert( pEntry, nRelPos );
+ GetRootList()->insert( std::unique_ptr<FmEntryData>(pEntry), nRelPos );
// notify UI
diff --git a/svx/source/inc/fmexpl.hxx b/svx/source/inc/fmexpl.hxx
index f681edc26ffb..024b38edb775 100644
--- a/svx/source/inc/fmexpl.hxx
+++ b/svx/source/inc/fmexpl.hxx
@@ -167,7 +167,7 @@ public:
FmEntryDataList* GetChildList() const { return pChildList.get(); }
virtual bool IsEqualWithoutChildren( FmEntryData* pEntryData );
- virtual FmEntryData* Clone() = 0;
+ virtual std::unique_ptr<FmEntryData> Clone() = 0;
// note that the interface returned is normalized, i.e. querying the given XInterface of the object
// for XInterface must return the interface itself.
@@ -193,18 +193,18 @@ typedef ::std::vector< FmEntryData* > FmEntryDataBaseList;
class FmEntryDataList final
{
private:
- FmEntryDataBaseList maEntryDataList;
+ std::vector< std::unique_ptr<FmEntryData> > maEntryDataList;
public:
FmEntryDataList();
~FmEntryDataList();
FmEntryData* at( size_t Index )
- { return ( Index < maEntryDataList.size() ) ? maEntryDataList[ Index ] : nullptr; }
+ { return maEntryDataList.at(Index).get(); }
size_t size() const { return maEntryDataList.size(); }
- FmEntryData* remove( FmEntryData* pItem );
- void insert( FmEntryData* pItem, size_t Index );
+ void remove( FmEntryData* pItem );
+ void insert( std::unique_ptr<FmEntryData> pItem, size_t Index );
void clear();
};
@@ -243,7 +243,7 @@ public:
const css::uno::Reference< css::form::XForm >& GetFormIface() const { return m_xForm; }
virtual bool IsEqualWithoutChildren( FmEntryData* pEntryData ) override;
- virtual FmEntryData* Clone() override;
+ virtual std::unique_ptr<FmEntryData> Clone() override;
};
@@ -264,7 +264,7 @@ public:
const css::uno::Reference< css::form::XFormComponent >& GetFormComponent() const { return m_xFormComponent; }
virtual bool IsEqualWithoutChildren( FmEntryData* pEntryData ) override;
- virtual FmEntryData* Clone() override;
+ virtual std::unique_ptr<FmEntryData> Clone() override;
void ModelReplaced(const css::uno::Reference< css::form::XFormComponent >& _rxNew);
};