diff options
author | Noel Grandin <noel@peralex.com> | 2020-10-08 10:21:09 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-10-08 18:45:29 +0200 |
commit | 592ad72ae178bc9018354ab37224666293ecbe81 (patch) | |
tree | 60954e07087ff8ee053e29e62d72ec1c281caa04 /svl | |
parent | 9b6fb8bf3d8e622bd2d013744a591ff32287d3de (diff) |
use sal_Int32 for style-sheet index
instead of a mix of unsigned and sal_uInt16.
Change-Id: Ice56d58d22856daa6645577610368ba19a849176
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104076
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svl')
-rw-r--r-- | svl/qa/unit/items/test_IndexedStyleSheets.cxx | 24 | ||||
-rw-r--r-- | svl/source/items/IndexedStyleSheets.cxx | 43 | ||||
-rw-r--r-- | svl/source/items/style.cxx | 23 |
3 files changed, 43 insertions, 47 deletions
diff --git a/svl/qa/unit/items/test_IndexedStyleSheets.cxx b/svl/qa/unit/items/test_IndexedStyleSheets.cxx index 50fd4d1ed42c..5c12acc250a5 100644 --- a/svl/qa/unit/items/test_IndexedStyleSheets.cxx +++ b/svl/qa/unit/items/test_IndexedStyleSheets.cxx @@ -91,9 +91,9 @@ void IndexedStyleSheetsTest::AddingSameStylesheetTwiceHasNoEffect() rtl::Reference<SfxStyleSheetBase> sheet1(new MockedStyleSheet("sheet1")); IndexedStyleSheets iss; iss.AddStyleSheet(sheet1); - CPPUNIT_ASSERT_EQUAL(1u, iss.GetNumberOfStyleSheets()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), iss.GetNumberOfStyleSheets()); iss.AddStyleSheet(sheet1); - CPPUNIT_ASSERT_EQUAL(1u, iss.GetNumberOfStyleSheets()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), iss.GetNumberOfStyleSheets()); } void IndexedStyleSheetsTest::RemovedStyleSheetIsNotFound() @@ -114,9 +114,9 @@ void IndexedStyleSheetsTest::RemovingStyleSheetWhichIsNotAvailableHasNoEffect() rtl::Reference<SfxStyleSheetBase> sheet2(new MockedStyleSheet("sheet2")); IndexedStyleSheets iss; iss.AddStyleSheet(sheet1); - CPPUNIT_ASSERT_EQUAL(1u, iss.GetNumberOfStyleSheets()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), iss.GetNumberOfStyleSheets()); iss.RemoveStyleSheet(sheet2); - CPPUNIT_ASSERT_EQUAL(1u, iss.GetNumberOfStyleSheets()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), iss.GetNumberOfStyleSheets()); } void IndexedStyleSheetsTest::StyleSheetsCanBeRetrievedByTheirName() @@ -131,17 +131,17 @@ void IndexedStyleSheetsTest::StyleSheetsCanBeRetrievedByTheirName() iss.AddStyleSheet(sheet2); iss.AddStyleSheet(sheet3); - std::vector<unsigned> r = iss.FindPositionsByName(name1); + std::vector<sal_Int32> r = iss.FindPositionsByName(name1); CPPUNIT_ASSERT_EQUAL_MESSAGE("Two style sheets are found by 'name1'", 2u, static_cast<unsigned>(r.size())); std::sort (r.begin(), r.end()); - CPPUNIT_ASSERT_EQUAL(0u, r.at(0)); - CPPUNIT_ASSERT_EQUAL(2u, r.at(1)); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), r.at(0)); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), r.at(1)); r = iss.FindPositionsByName(name2); CPPUNIT_ASSERT_EQUAL_MESSAGE("One style sheets is found by 'name2'", 1u, static_cast<unsigned>(r.size())); - CPPUNIT_ASSERT_EQUAL(1u, r.at(0)); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), r.at(0)); } void IndexedStyleSheetsTest::KnowsThatItStoresAStyleSheet() @@ -176,10 +176,10 @@ void IndexedStyleSheetsTest::PositionCanBeQueriedByFamily() iss.AddStyleSheet(sheet2); iss.AddStyleSheet(sheet3); - const std::vector<unsigned>& v = iss.GetStyleSheetPositionsByFamily(SfxStyleFamily::Char); + const std::vector<sal_Int32>& v = iss.GetStyleSheetPositionsByFamily(SfxStyleFamily::Char); CPPUNIT_ASSERT_EQUAL_MESSAGE("Separation by family works.", static_cast<size_t>(2), v.size()); - const std::vector<unsigned>& w = iss.GetStyleSheetPositionsByFamily(SfxStyleFamily::All); + const std::vector<sal_Int32>& w = iss.GetStyleSheetPositionsByFamily(SfxStyleFamily::All); CPPUNIT_ASSERT_EQUAL_MESSAGE("Wildcard works for family queries.", static_cast<size_t>(3), w.size()); } @@ -197,11 +197,11 @@ void IndexedStyleSheetsTest::OnlyOneStyleSheetIsReturnedWhenReturnFirstIsUsed() DummyPredicate predicate; // returns always true, i.e., all style sheets match the predicate. - std::vector<unsigned> v = iss.FindPositionsByNameAndPredicate(name, predicate, + std::vector<sal_Int32> v = iss.FindPositionsByNameAndPredicate(name, predicate, IndexedStyleSheets::SearchBehavior::ReturnFirst); CPPUNIT_ASSERT_EQUAL_MESSAGE("Only one style sheet is returned.", static_cast<size_t>(1), v.size()); - std::vector<unsigned> w = iss.FindPositionsByNameAndPredicate(name, predicate); + std::vector<sal_Int32> w = iss.FindPositionsByNameAndPredicate(name, predicate); CPPUNIT_ASSERT_EQUAL_MESSAGE("All style sheets are returned.", static_cast<size_t>(3), w.size()); } diff --git a/svl/source/items/IndexedStyleSheets.cxx b/svl/source/items/IndexedStyleSheets.cxx index 4d71e7e6ff95..57e2dddbf1c1 100644 --- a/svl/source/items/IndexedStyleSheets.cxx +++ b/svl/source/items/IndexedStyleSheets.cxx @@ -51,8 +51,7 @@ IndexedStyleSheets::IndexedStyleSheets() } ;} -void -IndexedStyleSheets::Register(const SfxStyleSheetBase& style, unsigned pos) +void IndexedStyleSheets::Register(const SfxStyleSheetBase& style, sal_Int32 pos) { mPositionsByName.insert(std::make_pair(style.GetName(), pos)); size_t position = family_to_index(style.GetFamily()); @@ -70,7 +69,7 @@ IndexedStyleSheets::Reindex() mStyleSheetPositionsByFamily.emplace_back(); } - unsigned i = 0; + sal_Int32 i = 0; for (const auto& rxStyleSheet : mStyleSheets) { SfxStyleSheetBase* p = rxStyleSheet.get(); Register(*p, i); @@ -78,8 +77,7 @@ IndexedStyleSheets::Reindex() } } -unsigned -IndexedStyleSheets::GetNumberOfStyleSheets() const +sal_Int32 IndexedStyleSheets::GetNumberOfStyleSheets() const { return mStyleSheets.size(); } @@ -100,7 +98,7 @@ IndexedStyleSheets::RemoveStyleSheet(const rtl::Reference< SfxStyleSheetBase >& std::pair<MapType::const_iterator, MapType::const_iterator> range = mPositionsByName.equal_range(style->GetName()); for (MapType::const_iterator it = range.first; it != range.second; ++it) { - unsigned pos = it->second; + sal_Int32 pos = it->second; if (mStyleSheets.at(pos) == style) { mStyleSheets.erase(mStyleSheets.begin() + pos); @@ -111,10 +109,9 @@ IndexedStyleSheets::RemoveStyleSheet(const rtl::Reference< SfxStyleSheetBase >& return false; } -std::vector<unsigned> -IndexedStyleSheets::FindPositionsByName(const OUString& name) const +std::vector<sal_Int32> IndexedStyleSheets::FindPositionsByName(const OUString& name) const { - std::vector<unsigned> r; + std::vector<sal_Int32> r; std::pair<MapType::const_iterator, MapType::const_iterator> range = mPositionsByName.equal_range(name); for (MapType::const_iterator it = range.first; it != range.second; ++it) { r.push_back(it->second); @@ -122,14 +119,13 @@ IndexedStyleSheets::FindPositionsByName(const OUString& name) const return r; } -std::vector<unsigned> -IndexedStyleSheets::FindPositionsByNameAndPredicate(const OUString& name, +std::vector<sal_Int32> IndexedStyleSheets::FindPositionsByNameAndPredicate(const OUString& name, StyleSheetPredicate& predicate, SearchBehavior behavior) const { - std::vector<unsigned> r; + std::vector<sal_Int32> r; auto range = mPositionsByName.equal_range(name); for (auto it = range.first; it != range.second; ++it) { - unsigned pos = it->second; + sal_Int32 pos = it->second; SfxStyleSheetBase *ssheet = mStyleSheets.at(pos).get(); if (predicate.Check(*ssheet)) { r.push_back(pos); @@ -142,7 +138,7 @@ IndexedStyleSheets::FindPositionsByNameAndPredicate(const OUString& name, } -unsigned +sal_Int32 IndexedStyleSheets::GetNumberOfStyleSheetsWithPredicate(StyleSheetPredicate& predicate) const { return std::count_if(mStyleSheets.begin(), mStyleSheets.end(), @@ -154,12 +150,12 @@ IndexedStyleSheets::GetNumberOfStyleSheetsWithPredicate(StyleSheetPredicate& pre SfxStyleSheetBase* IndexedStyleSheets::GetNthStyleSheetThatMatchesPredicate( - unsigned n, + sal_Int32 n, StyleSheetPredicate& predicate, - unsigned startAt) + sal_Int32 startAt) { SfxStyleSheetBase* retval = nullptr; - unsigned matching = 0; + sal_Int32 matching = 0; for (VectorType::const_iterator it = mStyleSheets.begin()+startAt; it != mStyleSheets.end(); ++it) { SfxStyleSheetBase *ssheet = it->get(); if (predicate.Check(*ssheet)) { @@ -173,8 +169,7 @@ IndexedStyleSheets::GetNthStyleSheetThatMatchesPredicate( return retval; } -unsigned -IndexedStyleSheets::FindStyleSheetPosition(const SfxStyleSheetBase& style) const +sal_Int32 IndexedStyleSheets::FindStyleSheetPosition(const SfxStyleSheetBase& style) const { VectorType::const_iterator it = std::find(mStyleSheets.begin(), mStyleSheets.end(), &style); if (it == mStyleSheets.end()) { @@ -210,9 +205,9 @@ IndexedStyleSheets::HasStyleSheet(const rtl::Reference< SfxStyleSheetBase >& sty } SfxStyleSheetBase* -IndexedStyleSheets::GetStyleSheetByPosition(unsigned pos) +IndexedStyleSheets::GetStyleSheetByPosition(sal_Int32 pos) { - if( pos < mStyleSheets.size() ) + if( pos < static_cast<sal_Int32>(mStyleSheets.size()) ) return mStyleSheets.at(pos).get(); return nullptr; } @@ -225,10 +220,10 @@ IndexedStyleSheets::ApplyToAllStyleSheets(StyleSheetCallback& callback) const } } -std::vector<unsigned> +std::vector<sal_Int32> IndexedStyleSheets::FindPositionsByPredicate(StyleSheetPredicate& predicate) const { - std::vector<unsigned> r; + std::vector<sal_Int32> r; for (VectorType::const_iterator it = mStyleSheets.begin(); it != mStyleSheets.end(); ++it) { if (predicate.Check(**it)) { r.push_back(std::distance(mStyleSheets.begin(), it)); @@ -237,7 +232,7 @@ IndexedStyleSheets::FindPositionsByPredicate(StyleSheetPredicate& predicate) con return r; } -const std::vector<unsigned>& +const std::vector<sal_Int32>& IndexedStyleSheets::GetStyleSheetPositionsByFamily(SfxStyleFamily e) const { size_t position = family_to_index(e); diff --git a/svl/source/items/style.cxx b/svl/source/items/style.cxx index e6606c82bdfa..8ef014755874 100644 --- a/svl/source/items/style.cxx +++ b/svl/source/items/style.cxx @@ -408,9 +408,9 @@ SfxStyleSheetIterator::~SfxStyleSheetIterator() { } -sal_uInt16 SfxStyleSheetIterator::Count() +sal_Int32 SfxStyleSheetIterator::Count() { - sal_uInt16 n = 0; + sal_Int32 n = 0; if( IsTrivialSearch()) { n = static_cast<sal_uInt16>(pBasePool->pImpl->mxIndexedStyleSheets->GetNumberOfStyleSheets()); @@ -427,7 +427,7 @@ sal_uInt16 SfxStyleSheetIterator::Count() return n; } -SfxStyleSheetBase* SfxStyleSheetIterator::operator[](sal_uInt16 nIdx) +SfxStyleSheetBase* SfxStyleSheetIterator::operator[](sal_Int32 nIdx) { SfxStyleSheetBase* retval = nullptr; if( IsTrivialSearch()) @@ -480,8 +480,8 @@ SfxStyleSheetBase* SfxStyleSheetIterator::Next() if ( IsTrivialSearch() ) { - unsigned nStyleSheets = pBasePool->pImpl->mxIndexedStyleSheets->GetNumberOfStyleSheets(); - unsigned newPosition = nCurrentPosition +1; + sal_Int32 nStyleSheets = pBasePool->pImpl->mxIndexedStyleSheets->GetNumberOfStyleSheets(); + sal_Int32 newPosition = nCurrentPosition + 1; if (nStyleSheets > newPosition) { nCurrentPosition = newPosition; @@ -490,13 +490,14 @@ SfxStyleSheetBase* SfxStyleSheetIterator::Next() } else if(nMask == SfxStyleSearchBits::All) { - unsigned newPosition = nCurrentPosition +1; - const std::vector<unsigned>& familyVector = + sal_Int32 newPosition = nCurrentPosition + 1; + const std::vector<sal_Int32>& familyVector + = pBasePool->pImpl->mxIndexedStyleSheets->GetStyleSheetPositionsByFamily(nSearchFamily); - if (familyVector.size() > newPosition) + if (static_cast<sal_Int32>(familyVector.size()) > newPosition) { nCurrentPosition = newPosition; - unsigned stylePosition = familyVector[newPosition]; + sal_Int32 stylePosition = familyVector[newPosition]; retval = pBasePool->pImpl->mxIndexedStyleSheets->GetStyleSheetByPosition(stylePosition); } } @@ -519,14 +520,14 @@ SfxStyleSheetBase* SfxStyleSheetIterator::Find(const OUString& rStr) { DoesStyleMatchStyleSheetPredicate predicate(this); - std::vector<unsigned> positions = + std::vector<sal_Int32> positions = pBasePool->pImpl->mxIndexedStyleSheets->FindPositionsByNameAndPredicate(rStr, predicate, svl::IndexedStyleSheets::SearchBehavior::ReturnFirst); if (positions.empty()) { return nullptr; } - unsigned pos = positions.front(); + sal_Int32 pos = positions.front(); SfxStyleSheetBase* pStyle = pBasePool->pImpl->mxIndexedStyleSheets->GetStyleSheetByPosition(pos); nCurrentPosition = pos; pCurrentStyle = pStyle; |