Kaydet (Commit) 5e8b31f1 authored tarafından Takeshi Abe's avatar Takeshi Abe Kaydeden (comit) Markus Mohrhard

fdo#75757: remove inheritance to std::vector

This also fixes possible memory leaks of SfxAllEnumValue_Impl
which may occur in SfxAllEnumItem::RemoveValue() of the original
implementation.

Change-Id: I5f458c546575d9e1f88b1167ae561537963c7b95
Reviewed-on: https://gerrit.libreoffice.org/10167Reviewed-by: 's avatarMarkus Mohrhard <markus.mohrhard@googlemail.com>
Tested-by: 's avatarMarkus Mohrhard <markus.mohrhard@googlemail.com>
üst b023565d
...@@ -19,7 +19,8 @@ ...@@ -19,7 +19,8 @@
#include <rtl/ustring.hxx> #include <rtl/ustring.hxx>
#include <svl/aeitem.hxx> #include <svl/aeitem.hxx>
#include <vector> #include <boost/noncopyable.hpp>
#include <boost/ptr_container/ptr_vector.hpp>
TYPEINIT1_AUTOFACTORY(SfxAllEnumItem, SfxEnumItem) TYPEINIT1_AUTOFACTORY(SfxAllEnumItem, SfxEnumItem)
...@@ -31,14 +32,31 @@ struct SfxAllEnumValue_Impl ...@@ -31,14 +32,31 @@ struct SfxAllEnumValue_Impl
OUString aText; OUString aText;
}; };
class SfxAllEnumValueArr : public std::vector<SfxAllEnumValue_Impl*> class SfxAllEnumValueArr : boost::noncopyable
{ {
public: public:
~SfxAllEnumValueArr() const SfxAllEnumValue_Impl &operator[](size_t i) const {
{ return mValues[i];
for( const_iterator it = begin(); it != end(); ++it ) }
delete *it;
bool empty() const {
return mValues.empty();
}
void Insert(sal_uInt16 n, SfxAllEnumValue_Impl *value) {
mValues.insert(mValues.begin() + n, value);
} }
void Erase(sal_uInt16 n) {
mValues.erase(mValues.begin() + n);
}
size_t size() const {
return mValues.size();
}
private:
boost::ptr_vector<SfxAllEnumValue_Impl> mValues;
}; };
...@@ -96,9 +114,9 @@ SfxAllEnumItem::SfxAllEnumItem(const SfxAllEnumItem &rCopy): ...@@ -96,9 +114,9 @@ SfxAllEnumItem::SfxAllEnumItem(const SfxAllEnumItem &rCopy):
for ( sal_uInt16 nPos = 0; nPos < rCopy.pValues->size(); ++nPos ) for ( sal_uInt16 nPos = 0; nPos < rCopy.pValues->size(); ++nPos )
{ {
SfxAllEnumValue_Impl *pVal = new SfxAllEnumValue_Impl; SfxAllEnumValue_Impl *pVal = new SfxAllEnumValue_Impl;
pVal->nValue = (*rCopy.pValues)[nPos]->nValue; pVal->nValue = (*rCopy.pValues)[nPos].nValue;
pVal->aText = (*rCopy.pValues)[nPos]->aText; pVal->aText = (*rCopy.pValues)[nPos].aText;
pValues->insert( pValues->begin() + nPos, pVal ); pValues->Insert( nPos, pVal );
} }
if( rCopy.pDisabledValues ) if( rCopy.pDisabledValues )
...@@ -127,7 +145,7 @@ sal_uInt16 SfxAllEnumItem::GetValueCount() const ...@@ -127,7 +145,7 @@ sal_uInt16 SfxAllEnumItem::GetValueCount() const
OUString SfxAllEnumItem::GetValueTextByPos( sal_uInt16 nPos ) const OUString SfxAllEnumItem::GetValueTextByPos( sal_uInt16 nPos ) const
{ {
DBG_ASSERT( pValues && nPos < pValues->size(), "enum overflow" ); DBG_ASSERT( pValues && nPos < pValues->size(), "enum overflow" );
return (*pValues)[nPos]->aText; return (*pValues)[nPos].aText;
} }
...@@ -135,7 +153,7 @@ OUString SfxAllEnumItem::GetValueTextByPos( sal_uInt16 nPos ) const ...@@ -135,7 +153,7 @@ OUString SfxAllEnumItem::GetValueTextByPos( sal_uInt16 nPos ) const
sal_uInt16 SfxAllEnumItem::GetValueByPos( sal_uInt16 nPos ) const sal_uInt16 SfxAllEnumItem::GetValueByPos( sal_uInt16 nPos ) const
{ {
DBG_ASSERT( pValues && nPos < pValues->size(), "enum overflow" ); DBG_ASSERT( pValues && nPos < pValues->size(), "enum overflow" );
return (*pValues)[nPos]->nValue; return (*pValues)[nPos].nValue;
} }
...@@ -171,7 +189,7 @@ sal_uInt16 SfxAllEnumItem::_GetPosByValue( sal_uInt16 nVal ) const ...@@ -171,7 +189,7 @@ sal_uInt16 SfxAllEnumItem::_GetPosByValue( sal_uInt16 nVal ) const
//!O: binaere Suche oder SortArray verwenden //!O: binaere Suche oder SortArray verwenden
sal_uInt16 nPos; sal_uInt16 nPos;
for ( nPos = 0; nPos < pValues->size(); ++nPos ) for ( nPos = 0; nPos < pValues->size(); ++nPos )
if ( (*pValues)[nPos]->nValue >= nVal ) if ( (*pValues)[nPos].nValue >= nVal )
return nPos; return nPos;
return nPos; return nPos;
} }
...@@ -207,7 +225,7 @@ void SfxAllEnumItem::InsertValue( sal_uInt16 nValue, const OUString &rValue ) ...@@ -207,7 +225,7 @@ void SfxAllEnumItem::InsertValue( sal_uInt16 nValue, const OUString &rValue )
// remove when exists // remove when exists
RemoveValue( nValue ); RemoveValue( nValue );
// then insert // then insert
pValues->insert( pValues->begin() + _GetPosByValue(nValue), pVal ); //! doppelte?! pValues->Insert( _GetPosByValue(nValue), pVal ); //! doppelte?!
} }
...@@ -220,7 +238,7 @@ void SfxAllEnumItem::InsertValue( sal_uInt16 nValue ) ...@@ -220,7 +238,7 @@ void SfxAllEnumItem::InsertValue( sal_uInt16 nValue )
if ( !pValues ) if ( !pValues )
pValues = new SfxAllEnumValueArr; pValues = new SfxAllEnumValueArr;
pValues->insert( pValues->begin() + _GetPosByValue(nValue), pVal ); //! doppelte?! pValues->Insert( _GetPosByValue(nValue), pVal ); //! doppelte?!
} }
void SfxAllEnumItem::DisableValue( sal_uInt16 nValue ) void SfxAllEnumItem::DisableValue( sal_uInt16 nValue )
...@@ -249,7 +267,7 @@ void SfxAllEnumItem::RemoveValue( sal_uInt16 nValue ) ...@@ -249,7 +267,7 @@ void SfxAllEnumItem::RemoveValue( sal_uInt16 nValue )
{ {
sal_uInt16 nPos = GetPosByValue(nValue); sal_uInt16 nPos = GetPosByValue(nValue);
DBG_ASSERT( nPos != USHRT_MAX, "removing value not in enum" ); DBG_ASSERT( nPos != USHRT_MAX, "removing value not in enum" );
pValues->erase( pValues->begin() + nPos ); pValues->Erase( nPos );
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment