diff options
author | Noel Grandin <noel@peralex.com> | 2012-05-10 15:07:32 +0200 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2012-05-14 19:49:14 +0200 |
commit | 0be2a98cc04ee26f605a6f6e7efbdee325560a91 (patch) | |
tree | 255ab0da65e5446216df1d2a21fb0831b369cc02 /sw | |
parent | 21155b8739b1a90455e75b9b527c75e27390455c (diff) |
Convert V_DECL_PTRARR_DEL(SortKeyArr) to boost::ptr_vector
Removed the copy constructor because it was dangerous,
it could result in accessing an SwTOXSortKey object after it was released.
Removed the operator= because it was private, and no longer used.
Change-Id: Ifaf21cbbad5f8b9cabddcc3009e4ed776b1fdd71
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/authfld.hxx | 9 | ||||
-rw-r--r-- | sw/source/core/fields/authfld.cxx | 46 |
2 files changed, 15 insertions, 40 deletions
diff --git a/sw/inc/authfld.hxx b/sw/inc/authfld.hxx index e17e8239a1bf..cb859e351693 100644 --- a/sw/inc/authfld.hxx +++ b/sw/inc/authfld.hxx @@ -33,6 +33,7 @@ #include <toxe.hxx> #include <svl/svstdarr.hxx> #include <vector> +#include <boost/ptr_container/ptr_vector.hpp> class SwAuthDataArr; @@ -64,14 +65,14 @@ struct SwTOXSortKey }; class SwAuthorityField; -class SortKeyArr; +typedef boost::ptr_vector<SwTOXSortKey> SortKeyArr; class SW_DLLPUBLIC SwAuthorityFieldType : public SwFieldType { SwDoc* m_pDoc; SwAuthDataArr* m_pDataArr; std::vector<long> m_SequArr; - SortKeyArr* m_pSortKeyArr; + SortKeyArr m_SortKeyArr; sal_Unicode m_cPrefix; sal_Unicode m_cSuffix; sal_Bool m_bIsSequence :1; @@ -79,15 +80,11 @@ class SW_DLLPUBLIC SwAuthorityFieldType : public SwFieldType LanguageType m_eLanguage; String m_sSortAlgorithm; - // @@@ private copy assignment, but public copy ctor? @@@ - const SwAuthorityFieldType& operator=( const SwAuthorityFieldType& ); - protected: virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew ); public: SwAuthorityFieldType(SwDoc* pDoc); - SwAuthorityFieldType( const SwAuthorityFieldType& ); ~SwAuthorityFieldType(); virtual SwFieldType* Copy() const; diff --git a/sw/source/core/fields/authfld.cxx b/sw/source/core/fields/authfld.cxx index c85759d17554..576814b135aa 100644 --- a/sw/source/core/fields/authfld.cxx +++ b/sw/source/core/fields/authfld.cxx @@ -61,10 +61,6 @@ SV_DECL_PTRARR_DEL( SwAuthDataArr, SwAuthEntryPtr, 5 ) SV_IMPL_PTRARR( SwAuthDataArr, SwAuthEntryPtr ) -typedef SwTOXSortKey* TOXSortKeyPtr; -SV_DECL_PTRARR_DEL( SortKeyArr, TOXSortKeyPtr, 5 ) -SV_IMPL_PTRARR( SortKeyArr, TOXSortKeyPtr ) - SwAuthEntry::SwAuthEntry(const SwAuthEntry& rCopy) : nRefCount(0) { @@ -84,7 +80,7 @@ SwAuthorityFieldType::SwAuthorityFieldType(SwDoc* pDoc) : SwFieldType( RES_AUTHORITY ), m_pDoc(pDoc), m_pDataArr(new SwAuthDataArr ), - m_pSortKeyArr(new SortKeyArr(3)), + m_SortKeyArr(3), m_cPrefix('['), m_cSuffix(']'), m_bIsSequence(sal_False), @@ -93,25 +89,8 @@ SwAuthorityFieldType::SwAuthorityFieldType(SwDoc* pDoc) { } -SwAuthorityFieldType::SwAuthorityFieldType( const SwAuthorityFieldType& rFType) - : SwFieldType( RES_AUTHORITY ), - m_pDataArr(new SwAuthDataArr ), - m_pSortKeyArr(new SortKeyArr(3)), - m_cPrefix(rFType.m_cPrefix), - m_cSuffix(rFType.m_cSuffix), - m_bIsSequence(rFType.m_bIsSequence), - m_bSortByDocument(rFType.m_bSortByDocument), - m_eLanguage(rFType.m_eLanguage), - m_sSortAlgorithm(rFType.m_sSortAlgorithm) -{ - for(sal_uInt16 i = 0; i < rFType.m_pSortKeyArr->Count(); i++) - m_pSortKeyArr->Insert((*rFType.m_pSortKeyArr)[i], i); -} - SwAuthorityFieldType::~SwAuthorityFieldType() { - m_pSortKeyArr->DeleteAndDestroy(0, m_pSortKeyArr->Count()); - delete m_pSortKeyArr; m_SequArr.clear(); delete m_pDataArr; } @@ -432,13 +411,13 @@ bool SwAuthorityFieldType::QueryValue( Any& rVal, sal_uInt16 nWhichId ) const case FIELD_PROP_PROP_SEQ: { - Sequence<PropertyValues> aRet(m_pSortKeyArr->Count()); + Sequence<PropertyValues> aRet(m_SortKeyArr.size()); PropertyValues* pValues = aRet.getArray(); OUString sProp1( rtl::OUString::createFromAscii(SW_PROP_NAME_STR(UNO_NAME_SORT_KEY)) ), sProp2( rtl::OUString::createFromAscii(SW_PROP_NAME_STR(UNO_NAME_IS_SORT_ASCENDING))); - for(sal_uInt16 i = 0; i < m_pSortKeyArr->Count(); i++) + for(sal_uInt16 i = 0; i < m_SortKeyArr.size(); i++) { - const SwTOXSortKey* pKey = (*m_pSortKeyArr)[i]; + const SwTOXSortKey* pKey = &m_SortKeyArr[i]; pValues[i].realloc(2); PropertyValue* pValue = pValues[i].getArray(); pValue[0].Name = sProp1; @@ -496,7 +475,7 @@ bool SwAuthorityFieldType::PutValue( const Any& rAny, sal_uInt16 nWhichId ) Sequence<PropertyValues> aSeq; if( 0 != (bRet = rAny >>= aSeq) ) { - m_pSortKeyArr->DeleteAndDestroy(0, m_pSortKeyArr->Count()); + m_SortKeyArr.clear(); const PropertyValues* pValues = aSeq.getConstArray(); for(sal_Int32 i = 0; i < aSeq.getLength() && i < USHRT_MAX / 4; i++) { @@ -517,7 +496,7 @@ bool SwAuthorityFieldType::PutValue( const Any& rAny, sal_uInt16 nWhichId ) pSortKey->bSortAscending = *(sal_Bool*)pValue[j].Value.getValue(); } } - m_pSortKeyArr->Insert(pSortKey, m_pSortKeyArr->Count()); + m_SortKeyArr.push_back(pSortKey); } } } @@ -537,25 +516,24 @@ void SwAuthorityFieldType::Modify( const SfxPoolItem* pOld, const SfxPoolItem *p sal_uInt16 SwAuthorityFieldType::GetSortKeyCount() const { - return m_pSortKeyArr->Count(); + return m_SortKeyArr.size(); } const SwTOXSortKey* SwAuthorityFieldType::GetSortKey(sal_uInt16 nIdx) const { - SwTOXSortKey* pRet = 0; - if(m_pSortKeyArr->Count() > nIdx) - pRet = (*m_pSortKeyArr)[nIdx]; + const SwTOXSortKey* pRet = 0; + if(m_SortKeyArr.size() > nIdx) + pRet = &m_SortKeyArr[nIdx]; OSL_ENSURE(pRet, "Sort key not found"); return pRet; } void SwAuthorityFieldType::SetSortKeys(sal_uInt16 nKeyCount, SwTOXSortKey aKeys[]) { - m_pSortKeyArr->DeleteAndDestroy(0, m_pSortKeyArr->Count()); - sal_uInt16 nArrIdx = 0; + m_SortKeyArr.clear(); for(sal_uInt16 i = 0; i < nKeyCount; i++) if(aKeys[i].eField < AUTH_FIELD_END) - m_pSortKeyArr->Insert(new SwTOXSortKey(aKeys[i]), nArrIdx++); + m_SortKeyArr.push_back(new SwTOXSortKey(aKeys[i])); } SwAuthorityField::SwAuthorityField( SwAuthorityFieldType* pInitType, |