summaryrefslogtreecommitdiff
path: root/svl/source/items/IndexedStyleSheets.cxx
diff options
context:
space:
mode:
authorArkadiy Illarionov <qarkai@gmail.com>2018-11-24 23:39:59 +0300
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-11-25 12:29:05 +0100
commit260002b16f18634a7e1d10d4160378beb0cc0c5f (patch)
tree2528cb63cafa6c8e52ef1537802a737990db3445 /svl/source/items/IndexedStyleSheets.cxx
parent159b30d92f7a17f1d77417a2ed1836ea72699a0e (diff)
Simplify containers iterations in svgio, svl, svtools
Use range-based loop or replace with STL functions Change-Id: I98a3e55a14c8ac00188c5003f84194c2cc6795fb Reviewed-on: https://gerrit.libreoffice.org/63959 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svl/source/items/IndexedStyleSheets.cxx')
-rw-r--r--svl/source/items/IndexedStyleSheets.cxx54
1 files changed, 19 insertions, 35 deletions
diff --git a/svl/source/items/IndexedStyleSheets.cxx b/svl/source/items/IndexedStyleSheets.cxx
index 28a36587c4c8..6b28873a05ba 100644
--- a/svl/source/items/IndexedStyleSheets.cxx
+++ b/svl/source/items/IndexedStyleSheets.cxx
@@ -71,9 +71,8 @@ IndexedStyleSheets::Reindex()
}
unsigned i = 0;
- for (VectorType::const_iterator it = mStyleSheets.begin();
- it != mStyleSheets.end(); ++it) {
- SfxStyleSheetBase* p = it->get();
+ for (const auto& rxStyleSheet : mStyleSheets) {
+ SfxStyleSheetBase* p = rxStyleSheet.get();
Register(*p, i);
++i;
}
@@ -100,22 +99,15 @@ IndexedStyleSheets::RemoveStyleSheet(const rtl::Reference< SfxStyleSheetBase >&
{
OUString styleName = style->GetName();
std::vector<unsigned> positions = FindPositionsByName(styleName);
- bool found = false;
- unsigned stylePosition = 0;
- for (std::vector<unsigned>::const_iterator it = positions.begin();
- it != positions.end(); ++it) {
- if (mStyleSheets.at(*it) == style) {
- found = true;
- stylePosition = *it;
- break;
- }
- }
+ auto it = std::find_if(positions.begin(), positions.end(),
+ [&](const unsigned pos) { return mStyleSheets.at(pos) == style; });
- if (found) {
- mStyleSheets.erase(mStyleSheets.begin() + stylePosition);
+ if (it != positions.end()) {
+ mStyleSheets.erase(mStyleSheets.begin() + *it);
Reindex();
+ return true;
}
- return found;
+ return false;
}
std::vector<unsigned>
@@ -152,14 +144,11 @@ IndexedStyleSheets::FindPositionsByNameAndPredicate(const OUString& name,
unsigned
IndexedStyleSheets::GetNumberOfStyleSheetsWithPredicate(StyleSheetPredicate& predicate) const
{
- unsigned r = 0;
- for (VectorType::const_iterator it = mStyleSheets.begin(); it != mStyleSheets.end(); ++it) {
- const SfxStyleSheetBase *ssheet = it->get();
- if (predicate.Check(*ssheet)) {
- ++r;
- }
- }
- return r;
+ return std::count_if(mStyleSheets.begin(), mStyleSheets.end(),
+ [&predicate](const rtl::Reference<SfxStyleSheetBase>& rxStyleSheet) {
+ const SfxStyleSheetBase *ssheet = rxStyleSheet.get();
+ return predicate.Check(*ssheet);
+ });
}
SfxStyleSheetBase*
@@ -196,8 +185,8 @@ IndexedStyleSheets::FindStyleSheetPosition(const SfxStyleSheetBase& style) const
void
IndexedStyleSheets::Clear(StyleSheetDisposer& disposer)
{
- for (VectorType::iterator it = mStyleSheets.begin(); it != mStyleSheets.end(); ++it) {
- disposer.Dispose(*it);
+ for (auto& rxStyleSheet : mStyleSheets) {
+ disposer.Dispose(rxStyleSheet);
}
mStyleSheets.clear();
mPositionsByName.clear();
@@ -212,13 +201,8 @@ IndexedStyleSheets::HasStyleSheet(const rtl::Reference< SfxStyleSheetBase >& sty
{
OUString styleName = style->GetName();
std::vector<unsigned> positions = FindPositionsByName(styleName);
- for (std::vector<unsigned>::const_iterator it = positions.begin();
- it != positions.end(); ++it) {
- if (mStyleSheets.at(*it) == style) {
- return true;
- }
- }
- return false;
+ return std::any_of(positions.begin(), positions.end(),
+ [&](const unsigned pos) { return mStyleSheets.at(pos) == style; });
}
SfxStyleSheetBase*
@@ -232,8 +216,8 @@ IndexedStyleSheets::GetStyleSheetByPosition(unsigned pos)
void
IndexedStyleSheets::ApplyToAllStyleSheets(StyleSheetCallback& callback) const
{
- for (VectorType::const_iterator it = mStyleSheets.begin(); it != mStyleSheets.end(); ++it) {
- callback.DoIt(**it);
+ for (const auto& rxStyleSheet : mStyleSheets) {
+ callback.DoIt(*rxStyleSheet);
}
}