Skip to content

Commit

Permalink
Merge pull request #3862 from rism-digital/develop-range-loops
Browse files Browse the repository at this point in the history
Use range loops instead of iterator when possible
  • Loading branch information
lpugin authored Nov 21, 2024
2 parents f562935 + 411f28d commit d690a06
Show file tree
Hide file tree
Showing 16 changed files with 202 additions and 225 deletions.
5 changes: 2 additions & 3 deletions src/adjustdotsfunctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,13 @@ FunctorCode AdjustDotsFunctor::VisitMeasure(Measure *measure)
Filters filters;
Filters *previousFilters = this->SetFilters(&filters);

std::vector<int>::iterator iter;
for (iter = m_staffNs.begin(); iter != m_staffNs.end(); ++iter) {
for (int &n : m_staffNs) {
filters.Clear();
// Create ad comparison object for each type / @n
std::vector<int> ns;
// -1 for barline attributes that need to be taken into account each time
ns.push_back(BARLINE_REFERENCES);
ns.push_back(*iter);
ns.push_back(n);
AttNIntegerAnyComparison matchStaff(ALIGNMENT_REFERENCE, ns);
filters.Add(&matchStaff);

Expand Down
6 changes: 3 additions & 3 deletions src/adjustfloatingpositionerfunctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ FunctorCode AdjustFloatingPositionersFunctor::VisitStaffAlignment(StaffAlignment
}

// Find all the overflowing elements from the staff that overlap horizontally
for (auto i = overflowBoxes.begin(); i != overflowBoxes.end(); ++i) {
if (positioner->HasHorizontalOverlapWith(*i, drawingUnit)) {
for (BoundingBox *bbox : overflowBoxes) {
if (positioner->HasHorizontalOverlapWith(bbox, drawingUnit)) {
// update the yRel accordingly
positioner->CalcDrawingYRel(m_doc, staffAlignment, *i);
positioner->CalcDrawingYRel(m_doc, staffAlignment, bbox);
}
}

Expand Down
11 changes: 5 additions & 6 deletions src/adjustgracexposfunctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ FunctorCode AdjustGraceXPosFunctor::VisitAlignment(Alignment *alignment)
Filters filters;
Filters *previousFilters = this->SetFilters(&filters);

std::vector<int>::iterator iter;
for (iter = m_staffNs.begin(); iter != m_staffNs.end(); ++iter) {
const int graceAlignerId = m_doc->GetOptions()->m_graceRhythmAlign.GetValue() ? 0 : *iter;
for (int &n : m_staffNs) {
const int graceAlignerId = m_doc->GetOptions()->m_graceRhythmAlign.GetValue() ? 0 : n;

std::vector<ClassId> exclude;
if (alignment->HasGraceAligner(graceAlignerId) && m_rightDefaultAlignment) {
Expand All @@ -74,7 +73,7 @@ FunctorCode AdjustGraceXPosFunctor::VisitAlignment(Alignment *alignment)
// Get its minimum left and make it the max right position of the grace group
if (m_rightDefaultAlignment) {
int minLeft, maxRight;
m_rightDefaultAlignment->GetLeftRight(*iter, minLeft, maxRight, exclude);
m_rightDefaultAlignment->GetLeftRight(n, minLeft, maxRight, exclude);
if (minLeft != -VRV_UNSET)
graceMaxPos = minLeft - m_doc->GetLeftMargin(NOTE) * m_doc->GetDrawingUnit(75);
}
Expand All @@ -94,7 +93,7 @@ FunctorCode AdjustGraceXPosFunctor::VisitAlignment(Alignment *alignment)
m_graceCumulatedXShift = VRV_UNSET;
filters.Clear();
// Create ad comparison object for each type / @n
AttNIntegerComparison matchStaff(ALIGNMENT_REFERENCE, (*iter));
AttNIntegerComparison matchStaff(ALIGNMENT_REFERENCE, n);
filters.Add(&matchStaff);

if (alignment->HasGraceAligner(graceAlignerId)) {
Expand All @@ -105,7 +104,7 @@ FunctorCode AdjustGraceXPosFunctor::VisitAlignment(Alignment *alignment)
if (m_graceCumulatedXShift == VRV_UNSET) continue;

// Now we need to adjust the space for the grace note group
measureAligner->AdjustGraceNoteSpacing(m_doc, alignment, (*iter));
measureAligner->AdjustGraceNoteSpacing(m_doc, alignment, n);
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/adjustlayersfunctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,13 @@ FunctorCode AdjustLayersFunctor::VisitMeasure(Measure *measure)
Filters filters;
Filters *previousFilters = this->SetFilters(&filters);

std::vector<int>::iterator iter;
for (iter = m_staffNs.begin(); iter != m_staffNs.end(); ++iter) {
for (int &n : m_staffNs) {
filters.Clear();
// Create ad comparison object for each type / @n
std::vector<int> ns;
// -1 for barline attributes that need to be taken into account each time
ns.push_back(BARLINE_REFERENCES);
ns.push_back(*iter);
ns.push_back(n);
AttNIntegerAnyComparison matchStaff(ALIGNMENT_REFERENCE, ns);
filters.Add(&matchStaff);

Expand Down
11 changes: 5 additions & 6 deletions src/beam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,21 +336,20 @@ std::pair<int, int> BeamSegment::GetMinimalStemLength(const BeamDrawingInterface
const auto isNoteOrChord
= [](BeamElementCoord *coord) { return (coord->m_element && coord->m_element->Is({ CHORD, NOTE })); };

using CoordIt = ArrayOfBeamElementCoords::const_iterator;
for (CoordIt it = m_beamElementCoordRefs.begin(); it != m_beamElementCoordRefs.end(); ++it) {
if (!isNoteOrChord(*it)) continue;
for (BeamElementCoord *coord : m_beamElementCoordRefs) {
if (!isNoteOrChord(coord)) continue;

// Get the stem direction
const StemmedDrawingInterface *stemmedInterface = (*it)->GetStemHolderInterface();
const StemmedDrawingInterface *stemmedInterface = coord->GetStemHolderInterface();
if (!stemmedInterface) continue;
const Stem *stem = stemmedInterface->GetDrawingStem();
const bool isStemUp = (stem->GetDrawingStemDir() == STEMDIRECTION_up);

if (isStemUp) {
currentLength = (*it)->m_yBeam - bottomOffset - (*it)->m_closestNote->GetDrawingY();
currentLength = coord->m_yBeam - bottomOffset - coord->m_closestNote->GetDrawingY();
}
else {
currentLength = (*it)->m_closestNote->GetDrawingY() - (*it)->m_yBeam - topOffset;
currentLength = coord->m_closestNote->GetDrawingY() - coord->m_yBeam - topOffset;
}

// Update the min length
Expand Down
5 changes: 2 additions & 3 deletions src/calcalignmentxposfunctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ FunctorCode CalcAlignmentXPosFunctor::VisitAlignment(Alignment *alignment)
// LogDebug("CalcAlignmentXPos: intervalTime=%.2f intervalXRel=%d", intervalTime, intervalXRel);
}

MapOfIntGraceAligners::const_iterator iter;
const MapOfIntGraceAligners &graceAligners = alignment->GetGraceAligners();
for (iter = graceAligners.begin(); iter != graceAligners.end(); ++iter) {
iter->second->SetGraceAlignmentXPos(m_doc);
for (const auto &[key, value] : graceAligners) {
value->SetGraceAlignmentXPos(m_doc);
}

alignment->SetXRel(m_previousXRel + intervalXRel * DEFINITION_FACTOR * m_estimatedJustificationRatio);
Expand Down
66 changes: 28 additions & 38 deletions src/doc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,17 +437,14 @@ void Doc::ExportMIDI(smf::MidiFile *midiFile)
// For this, we use a array of AttNIntegerComparison that looks for each object if it is of the type
// and with @n specified

IntTree_t::const_iterator staves;
IntTree_t::const_iterator layers;

// Process notes and chords, rests, spaces layer by layer
// track 0 (included by default) is reserved for meta messages common to all tracks
int midiChannel = 0;
int midiTrack = 1;
Filters filters;
for (staves = layerTree.child.begin(); staves != layerTree.child.end(); ++staves) {
for (auto &staves : layerTree.child) {
int transSemi = 0;
if (StaffDef *staffDef = scoreDef->GetStaffDef(staves->first)) {
if (StaffDef *staffDef = scoreDef->GetStaffDef(staves.first)) {
// get the transposition (semi-tone) value for the staff
if (staffDef->HasTransSemi()) transSemi = staffDef->GetTransSemi();
midiTrack = staffDef->GetN();
Expand Down Expand Up @@ -514,11 +511,11 @@ void Doc::ExportMIDI(smf::MidiFile *midiFile)
generateScoreDefMIDI.SetTrack(midiTrack);
scoreDef->Process(generateScoreDefMIDI);

for (layers = staves->second.child.begin(); layers != staves->second.child.end(); ++layers) {
for (auto &layers : staves.second.child) {
filters.Clear();
// Create ad comparison object for each type / @n
AttNIntegerComparison matchStaff(STAFF, staves->first);
AttNIntegerComparison matchLayer(LAYER, layers->first);
AttNIntegerComparison matchStaff(STAFF, staves.first);
AttNIntegerComparison matchLayer(LAYER, layers.first);
filters.Add(&matchStaff);
filters.Add(&matchLayer);

Expand All @@ -527,7 +524,7 @@ void Doc::ExportMIDI(smf::MidiFile *midiFile)

generateMIDI.SetChannel(midiChannel);
generateMIDI.SetTrack(midiTrack);
generateMIDI.SetStaffN(staves->first);
generateMIDI.SetStaffN(staves.first);
generateMIDI.SetTempoEventTicks(tempoEventTicks);
generateMIDI.SetTransSemi(transSemi);
generateMIDI.SetCurrentTempo(tempo);
Expand Down Expand Up @@ -740,19 +737,15 @@ void Doc::PrepareData()
// For this, we use an array of AttNIntegerComparison that looks for each object if it is of the type
// and with @n specified

IntTree_t::const_iterator staves;
IntTree_t::const_iterator layers;
IntTree_t::const_iterator verses;

/************ Resolve some pointers by layer ************/

Filters filters;
for (staves = layerTree.child.begin(); staves != layerTree.child.end(); ++staves) {
for (layers = staves->second.child.begin(); layers != staves->second.child.end(); ++layers) {
for (auto &staves : layerTree.child) {
for (auto &layers : staves.second.child) {
filters.Clear();
// Create ad comparison object for each type / @n
AttNIntegerComparison matchStaff(STAFF, staves->first);
AttNIntegerComparison matchLayer(LAYER, layers->first);
AttNIntegerComparison matchStaff(STAFF, staves.first);
AttNIntegerComparison matchLayer(LAYER, layers.first);
filters.Add(&matchStaff);
filters.Add(&matchLayer);

Expand All @@ -769,12 +762,12 @@ void Doc::PrepareData()
prepareDelayedTurns.SetDataCollectionCompleted();

if (!prepareDelayedTurns.GetDelayedTurns().empty()) {
for (staves = layerTree.child.begin(); staves != layerTree.child.end(); ++staves) {
for (layers = staves->second.child.begin(); layers != staves->second.child.end(); ++layers) {
for (auto &staves : layerTree.child) {
for (auto &layers : staves.second.child) {
filters.Clear();
// Create ad comparison object for each type / @n
AttNIntegerComparison matchStaff(STAFF, staves->first);
AttNIntegerComparison matchLayer(LAYER, layers->first);
AttNIntegerComparison matchStaff(STAFF, staves.first);
AttNIntegerComparison matchLayer(LAYER, layers.first);
filters.Add(&matchStaff);
filters.Add(&matchLayer);

Expand All @@ -788,15 +781,15 @@ void Doc::PrepareData()
/************ Resolve lyric connectors ************/

// Same for the lyrics, but Verse by Verse since Syl are TimeSpanningInterface elements for handling connectors
for (staves = verseTree.child.begin(); staves != verseTree.child.end(); ++staves) {
for (layers = staves->second.child.begin(); layers != staves->second.child.end(); ++layers) {
for (verses = layers->second.child.begin(); verses != layers->second.child.end(); ++verses) {
for (auto &staves : verseTree.child) {
for (auto &layers : staves.second.child) {
for (auto &verses : layers.second.child) {
// std::cout << staves->first << " => " << layers->first << " => " << verses->first << '\n';
filters.Clear();
// Create ad comparison object for each type / @n
AttNIntegerComparison matchStaff(STAFF, staves->first);
AttNIntegerComparison matchLayer(LAYER, layers->first);
AttNIntegerComparison matchVerse(VERSE, verses->first);
AttNIntegerComparison matchStaff(STAFF, staves.first);
AttNIntegerComparison matchLayer(LAYER, layers.first);
AttNIntegerComparison matchVerse(VERSE, verses.first);
filters.Add(&matchStaff);
filters.Add(&matchLayer);
filters.Add(&matchVerse);
Expand Down Expand Up @@ -827,12 +820,12 @@ void Doc::PrepareData()
/************ Resolve mRpt ************/

// Process by staff for matching mRpt elements and setting the drawing number
for (staves = layerTree.child.begin(); staves != layerTree.child.end(); ++staves) {
for (layers = staves->second.child.begin(); layers != staves->second.child.end(); ++layers) {
for (auto &staves : layerTree.child) {
for (auto &layers : staves.second.child) {
filters.Clear();
// Create ad comparison object for each type / @n
AttNIntegerComparison matchStaff(STAFF, staves->first);
AttNIntegerComparison matchLayer(LAYER, layers->first);
AttNIntegerComparison matchStaff(STAFF, staves.first);
AttNIntegerComparison matchLayer(LAYER, layers.first);
filters.Add(&matchStaff);
filters.Add(&matchLayer);

Expand Down Expand Up @@ -1362,20 +1355,17 @@ void Doc::ConvertMarkupDoc(bool permanent)
this->Process(initProcessingLists);
const IntTree &layerTree = initProcessingLists.GetLayerTree();

IntTree_t::const_iterator staves;
IntTree_t::const_iterator layers;

/************ Resolve ties ************/

// Process by layer for matching @tie attribute - we process notes and chords, looking at
// GetTie values and pitch and oct for matching notes
Filters filters;
for (staves = layerTree.child.begin(); staves != layerTree.child.end(); ++staves) {
for (layers = staves->second.child.begin(); layers != staves->second.child.end(); ++layers) {
for (auto &staves : layerTree.child) {
for (auto &layers : staves.second.child) {
filters.Clear();
// Create ad comparison object for each type / @n
AttNIntegerComparison matchStaff(STAFF, staves->first);
AttNIntegerComparison matchLayer(LAYER, layers->first);
AttNIntegerComparison matchStaff(STAFF, staves.first);
AttNIntegerComparison matchLayer(LAYER, layers.first);
filters.Add(&matchStaff);
filters.Add(&matchLayer);

Expand Down
Loading

0 comments on commit d690a06

Please sign in to comment.