diff options
author | Michael Stahl <mstahl@redhat.com> | 2015-11-06 17:03:25 +0100 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2015-11-06 20:37:39 +0100 |
commit | 37856f59d2351951b95cf5eb3a5e4f0c011a8762 (patch) | |
tree | 55777665cff7b7145c5b54cf7503aab5db33ca34 | |
parent | ce6401c263b9f098c1fad636656749db6c6f22a1 (diff) |
sc: replace boost::ptr_vector with std::vector<std::unique_ptr>
Change-Id: Iea907bd407d0a6d1d7fa8a5a98ae7a9b4bbed642
-rw-r--r-- | sc/inc/dpsave.hxx | 9 | ||||
-rw-r--r-- | sc/source/core/data/dpsave.cxx | 89 | ||||
-rw-r--r-- | sc/source/filter/excel/xepivot.cxx | 9 | ||||
-rw-r--r-- | sc/source/filter/excel/xepivotxml.cxx | 2 | ||||
-rw-r--r-- | sc/source/filter/xml/XMLExportDataPilot.cxx | 10 | ||||
-rw-r--r-- | sc/source/ui/unoobj/dapiuno.cxx | 17 |
6 files changed, 63 insertions, 73 deletions
diff --git a/sc/inc/dpsave.hxx b/sc/inc/dpsave.hxx index 77cdcf54a5c1..4d7467aa2a16 100644 --- a/sc/inc/dpsave.hxx +++ b/sc/inc/dpsave.hxx @@ -22,8 +22,7 @@ #include <list> #include <memory> - -#include <boost/ptr_container/ptr_vector.hpp> +#include <vector> #include <com/sun/star/sheet/XDimensionsSupplier.hpp> #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp> @@ -241,10 +240,10 @@ class ScDPSaveData typedef std::unordered_map<OUString, size_t, OUStringHash> DupNameCountType; public: typedef std::unordered_map<OUString, size_t, OUStringHash> DimOrderType; - typedef boost::ptr_vector<ScDPSaveDimension> DimsType; + typedef std::vector<std::unique_ptr<ScDPSaveDimension>> DimsType; private: - DimsType aDimList; + DimsType m_DimList; DupNameCountType maDupNameCounts; /// keep track of number of duplicates in each name. ScDPDimensionSaveData* pDimensionData; // settings that create new dimensions sal_uInt16 nColumnGrandMode; @@ -273,7 +272,7 @@ public: SC_DLLPUBLIC void SetGrandTotalName(const OUString& rName); SC_DLLPUBLIC const OUString* GetGrandTotalName() const; - const DimsType& GetDimensions() const { return aDimList;} + const DimsType& GetDimensions() const { return m_DimList; } /** * Get sort order map to sort row and column dimensions in order of diff --git a/sc/source/core/data/dpsave.cxx b/sc/source/core/data/dpsave.cxx index f9d1526d6e28..e15dd8874146 100644 --- a/sc/source/core/data/dpsave.cxx +++ b/sc/source/core/data/dpsave.cxx @@ -28,7 +28,9 @@ #include <sal/types.h> #include <osl/diagnose.h> +#include <o3tl/make_unique.hxx> #include <comphelper/string.hxx> +#include <comphelper/stl_types.hxx> #include <com/sun/star/sheet/GeneralFunction.hpp> #include <com/sun/star/sheet/DataPilotFieldAutoShowInfo.hpp> @@ -825,7 +827,10 @@ ScDPSaveData::ScDPSaveData(const ScDPSaveData& r) : else pDimensionData = nullptr; - aDimList = r.aDimList.clone(); + for (auto const& it : r.m_DimList) + { + m_DimList.push_back(o3tl::make_unique<ScDPSaveDimension>(*it)); + } if (r.mpGrandTotalName) mpGrandTotalName.reset(new OUString(*r.mpGrandTotalName)); @@ -856,10 +861,7 @@ bool ScDPSaveData::operator== ( const ScDPSaveData& r ) const if ( !pDimensionData || !r.pDimensionData || !( *pDimensionData == *r.pDimensionData ) ) return false; - if ( aDimList.size() != r.aDimList.size() ) - return false; - - if (aDimList != r.aDimList) + if (!(::comphelper::ContainerUniquePtrEquals(m_DimList, r.m_DimList))) return false; if (mpGrandTotalName) @@ -927,8 +929,7 @@ void ScDPSaveData::GetAllDimensionsByOrientation( sheet::DataPilotFieldOrientation eOrientation, std::vector<const ScDPSaveDimension*>& rDims) const { std::vector<const ScDPSaveDimension*> aDims; - DimsType::const_iterator it = aDimList.begin(), itEnd = aDimList.end(); - for (; it != itEnd; ++it) + for (auto const& it : m_DimList) { const ScDPSaveDimension& rDim = *it; if (rDim.GetOrientation() != static_cast<sal_uInt16>(eOrientation)) @@ -946,15 +947,14 @@ void ScDPSaveData::AddDimension(ScDPSaveDimension* pDim) return; CheckDuplicateName(*pDim); - aDimList.push_back(pDim); + m_DimList.push_back(std::unique_ptr<ScDPSaveDimension>(pDim)); DimensionsChanged(); } ScDPSaveDimension* ScDPSaveData::GetDimensionByName(const OUString& rName) { - boost::ptr_vector<ScDPSaveDimension>::const_iterator iter; - for (iter = aDimList.begin(); iter != aDimList.end(); ++iter) + for (auto const& iter : m_DimList) { if (iter->GetName() == rName && !iter->IsDataLayout() ) return const_cast<ScDPSaveDimension*>(&(*iter)); @@ -965,8 +965,7 @@ ScDPSaveDimension* ScDPSaveData::GetDimensionByName(const OUString& rName) ScDPSaveDimension* ScDPSaveData::GetExistingDimensionByName(const OUString& rName) const { - boost::ptr_vector<ScDPSaveDimension>::const_iterator iter; - for (iter = aDimList.begin(); iter != aDimList.end(); ++iter) + for (auto const& iter : m_DimList) { if (iter->GetName() == rName && !iter->IsDataLayout() ) return const_cast<ScDPSaveDimension*>(&(*iter)); @@ -976,8 +975,7 @@ ScDPSaveDimension* ScDPSaveData::GetExistingDimensionByName(const OUString& rNam ScDPSaveDimension* ScDPSaveData::GetNewDimensionByName(const OUString& rName) { - boost::ptr_vector<ScDPSaveDimension>::const_iterator iter; - for (iter = aDimList.begin(); iter != aDimList.end(); ++iter) + for (auto const& iter : m_DimList) { if (iter->GetName() == rName && !iter->IsDataLayout() ) return DuplicateDimension(rName); @@ -997,8 +995,7 @@ ScDPSaveDimension* ScDPSaveData::GetDataLayoutDimension() ScDPSaveDimension* ScDPSaveData::GetExistingDataLayoutDimension() const { - boost::ptr_vector<ScDPSaveDimension>::const_iterator iter; - for (iter = aDimList.begin(); iter != aDimList.end(); ++iter) + for (auto const& iter : m_DimList) { if ( iter->IsDataLayout() ) return const_cast<ScDPSaveDimension*>(&(*iter)); @@ -1021,13 +1018,12 @@ ScDPSaveDimension* ScDPSaveData::DuplicateDimension(const OUString& rName) void ScDPSaveData::RemoveDimensionByName(const OUString& rName) { - boost::ptr_vector<ScDPSaveDimension>::iterator iter; - for (iter = aDimList.begin(); iter != aDimList.end(); ++iter) + for (auto iter = m_DimList.begin(); iter != m_DimList.end(); ++iter) { - if (iter->GetName() != rName || iter->IsDataLayout()) + if ((*iter)->GetName() != rName || (*iter)->IsDataLayout()) continue; - aDimList.erase(iter); + m_DimList.erase(iter); RemoveDuplicateNameCount(rName); DimensionsChanged(); return; @@ -1046,8 +1042,7 @@ ScDPSaveDimension* ScDPSaveData::GetInnermostDimension(sal_uInt16 nOrientation) // return the innermost dimension for the given orientation, // excluding data layout dimension - boost::ptr_vector<ScDPSaveDimension>::const_reverse_iterator iter; - for (iter = aDimList.rbegin(); iter != aDimList.rend(); ++iter) + for (auto const& iter : m_DimList) { if (iter->GetOrientation() == nOrientation && !iter->IsDataLayout()) return const_cast<ScDPSaveDimension*>(&(*iter)); @@ -1058,8 +1053,7 @@ ScDPSaveDimension* ScDPSaveData::GetInnermostDimension(sal_uInt16 nOrientation) ScDPSaveDimension* ScDPSaveData::GetFirstDimension(sheet::DataPilotFieldOrientation eOrientation) { - boost::ptr_vector<ScDPSaveDimension>::const_iterator iter; - for (iter = aDimList.begin(); iter != aDimList.end(); ++iter) + for (auto const& iter : m_DimList) { if (iter->GetOrientation() == eOrientation && !iter->IsDataLayout()) return const_cast<ScDPSaveDimension*>(&(*iter)); @@ -1071,8 +1065,7 @@ long ScDPSaveData::GetDataDimensionCount() const { long nDataCount = 0; - boost::ptr_vector<ScDPSaveDimension>::const_iterator iter; - for (iter = aDimList.begin(); iter != aDimList.end(); ++iter) + for (auto const& iter : m_DimList) { if (iter->GetOrientation() == sheet::DataPilotFieldOrientation_DATA) ++nDataCount; @@ -1087,29 +1080,29 @@ void ScDPSaveData::SetPosition( ScDPSaveDimension* pDim, long nNew ) sal_uInt16 nOrient = pDim->GetOrientation(); - boost::ptr_vector<ScDPSaveDimension>::iterator it; - for ( it = aDimList.begin(); it != aDimList.end(); ++it) + for (auto it = m_DimList.begin(); it != m_DimList.end(); ++it) { - if (pDim == &(*it)) + if (pDim == it->get()) { // Tell ptr_vector to give up ownership of this element. Don't // delete this instance as it is re-inserted into the container // later. - aDimList.release(it).release(); + it->release(); + m_DimList.erase(it); break; } } - boost::ptr_vector<ScDPSaveDimension>::iterator iterInsert = aDimList.begin(); - while ( nNew > 0 && iterInsert != aDimList.end()) + auto iterInsert = m_DimList.begin(); + while ( nNew > 0 && iterInsert != m_DimList.end()) { - if (iterInsert->GetOrientation() == nOrient ) + if ((*iterInsert)->GetOrientation() == nOrient ) --nNew; ++iterInsert; } - aDimList.insert(iterInsert,pDim); + m_DimList.insert(iterInsert, std::unique_ptr<ScDPSaveDimension>(pDim)); DimensionsChanged(); } @@ -1210,15 +1203,15 @@ void ScDPSaveData::WriteToSource( const uno::Reference<sheet::XDimensionsSupplie uno::Reference<container::XIndexAccess> xIntDims = new ScNameToIndexAccess( xDimsName ); long nIntCount = xIntDims->getCount(); - boost::ptr_vector<ScDPSaveDimension>::iterator iter = aDimList.begin(); - for (long i = 0; iter != aDimList.end(); ++iter, ++i) + auto iter = m_DimList.begin(); + for (long i = 0; iter != m_DimList.end(); ++iter, ++i) { - OUString aName = iter->GetName(); + OUString aName = (*iter)->GetName(); OUString aCoreName = ScDPUtil::getSourceDimensionName(aName); SAL_INFO("sc.core", aName); - bool bData = iter->IsDataLayout(); + bool bData = (*iter)->IsDataLayout(); //TODO: getByName for ScDPSource, including DataLayoutDimension !!!!!!!! @@ -1245,7 +1238,7 @@ void ScDPSaveData::WriteToSource( const uno::Reference<sheet::XDimensionsSupplie if (bFound) { - if (iter->GetDupFlag()) + if ((*iter)->GetDupFlag()) { uno::Reference<util::XCloneable> xCloneable(xIntDim, uno::UNO_QUERY); OSL_ENSURE(xCloneable.is(), "cannot clone dimension"); @@ -1256,12 +1249,12 @@ void ScDPSaveData::WriteToSource( const uno::Reference<sheet::XDimensionsSupplie if (xNewName.is()) { xNewName->setName(aName); - iter->WriteToSource(xNew); + (*iter)->WriteToSource(xNew); } } } else - iter->WriteToSource( xIntDim ); + (*iter)->WriteToSource( xIntDim ); } } OSL_ENSURE(bFound, "WriteToSource: Dimension not found"); @@ -1285,8 +1278,7 @@ void ScDPSaveData::WriteToSource( const uno::Reference<sheet::XDimensionsSupplie bool ScDPSaveData::IsEmpty() const { - boost::ptr_vector<ScDPSaveDimension>::const_iterator iter; - for (iter = aDimList.begin(); iter != aDimList.end(); ++iter) + for (auto const& iter : m_DimList) { if (iter->GetOrientation() != sheet::DataPilotFieldOrientation_HIDDEN && !iter->IsDataLayout()) return false; @@ -1361,8 +1353,7 @@ void ScDPSaveData::BuildAllDimensionMembers(ScDPTableData* pData) NameIndexMap::const_iterator itrEnd = aMap.end(); - boost::ptr_vector<ScDPSaveDimension>::iterator iter; - for (iter = aDimList.begin(); iter != aDimList.end(); ++iter) + for (auto const& iter : m_DimList) { const OUString& rDimName = iter->GetName(); if (rDimName.isEmpty()) @@ -1406,8 +1397,7 @@ void ScDPSaveData::SyncAllDimensionMembers(ScDPTableData* pData) NameIndexMap::const_iterator itMapEnd = aMap.end(); - DimsType::iterator it = aDimList.begin(), itEnd = aDimList.end(); - for (it = aDimList.begin(); it != itEnd; ++it) + for (auto const& it : m_DimList) { const OUString& rDimName = it->GetName(); if (rDimName.isEmpty()) @@ -1447,8 +1437,7 @@ bool ScDPSaveData::HasInvisibleMember(const OUString& rDimName) const void ScDPSaveData::Dump() const { - DimsType::const_iterator itDim = aDimList.begin(), itDimEnd = aDimList.end(); - for (; itDim != itDimEnd; ++itDim) + for (auto const& itDim : m_DimList) { const ScDPSaveDimension& rDim = *itDim; rDim.Dump(); @@ -1498,7 +1487,7 @@ ScDPSaveDimension* ScDPSaveData::AppendNewDimension(const OUString& rName, bool return nullptr; ScDPSaveDimension* pNew = new ScDPSaveDimension(rName, bDataLayout); - aDimList.push_back(pNew); + m_DimList.push_back(std::unique_ptr<ScDPSaveDimension>(pNew)); if (!maDupNameCounts.count(rName)) maDupNameCounts.insert(DupNameCountType::value_type(rName, 0)); diff --git a/sc/source/filter/excel/xepivot.cxx b/sc/source/filter/excel/xepivot.cxx index 416329b605a6..a0ca2ba81c30 100644 --- a/sc/source/filter/excel/xepivot.cxx +++ b/sc/source/filter/excel/xepivot.cxx @@ -1205,19 +1205,22 @@ XclExpPivotTable::XclExpPivotTable( const XclExpRoot& rRoot, const ScDPObject& r for( sal_uInt16 nFieldIdx = 0, nFieldCount = mrPCache.GetFieldCount(); nFieldIdx < nFieldCount; ++nFieldIdx ) maFieldList.AppendNewRecord( new XclExpPTField( *this, nFieldIdx ) ); - boost::ptr_vector<ScDPSaveDimension>::const_iterator iter; const ScDPSaveData::DimsType& rDimList = pSaveData->GetDimensions(); /* 2) First process all data dimensions, they are needed for extended settings of row/column/page fields (sorting/auto show). */ - for (iter = rDimList.begin(); iter != rDimList.end(); ++iter) + for (auto const& iter : rDimList) + { if (iter->GetOrientation() == DataPilotFieldOrientation_DATA) SetDataFieldPropertiesFromDim(*iter); + } /* 3) Row/column/page/hidden fields. */ - for (iter = rDimList.begin(); iter != rDimList.end(); ++iter) + for (auto const& iter : rDimList) + { if (iter->GetOrientation() != DataPilotFieldOrientation_DATA) SetFieldPropertiesFromDim(*iter); + } // Finalize ------------------------------------------------------- diff --git a/sc/source/filter/excel/xepivotxml.cxx b/sc/source/filter/excel/xepivotxml.cxx index 917af8d95c7d..1fd6f7dcc8bc 100644 --- a/sc/source/filter/excel/xepivotxml.cxx +++ b/sc/source/filter/excel/xepivotxml.cxx @@ -451,7 +451,7 @@ void XclExpXmlPivotTables::SavePivotTableXml( XclExpXmlStream& rStrm, const ScDP for (size_t i = 0, n = rDims.size(); i < n; ++i) { - const ScDPSaveDimension& rDim = rDims[i]; + const ScDPSaveDimension& rDim = *rDims[i]; long nPos = -1; // position in cache if (rDim.IsDataLayout()) diff --git a/sc/source/filter/xml/XMLExportDataPilot.cxx b/sc/source/filter/xml/XMLExportDataPilot.cxx index 5c5338040c76..eff5e31c328c 100644 --- a/sc/source/filter/xml/XMLExportDataPilot.cxx +++ b/sc/source/filter/xml/XMLExportDataPilot.cxx @@ -720,10 +720,12 @@ void ScXMLExportDataPilot::WriteDimension(ScDPSaveDimension* pDim, const ScDPDim void ScXMLExportDataPilot::WriteDimensions(ScDPSaveData* pDPSave) { - const boost::ptr_vector<ScDPSaveDimension> &rDimensions = pDPSave->GetDimensions(); - boost::ptr_vector<ScDPSaveDimension>::const_iterator iter; - for (iter = rDimensions.begin(); iter != rDimensions.end(); ++iter) - WriteDimension(const_cast<ScDPSaveDimension*>(&(*iter)), pDPSave->GetExistingDimensionData()); + const ScDPSaveData::DimsType& rDimensions = pDPSave->GetDimensions(); + for (auto const& iter : rDimensions) + { + WriteDimension(const_cast<ScDPSaveDimension*>(iter.get()), + pDPSave->GetExistingDimensionData()); + } } void ScXMLExportDataPilot::WriteGrandTotal(::xmloff::token::XMLTokenEnum eOrient, bool bVisible, const OUString* pGrandTotal) diff --git a/sc/source/ui/unoobj/dapiuno.cxx b/sc/source/ui/unoobj/dapiuno.cxx index 04cdd8822f59..f6422ca750d7 100644 --- a/sc/source/ui/unoobj/dapiuno.cxx +++ b/sc/source/ui/unoobj/dapiuno.cxx @@ -1486,8 +1486,7 @@ ScDPSaveDimension* ScDataPilotChildObjBase::GetDPDimension( ScDPObject** ppDPObj const ScDPSaveData::DimsType& rDims = pSaveData->GetDimensions(); sal_Int32 nFoundIdx = 0; - ScDPSaveData::DimsType::const_iterator it; - for (it = rDims.begin(); it != rDims.end(); ++it) + for (auto const& it : rDims) { if (it->IsDataLayout()) continue; @@ -1496,7 +1495,7 @@ ScDPSaveDimension* ScDataPilotChildObjBase::GetDPDimension( ScDPObject** ppDPObj if (aSrcName == maFieldId.maFieldName) { if( nFoundIdx == maFieldId.mnFieldIdx ) - return const_cast<ScDPSaveDimension*>(&(*it)); + return const_cast<ScDPSaveDimension*>(it.get()); ++nFoundIdx; } } @@ -1769,9 +1768,8 @@ Sequence<OUString> SAL_CALL ScDataPilotFieldsObj::getElementNames() Sequence< OUString > aSeq( lcl_GetFieldCount( pDPObj->GetSource(), maOrient ) ); OUString* pAry = aSeq.getArray(); - const boost::ptr_vector<ScDPSaveDimension>& rDimensions = pDPObj->GetSaveData()->GetDimensions(); - boost::ptr_vector<ScDPSaveDimension>::const_iterator it; - for (it = rDimensions.begin(); it != rDimensions.end(); ++it) + const ScDPSaveData::DimsType& rDimensions = pDPObj->GetSaveData()->GetDimensions(); + for (auto const& it : rDimensions) { if(maOrient.hasValue() && (it->GetOrientation() == maOrient.get< DataPilotFieldOrientation >())) { @@ -2067,14 +2065,13 @@ void ScDataPilotFieldObj::setOrientation(DataPilotFieldOrientation eNew) // look for existing duplicate with orientation "hidden" sal_Int32 nFound = 0; - const boost::ptr_vector<ScDPSaveDimension>& rDimensions = pSaveData->GetDimensions(); - boost::ptr_vector<ScDPSaveDimension>::const_iterator it; - for ( it = rDimensions.begin(); it != rDimensions.end() && !pNewDim; ++it ) + const ScDPSaveData::DimsType& rDimensions = pSaveData->GetDimensions(); + for (auto const& it : rDimensions) { if ( !it->IsDataLayout() && (it->GetName() == maFieldId.maFieldName) ) { if ( it->GetOrientation() == DataPilotFieldOrientation_HIDDEN ) - pNewDim = const_cast<ScDPSaveDimension*>(&(*it)); // use this one + pNewDim = const_cast<ScDPSaveDimension*>(it.get()); // use this one else ++nFound; // count existing non-hidden occurrences } |