summaryrefslogtreecommitdiff
path: root/sc/source
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2015-12-11 14:57:10 +0200
committerNoel Grandin <noel@peralex.com>2015-12-12 07:05:59 +0200
commite8c433b34754490e1415e6b98d2a3c51c7e5dbab (patch)
tree509e3671e385fa03affbb5656c543aac9ea750e9 /sc/source
parent3f928e54846b362c78d2740a600971b74a6d8745 (diff)
tdf#96339 fix bug in sort list
this bug was caused by commit 2aacf6c2cd82322b953988ff30d3bc997ae76d7b "sc: boost::ptr_vector->std::vector" Since the code in question likes passing around a pointer to the element of the vector, convert to using std::vector<std::unique_ptr> Change-Id: I9e9676fe7c2dc32e23ba6708aaea1f16c1bf2ff8 (cherry picked from commit 0bcef149ce3785306271fa06184eb62950b62087)
Diffstat (limited to 'sc/source')
-rw-r--r--sc/source/core/tool/appoptio.cxx4
-rw-r--r--sc/source/core/tool/userlist.cxx45
-rw-r--r--sc/source/ui/optdlg/tpusrlst.cxx2
-rw-r--r--sc/source/ui/unoobj/appluno.cxx4
4 files changed, 35 insertions, 20 deletions
diff --git a/sc/source/core/tool/appoptio.cxx b/sc/source/core/tool/appoptio.cxx
index 5328f67a353f..3bdf429dfa67 100644
--- a/sc/source/core/tool/appoptio.cxx
+++ b/sc/source/core/tool/appoptio.cxx
@@ -180,11 +180,11 @@ static void lcl_SetSortList( const Any& rValue )
if (!bDefault)
{
aList.clear();
- aList.reserve(nCount);
for (long i=0; i<nCount; i++)
{
- aList.push_back( ScUserListData( pArray[i] ) );
+ ScUserListData* pNew = new ScUserListData( pArray[i] );
+ aList.push_back(pNew);
}
}
diff --git a/sc/source/core/tool/userlist.cxx b/sc/source/core/tool/userlist.cxx
index 0299bfe7937f..39344a96e9b0 100644
--- a/sc/source/core/tool/userlist.cxx
+++ b/sc/source/core/tool/userlist.cxx
@@ -24,6 +24,7 @@
#include <unotools/localedatawrapper.hxx>
#include <unotools/calendarwrapper.hxx>
#include <unotools/transliterationwrapper.hxx>
+#include <o3tl/make_unique.hxx>
#include <boost/bind.hpp>
#include <algorithm>
@@ -96,6 +97,10 @@ ScUserListData::ScUserListData(const ScUserListData& rData) :
InitTokens();
}
+ScUserListData::~ScUserListData()
+{
+}
+
void ScUserListData::SetString( const OUString& rStr )
{
aStr = rStr;
@@ -233,9 +238,9 @@ ScUserList::ScUserList()
OUString aDayLong = aDayLongBuf.makeStringAndClear();
if ( !HasEntry( aDayShort ) )
- maData.push_back( ScUserListData( aDayShort ));
+ maData.push_back( o3tl::make_unique<ScUserListData>( aDayShort ));
if ( !HasEntry( aDayLong ) )
- maData.push_back( ScUserListData( aDayLong ));
+ maData.push_back( o3tl::make_unique<ScUserListData>( aDayLong ));
}
xCal = xCalendars[j].Months;
@@ -258,15 +263,18 @@ ScUserList::ScUserList()
OUString aMonthLong = aMonthLongBuf.makeStringAndClear();
if ( !HasEntry( aMonthShort ) )
- maData.push_back( ScUserListData( aMonthShort ));
+ maData.push_back( o3tl::make_unique<ScUserListData>( aMonthShort ));
if ( !HasEntry( aMonthLong ) )
- maData.push_back( ScUserListData( aMonthLong ));
+ maData.push_back( o3tl::make_unique<ScUserListData>( aMonthLong ));
}
}
}
-ScUserList::ScUserList(const ScUserList& r) :
- maData(r.maData) {}
+ScUserList::ScUserList(const ScUserList& rOther)
+{
+ for (const std::unique_ptr<ScUserListData>& rData : rOther.maData)
+ maData.push_back( o3tl::make_unique<ScUserListData>(*rData.get()) );
+}
const ScUserListData* ScUserList::GetData(const OUString& rSubStr) const
{
@@ -277,12 +285,12 @@ const ScUserListData* ScUserList::GetData(const OUString& rSubStr) const
for (; itr != itrEnd; ++itr)
{
- if (itr->GetSubIndex(rSubStr, nIndex, bMatchCase))
+ if ((*itr)->GetSubIndex(rSubStr, nIndex, bMatchCase))
{
if (bMatchCase)
- return &(*itr);
+ return itr->get();
if (!pFirstCaseInsensitive)
- pFirstCaseInsensitive = &(*itr);
+ pFirstCaseInsensitive = itr->get();
}
}
@@ -291,17 +299,19 @@ const ScUserListData* ScUserList::GetData(const OUString& rSubStr) const
const ScUserListData& ScUserList::operator[](size_t nIndex) const
{
- return maData[nIndex];
+ return *maData[nIndex].get();
}
ScUserListData& ScUserList::operator[](size_t nIndex)
{
- return maData[nIndex];
+ return *maData[nIndex].get();
}
-ScUserList& ScUserList::operator=( const ScUserList& r )
+ScUserList& ScUserList::operator=( const ScUserList& rOther )
{
- maData = r.maData;
+ maData.clear();
+ for (const std::unique_ptr<ScUserListData>& rData : rOther.maData)
+ maData.push_back( o3tl::make_unique<ScUserListData>(*rData.get()) );
return *this;
}
@@ -313,8 +323,8 @@ bool ScUserList::operator==( const ScUserList& r ) const
DataType::const_iterator itr1 = maData.begin(), itr2 = r.maData.begin(), itrEnd = maData.end();
for (; itr1 != itrEnd; ++itr1, ++itr2)
{
- const ScUserListData& v1 = *itr1;
- const ScUserListData& v2 = *itr2;
+ const ScUserListData& v1 = *itr1->get();
+ const ScUserListData& v2 = *itr2->get();
if (v1.GetString() != v2.GetString() || v1.GetSubCount() != v2.GetSubCount())
return false;
}
@@ -346,6 +356,11 @@ size_t ScUserList::size() const
return maData.size();
}
+void ScUserList::push_back(ScUserListData* p)
+{
+ maData.push_back(std::unique_ptr<ScUserListData>(p));
+}
+
void ScUserList::erase(iterator itr)
{
maData.erase(itr);
diff --git a/sc/source/ui/optdlg/tpusrlst.cxx b/sc/source/ui/optdlg/tpusrlst.cxx
index 2511027ec78e..9a4ff48aeea8 100644
--- a/sc/source/ui/optdlg/tpusrlst.cxx
+++ b/sc/source/ui/optdlg/tpusrlst.cxx
@@ -344,7 +344,7 @@ void ScTpUserLists::AddNewList( const OUString& rEntriesStr )
MakeListStr( theEntriesStr );
- pUserLists->push_back(ScUserListData(rEntriesStr));
+ pUserLists->push_back(new ScUserListData(theEntriesStr));
}
void ScTpUserLists::CopyListFromArea( const ScRefAddress& rStartPos,
diff --git a/sc/source/ui/unoobj/appluno.cxx b/sc/source/ui/unoobj/appluno.cxx
index c1d847d4008d..b597272f0d06 100644
--- a/sc/source/ui/unoobj/appluno.cxx
+++ b/sc/source/ui/unoobj/appluno.cxx
@@ -356,12 +356,12 @@ void SAL_CALL ScSpreadsheetSettings::setPropertyValue(
pUserList->clear(); // alle Eintraege raus
sal_uInt16 nCount = (sal_uInt16)aSeq.getLength();
- pUserList->reserve(nCount);
const OUString* pAry = aSeq.getConstArray();
for (sal_uInt16 i=0; i<nCount; i++)
{
OUString aEntry = pAry[i];
- pUserList->push_back( ScUserListData(aEntry) );
+ ScUserListData* pData = new ScUserListData(aEntry);
+ pUserList->push_back(pData);
}
bSaveApp = true; // Liste wird mit den App-Optionen gespeichert
}