[Libreoffice-commits] libcdr.git: src/lib
Miklos Vajna
vmiklos at collabora.co.uk
Tue Aug 22 07:29:56 UTC 2017
src/lib/CDRContentCollector.cpp | 26 ++++++++++-------------
src/lib/CDRDocument.cpp | 8 +++----
src/lib/CDROutputElementList.cpp | 16 +++++++-------
src/lib/CDRParser.cpp | 6 ++---
src/lib/CDRPath.cpp | 44 ++++++++++++++++++---------------------
src/lib/CDRTransforms.cpp | 8 +++----
6 files changed, 52 insertions(+), 56 deletions(-)
New commits:
commit ecb7b0ee27c32bb00945f43ca840fdd63cfc3dc0
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Aug 22 09:29:33 2017 +0200
Convert explicit for loops to range-based ones where possible
Saves a few lines of redundant code.
Change-Id: I303893ace619703dc23e50e20eb44b0247b61b28
diff --git a/src/lib/CDRContentCollector.cpp b/src/lib/CDRContentCollector.cpp
index 0843fc1..b2b08cd 100644
--- a/src/lib/CDRContentCollector.cpp
+++ b/src/lib/CDRContentCollector.cpp
@@ -471,9 +471,9 @@ void libcdr::CDRContentCollector::_flushCurrentPath()
textFrameProps.insert("fo:padding-left", 0.0);
textFrameProps.insert("fo:padding-right", 0.0);
outputElement.addStartTextObject(textFrameProps);
- for (unsigned i = 0; i < m_currentText->size(); ++i)
+ for (const auto &i : *m_currentText)
{
- const std::vector<CDRText> ¤tLine = (*m_currentText)[i].m_line;
+ const std::vector<CDRText> ¤tLine = i.m_line;
if (currentLine.empty())
continue;
librevenge::RVNGPropertyList paraProps;
@@ -506,19 +506,19 @@ void libcdr::CDRContentCollector::_flushCurrentPath()
break;
}
outputElement.addOpenParagraph(paraProps);
- for (unsigned j = 0; j < currentLine.size(); ++j)
+ for (const auto &j : currentLine)
{
- if (!currentLine[j].m_text.empty())
+ if (!j.m_text.empty())
{
librevenge::RVNGPropertyList spanProps;
- double fontSize = (double)cdr_round(144.0*currentLine[j].m_style.m_fontSize) / 2.0;
+ double fontSize = (double)cdr_round(144.0*j.m_style.m_fontSize) / 2.0;
spanProps.insert("fo:font-size", fontSize, librevenge::RVNG_POINT);
- if (currentLine[j].m_style.m_fontName.len())
- spanProps.insert("style:font-name", currentLine[j].m_style.m_fontName);
- if (currentLine[j].m_style.m_fillStyle.fillType != (unsigned short)-1)
- spanProps.insert("fo:color", m_ps.getRGBColorString(currentLine[j].m_style.m_fillStyle.color1));
+ if (j.m_style.m_fontName.len())
+ spanProps.insert("style:font-name", j.m_style.m_fontName);
+ if (j.m_style.m_fillStyle.fillType != (unsigned short)-1)
+ spanProps.insert("fo:color", m_ps.getRGBColorString(j.m_style.m_fillStyle.color1));
outputElement.addOpenSpan(spanProps);
- outputElement.addInsertText(currentLine[j].m_text);
+ outputElement.addInsertText(j.m_text);
outputElement.addCloseSpan();
}
}
@@ -759,9 +759,8 @@ void libcdr::CDRContentCollector::_fillProperties(librevenge::RVNGPropertyList &
angle -= 360.0;
propList.insert("draw:angle", (int)angle);
librevenge::RVNGPropertyListVector vec;
- for (unsigned i = 0; i < m_currentFillStyle.gradient.m_stops.size(); i++)
+ for (auto &gradStop : m_currentFillStyle.gradient.m_stops)
{
- libcdr::CDRGradientStop &gradStop = m_currentFillStyle.gradient.m_stops[i];
librevenge::RVNGPropertyList stopElement;
stopElement.insert("svg:offset", gradStop.m_offset, librevenge::RVNG_PERCENT);
stopElement.insert("svg:stop-color", m_ps.getRGBColorString(gradStop.m_color));
@@ -784,9 +783,8 @@ void libcdr::CDRContentCollector::_fillProperties(librevenge::RVNGPropertyList &
angle -= 360.0;
propList.insert("draw:angle", (int)angle);
librevenge::RVNGPropertyListVector vec;
- for (unsigned i = 0; i < m_currentFillStyle.gradient.m_stops.size(); i++)
+ for (auto &gradStop : m_currentFillStyle.gradient.m_stops)
{
- libcdr::CDRGradientStop &gradStop = m_currentFillStyle.gradient.m_stops[i];
librevenge::RVNGPropertyList stopElement;
stopElement.insert("svg:offset", gradStop.m_offset, librevenge::RVNG_PERCENT);
stopElement.insert("svg:stop-color", m_ps.getRGBColorString(gradStop.m_color));
diff --git a/src/lib/CDRDocument.cpp b/src/lib/CDRDocument.cpp
index b44c6a4..9f56b63 100644
--- a/src/lib/CDRDocument.cpp
+++ b/src/lib/CDRDocument.cpp
@@ -185,10 +185,10 @@ CDRAPI bool libcdr::CDRDocument::parse(librevenge::RVNGInputStream *input, libre
}
}
dataStreams.reserve(dataFiles.size());
- for (unsigned i=0; i<dataFiles.size(); i++)
+ for (const auto &dataFile : dataFiles)
{
std::string streamName("content/data/");
- streamName += dataFiles[i];
+ streamName += dataFile;
CDR_DEBUG_MSG(("Extracting stream: %s\n", streamName.c_str()));
tmpInput->seek(0, librevenge::RVNG_SEEK_SET);
dataStreams.push_back(tmpInput->getSubStreamByName(streamName.c_str()));
@@ -232,8 +232,8 @@ CDRAPI bool libcdr::CDRDocument::parse(librevenge::RVNGInputStream *input, libre
}
if (input != tmpInput)
delete input;
- for (std::vector<librevenge::RVNGInputStream *>::iterator iter = dataStreams.begin(); iter != dataStreams.end(); ++iter)
- delete *iter;
+ for (auto &dataStream : dataStreams)
+ delete dataStream;
return retVal;
}
diff --git a/src/lib/CDROutputElementList.cpp b/src/lib/CDROutputElementList.cpp
index b7c0cd6..c1de564 100644
--- a/src/lib/CDROutputElementList.cpp
+++ b/src/lib/CDROutputElementList.cpp
@@ -406,28 +406,28 @@ libcdr::CDROutputElementList::CDROutputElementList(const libcdr::CDROutputElemen
libcdr::CDROutputElementList &libcdr::CDROutputElementList::operator=(const libcdr::CDROutputElementList &elementList)
{
- for (std::vector<CDROutputElement *>::iterator iter = m_elements.begin(); iter != m_elements.end(); ++iter)
- delete *iter;
+ for (auto &element : m_elements)
+ delete element;
m_elements.clear();
- for (std::vector<CDROutputElement *>::const_iterator cstiter = elementList.m_elements.begin(); cstiter != elementList.m_elements.end(); ++cstiter)
- m_elements.push_back((*cstiter)->clone());
+ for (auto element : elementList.m_elements)
+ m_elements.push_back(element->clone());
return *this;
}
libcdr::CDROutputElementList::~CDROutputElementList()
{
- for (std::vector<CDROutputElement *>::iterator iter = m_elements.begin(); iter != m_elements.end(); ++iter)
- delete *iter;
+ for (auto &element : m_elements)
+ delete element;
m_elements.clear();
}
void libcdr::CDROutputElementList::draw(librevenge::RVNGDrawingInterface *painter) const
{
- for (std::vector<CDROutputElement *>::const_iterator iter = m_elements.begin(); iter != m_elements.end(); ++iter)
- (*iter)->draw(painter);
+ for (auto element : m_elements)
+ element->draw(painter);
}
void libcdr::CDROutputElementList::addStyle(const librevenge::RVNGPropertyList &propList)
diff --git a/src/lib/CDRParser.cpp b/src/lib/CDRParser.cpp
index ba14393..79271d3 100644
--- a/src/lib/CDRParser.cpp
+++ b/src/lib/CDRParser.cpp
@@ -206,9 +206,9 @@ bool libcdr::CDRParser::parseWaldo(librevenge::RVNGInputStream *input)
gatherWaldoInformation(input, records, records2, records3, records4, records6, records7, records8, recordsOther);
}
std::map<unsigned, WaldoRecordType1> records1;
- for (std::vector<WaldoRecordInfo>::iterator iterVec = records.begin(); iterVec != records.end(); ++iterVec)
+ for (auto &record : records)
{
- input->seek(iterVec->offset, librevenge::RVNG_SEEK_SET);
+ input->seek(record.offset, librevenge::RVNG_SEEK_SET);
unsigned length = readU32(input);
if (length != 0x18)
{
@@ -241,7 +241,7 @@ bool libcdr::CDRParser::parseWaldo(librevenge::RVNGInputStream *input)
double v5 = readFixedPoint(input) / 1000.0;
trafo = CDRTransform(v0, v1, v2, v3, v4, v5);
}
- records1[iterVec->id] = WaldoRecordType1(iterVec->id, next, previous, child, parent, flags, x0, y0, x1, y1, trafo);
+ records1[record.id] = WaldoRecordType1(record.id, next, previous, child, parent, flags, x0, y0, x1, y1, trafo);
}
std::map<unsigned, WaldoRecordInfo>::const_iterator iter;
for (iter = records3.begin(); iter != records3.end(); ++iter)
diff --git a/src/lib/CDRPath.cpp b/src/lib/CDRPath.cpp
index a0d500d..636544a 100644
--- a/src/lib/CDRPath.cpp
+++ b/src/lib/CDRPath.cpp
@@ -569,16 +569,14 @@ void libcdr::CDRSplineToElement::writeOut(librevenge::RVNGPropertyListVector &ve
void libcdr::CDRSplineToElement::transform(const CDRTransforms &trafos)
{
- for (std::vector<std::pair<double, double> >::iterator iter = m_points.begin();
- iter != m_points.end(); ++iter)
- trafos.applyToPoint(iter->first, iter->second);
+ for (auto &point : m_points)
+ trafos.applyToPoint(point.first, point.second);
}
void libcdr::CDRSplineToElement::transform(const CDRTransform &trafo)
{
- for (std::vector<std::pair<double, double> >::iterator iter = m_points.begin();
- iter != m_points.end(); ++iter)
- trafo.applyToPoint(iter->first, iter->second);
+ for (auto &point : m_points)
+ trafo.applyToPoint(point.first, point.second);
}
libcdr::CDRPathElement *libcdr::CDRSplineToElement::clone()
@@ -673,8 +671,8 @@ void libcdr::CDRPath::appendClosePath()
libcdr::CDRPath::CDRPath(const libcdr::CDRPath &path) : m_elements(), m_isClosed(false)
{
- for (std::vector<CDRPathElement *>::const_iterator iter = path.m_elements.begin(); iter != path.m_elements.end(); ++iter)
- m_elements.push_back((*iter)->clone());
+ for (auto element : path.m_elements)
+ m_elements.push_back(element->clone());
m_isClosed = path.isClosed();
}
@@ -684,8 +682,8 @@ libcdr::CDRPath &libcdr::CDRPath::operator=(const libcdr::CDRPath &path)
if (this == &path)
return *this;
clear();
- for (std::vector<CDRPathElement *>::const_iterator iter = path.m_elements.begin(); iter != path.m_elements.end(); ++iter)
- m_elements.push_back((*iter)->clone());
+ for (auto element : path.m_elements)
+ m_elements.push_back(element->clone());
m_isClosed = path.isClosed();
return *this;
}
@@ -698,26 +696,26 @@ libcdr::CDRPath::~CDRPath()
void libcdr::CDRPath::appendPath(const CDRPath &path)
{
- for (std::vector<CDRPathElement *>::const_iterator iter = path.m_elements.begin(); iter != path.m_elements.end(); ++iter)
- m_elements.push_back((*iter)->clone());
+ for (auto element : path.m_elements)
+ m_elements.push_back(element->clone());
}
void libcdr::CDRPath::writeOut(librevenge::RVNGPropertyListVector &vec) const
{
bool wasZ = true;
- for (std::vector<CDRPathElement *>::const_iterator iter = m_elements.begin(); iter != m_elements.end(); ++iter)
+ for (auto element : m_elements)
{
- if (dynamic_cast<CDRClosePathElement *>(*iter))
+ if (dynamic_cast<CDRClosePathElement *>(element))
{
if (!wasZ)
{
- (*iter)->writeOut(vec);
+ element->writeOut(vec);
wasZ = true;
}
}
else
{
- (*iter)->writeOut(vec);
+ element->writeOut(vec);
wasZ = false;
}
}
@@ -852,14 +850,14 @@ void libcdr::CDRPath::writeOut(librevenge::RVNGString &path, librevenge::RVNGStr
void libcdr::CDRPath::transform(const CDRTransforms &trafos)
{
- for (std::vector<CDRPathElement *>::iterator iter = m_elements.begin(); iter != m_elements.end(); ++iter)
- (*iter)->transform(trafos);
+ for (auto &element : m_elements)
+ element->transform(trafos);
}
void libcdr::CDRPath::transform(const CDRTransform &trafo)
{
- for (std::vector<CDRPathElement *>::iterator iter = m_elements.begin(); iter != m_elements.end(); ++iter)
- (*iter)->transform(trafo);
+ for (auto &element : m_elements)
+ element->transform(trafo);
}
libcdr::CDRPathElement *libcdr::CDRPath::clone()
@@ -869,9 +867,9 @@ libcdr::CDRPathElement *libcdr::CDRPath::clone()
void libcdr::CDRPath::clear()
{
- for (std::vector<CDRPathElement *>::iterator iter = m_elements.begin(); iter != m_elements.end(); ++iter)
- if (*iter)
- delete *iter;
+ for (auto &element : m_elements)
+ if (element)
+ delete element;
m_elements.clear();
m_isClosed = false;
}
diff --git a/src/lib/CDRTransforms.cpp b/src/lib/CDRTransforms.cpp
index 49f10b8..2d2c733 100644
--- a/src/lib/CDRTransforms.cpp
+++ b/src/lib/CDRTransforms.cpp
@@ -253,14 +253,14 @@ bool libcdr::CDRTransforms::empty() const
void libcdr::CDRTransforms::applyToPoint(double &x, double &y) const
{
- for (std::vector<CDRTransform>::const_iterator iter = m_trafos.begin(); iter != m_trafos.end(); ++iter)
- iter->applyToPoint(x,y);
+ for (const auto &trafo : m_trafos)
+ trafo.applyToPoint(x,y);
}
void libcdr::CDRTransforms::applyToArc(double &rx, double &ry, double &rotation, bool &sweep, double &x, double &y) const
{
- for (std::vector<CDRTransform>::const_iterator iter = m_trafos.begin(); iter != m_trafos.end(); ++iter)
- iter->applyToArc(rx, ry, rotation, sweep, x, y);
+ for (const auto &trafo : m_trafos)
+ trafo.applyToArc(rx, ry, rotation, sweep, x, y);
}
double libcdr::CDRTransforms::_getScaleX() const
More information about the Libreoffice-commits
mailing list