From 11185dad44210e953515c378778655a72dbb1ae5 Mon Sep 17 00:00:00 2001 From: Laurent Pugin Date: Thu, 14 Nov 2024 16:42:35 +0100 Subject: [PATCH 1/5] Simplify code using range loops --- src/adjustdotsfunctor.cpp | 5 +-- src/adjustgracexposfunctor.cpp | 11 +++--- src/adjustlayersfunctor.cpp | 5 +-- src/beam.cpp | 11 +++--- src/calcalignmentxposfunctor.cpp | 5 +-- src/doc.cpp | 66 ++++++++++++++------------------ 6 files changed, 44 insertions(+), 59 deletions(-) diff --git a/src/adjustdotsfunctor.cpp b/src/adjustdotsfunctor.cpp index 1f930da9a88..e5238ca3451 100644 --- a/src/adjustdotsfunctor.cpp +++ b/src/adjustdotsfunctor.cpp @@ -104,14 +104,13 @@ FunctorCode AdjustDotsFunctor::VisitMeasure(Measure *measure) Filters filters; Filters *previousFilters = this->SetFilters(&filters); - std::vector::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 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); diff --git a/src/adjustgracexposfunctor.cpp b/src/adjustgracexposfunctor.cpp index 85e4876cbb5..1dd2f509ea1 100644 --- a/src/adjustgracexposfunctor.cpp +++ b/src/adjustgracexposfunctor.cpp @@ -53,9 +53,8 @@ FunctorCode AdjustGraceXPosFunctor::VisitAlignment(Alignment *alignment) Filters filters; Filters *previousFilters = this->SetFilters(&filters); - std::vector::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 exclude; if (alignment->HasGraceAligner(graceAlignerId) && m_rightDefaultAlignment) { @@ -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); } @@ -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)) { @@ -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); } } diff --git a/src/adjustlayersfunctor.cpp b/src/adjustlayersfunctor.cpp index 058120c970c..e18049dbe04 100644 --- a/src/adjustlayersfunctor.cpp +++ b/src/adjustlayersfunctor.cpp @@ -127,14 +127,13 @@ FunctorCode AdjustLayersFunctor::VisitMeasure(Measure *measure) Filters filters; Filters *previousFilters = this->SetFilters(&filters); - std::vector::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 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); diff --git a/src/beam.cpp b/src/beam.cpp index f779239884d..2cefcb2e3b3 100644 --- a/src/beam.cpp +++ b/src/beam.cpp @@ -336,21 +336,20 @@ std::pair 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 diff --git a/src/calcalignmentxposfunctor.cpp b/src/calcalignmentxposfunctor.cpp index 38e992e3741..63eac3eec62 100644 --- a/src/calcalignmentxposfunctor.cpp +++ b/src/calcalignmentxposfunctor.cpp @@ -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); diff --git a/src/doc.cpp b/src/doc.cpp index f5664d709ef..e829d336cac 100644 --- a/src/doc.cpp +++ b/src/doc.cpp @@ -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(); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); From 5bfd04b73bdc1dc629cc7e6efffdc945679db667 Mon Sep 17 00:00:00 2001 From: Laurent Pugin Date: Mon, 18 Nov 2024 09:32:41 +0100 Subject: [PATCH 2/5] Additional simplifications to C++ range loops * No change expected --- src/iomusxml.cpp | 91 ++++++++++++++++++++--------------------- src/object.cpp | 13 +++--- src/options.cpp | 10 ++--- src/plistinterface.cpp | 5 +-- src/toolkit.cpp | 7 ++-- src/verticalaligner.cpp | 5 +-- 6 files changed, 62 insertions(+), 69 deletions(-) diff --git a/src/iomusxml.cpp b/src/iomusxml.cpp index babf405ac75..a4420bfd6ab 100644 --- a/src/iomusxml.cpp +++ b/src/iomusxml.cpp @@ -1130,16 +1130,15 @@ bool MusicXmlInput::ReadMusicXml(pugi::xml_node root) section->ReplaceChild(measureList.front(), ending); // go through measureList of that ending and remove remaining measures from
and add them to // - std::vector::iterator jter; - for (jter = measureList.begin(); jter != measureList.end(); ++jter) { - logString = logString + (*jter)->GetID().c_str(); + for (Measure *measure : measureList) { + logString = logString + measure->GetID().c_str(); // remove other measures from
that are not already removed above (first measure) - if ((*jter)->GetID() != measureList.front()->GetID()) { - int idx = section->GetChildIndex(*jter); + if (measure->GetID() != measureList.front()->GetID()) { + int idx = section->GetChildIndex(measure); section->DetachChild(idx); } - ending->AddChild(*jter); // add to - logString = logString + ((*jter == measureList.back()) ? ")." : ", "); + ending->AddChild(measure); // add to + logString = logString + ((measure == measureList.back()) ? ")." : ", "); } LogDebug(logString.c_str()); } @@ -1299,18 +1298,18 @@ short int MusicXmlInput::ReadMusicXmlPartAttributesAsStaffDef( m_instrdef = NULL; } - for (pugi::xml_node::iterator it = node.begin(); it != node.end(); ++it) { + for (pugi::xml_node child : node) { // We read all attribute elements until we reach something else // barline, direction, print, and sound elements may be present - if (!IsElement(*it, "attributes") && !IsElement(*it, "barline") && !IsElement(*it, "direction") - && !IsElement(*it, "print") && !IsElement(*it, "sound")) { + if (!IsElement(child, "attributes") && !IsElement(child, "barline") && !IsElement(child, "direction") + && !IsElement(child, "print") && !IsElement(child, "sound")) { break; } // we do not want to read it again, just change the name - if (IsElement(*it, "attributes")) { - it->set_name("mei-read"); + if (IsElement(child, "attributes")) { + child.set_name("mei-read"); } else { continue; @@ -1341,10 +1340,10 @@ short int MusicXmlInput::ReadMusicXmlPartAttributesAsStaffDef( // clef sign - first look if we have a clef-sign with the corresponding staff @number std::string xpath = StringFormat("clef[@number='%d']", i + 1); - pugi::xpath_node clef = it->select_node(xpath.c_str()); + pugi::xpath_node clef = child.select_node(xpath.c_str()); // if not, look at a common one if (!clef) { - clef = it->select_node("clef[not(@number)]"); + clef = child.select_node("clef[not(@number)]"); if (nbStaves > 1) clef.node().remove_attribute("id"); } Clef *meiClef = ConvertClef(clef.node()); @@ -1356,9 +1355,9 @@ short int MusicXmlInput::ReadMusicXmlPartAttributesAsStaffDef( // key sig xpath = StringFormat("key[@number='%d']", i + 1); - pugi::xpath_node key = it->select_node(xpath.c_str()); + pugi::xpath_node key = child.select_node(xpath.c_str()); if (!key) { - key = it->select_node("key[not(@number)]"); + key = child.select_node("key[not(@number)]"); if (nbStaves > 1) key.node().remove_attribute("id"); } if (key) { @@ -1370,9 +1369,9 @@ short int MusicXmlInput::ReadMusicXmlPartAttributesAsStaffDef( // staff details pugi::xpath_node staffDetails; xpath = StringFormat("staff-details[@number='%d']", i + 1); - staffDetails = it->select_node(xpath.c_str()); + staffDetails = child.select_node(xpath.c_str()); if (!staffDetails) { - staffDetails = it->select_node("staff-details[not(@number)]"); + staffDetails = child.select_node("staff-details[not(@number)]"); } short int staffLines = staffDetails.node().select_node("staff-lines").node().text().as_int(); if (staffLines) { @@ -1453,9 +1452,9 @@ short int MusicXmlInput::ReadMusicXmlPartAttributesAsStaffDef( // time pugi::xpath_node time; xpath = StringFormat("time[@number='%d']", i + 1); - time = it->select_node(xpath.c_str()); + time = child.select_node(xpath.c_str()); if (!time) { - time = it->select_node("time[not(@number)]"); + time = child.select_node("time[not(@number)]"); if (nbStaves > 1) time.node().remove_attribute("id"); } if (time) { @@ -1466,9 +1465,9 @@ short int MusicXmlInput::ReadMusicXmlPartAttributesAsStaffDef( // transpose pugi::xpath_node transpose; xpath = StringFormat("transpose[@number='%d']", i + 1); - transpose = it->select_node(xpath.c_str()); + transpose = child.select_node(xpath.c_str()); if (!transpose) { - transpose = it->select_node("transpose"); + transpose = child.select_node("transpose"); } if (transpose) { staffDef->SetTransDiat(transpose.node().child("diatonic").text().as_int()); @@ -1481,13 +1480,13 @@ short int MusicXmlInput::ReadMusicXmlPartAttributesAsStaffDef( } } // ppq - pugi::xpath_node divisions = it->select_node("divisions"); + pugi::xpath_node divisions = child.select_node("divisions"); if (divisions) { m_ppq = divisions.node().text().as_int(); staffDef->SetPpq(m_ppq); } // measure style - pugi::xpath_node measureSlash = it->select_node("measure-style/slash"); + pugi::xpath_node measureSlash = child.select_node("measure-style/slash"); if (measureSlash) { m_slash = (HasAttributeWithValue(measureSlash.node(), "type", "start")) ? true : false; } @@ -1655,10 +1654,10 @@ bool MusicXmlInput::ReadMusicXmlMeasure( int multiRestStaffNumber = 1; // read the content of the measure - for (pugi::xml_node::iterator it = node.begin(); it != node.end(); ++it) { + for (pugi::xml_node child : node) { // first check if there is a multi measure rest - if (it->select_node(".//multiple-rest")) { - const pugi::xml_node multiRestNode = it->select_node(".//multiple-rest").node(); + if (child.select_node(".//multiple-rest")) { + const pugi::xml_node multiRestNode = child.select_node(".//multiple-rest").node(); const int multiRestLength = multiRestNode.text().as_int(); const std::string symbols = multiRestNode.attribute("use-symbols").as_string(); MultiRest *multiRest = new MultiRest; @@ -1676,7 +1675,7 @@ bool MusicXmlInput::ReadMusicXmlMeasure( break; } else if (isMRestInOtherSystem) { - if ((multiRestStaffNumber > 1) && !IsElement(*it, "backup")) continue; + if ((multiRestStaffNumber > 1) && !IsElement(child, "backup")) continue; MultiRest *multiRest = new MultiRest; multiRest->SetNum(mrestPositonIter->second - mrestPositonIter->first + 1); Layer *layer = SelectLayer(multiRestStaffNumber, measure); @@ -1684,33 +1683,33 @@ bool MusicXmlInput::ReadMusicXmlMeasure( if (multiRestStaffNumber < nbStaves) multiRestStaffNumber++; continue; } - if (IsElement(*it, "attributes")) { - ReadMusicXmlAttributes(*it, section, measure, measureNum); + if (IsElement(child, "attributes")) { + ReadMusicXmlAttributes(child, section, measure, measureNum); } - else if (IsElement(*it, "backup")) { - ReadMusicXmlBackup(*it, measure, measureNum); + else if (IsElement(child, "backup")) { + ReadMusicXmlBackup(child, measure, measureNum); } - else if (IsElement(*it, "barline")) { - ReadMusicXmlBarLine(*it, measure, measureNum); + else if (IsElement(child, "barline")) { + ReadMusicXmlBarLine(child, measure, measureNum); } - else if (IsElement(*it, "direction")) { - ReadMusicXmlDirection(*it, measure, measureNum, staffOffset); + else if (IsElement(child, "direction")) { + ReadMusicXmlDirection(child, measure, measureNum, staffOffset); } - else if (IsElement(*it, "figured-bass")) { - ReadMusicXmlFigures(*it, measure, measureNum); + else if (IsElement(child, "figured-bass")) { + ReadMusicXmlFigures(child, measure, measureNum); } - else if (IsElement(*it, "forward")) { - ReadMusicXmlForward(*it, measure, measureNum); + else if (IsElement(child, "forward")) { + ReadMusicXmlForward(child, measure, measureNum); } - else if (IsElement(*it, "harmony")) { - ReadMusicXmlHarmony(*it, measure, measureNum); + else if (IsElement(child, "harmony")) { + ReadMusicXmlHarmony(child, measure, measureNum); } - else if (IsElement(*it, "note")) { - ReadMusicXmlNote(*it, measure, measureNum, staffOffset, section); + else if (IsElement(child, "note")) { + ReadMusicXmlNote(child, measure, measureNum, staffOffset, section); } // for now only check first part - else if (IsElement(*it, "print") && node.select_node("parent::part[not(preceding-sibling::part)]")) { - ReadMusicXmlPrint(*it, section); + else if (IsElement(child, "print") && node.select_node("parent::part[not(preceding-sibling::part)]")) { + ReadMusicXmlPrint(child, section); } } diff --git a/src/object.cpp b/src/object.cpp index b2b3c175b96..d2cabed1835 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -366,12 +366,11 @@ void Object::ClearChildren() return; } - ArrayOfObjects::iterator iter; - for (iter = m_children.begin(); iter != m_children.end(); ++iter) { + for (Object *child : m_children) { // we need to check if this is the parent // ownership might have been given up with Relinquish - if ((*iter)->GetParent() == this) { - delete *iter; + if (child->GetParent() == this) { + delete child; } } m_children.clear(); @@ -1051,10 +1050,10 @@ void Object::Process(Functor &functor, int deepness, bool skipFirst) } } else { - for (ArrayOfObjects::iterator iter = children->begin(); iter != children->end(); ++iter) { + for (Object *child : m_children) { // we will end here if there is no filter at all or for the current child type - if (this->FiltersApply(filters, *iter)) { - (*iter)->Process(functor, deepness); + if (this->FiltersApply(filters, child)) { + child->Process(functor, deepness); } } } diff --git a/src/options.cpp b/src/options.cpp index b978eac5fd9..5f03508288c 100644 --- a/src/options.cpp +++ b/src/options.cpp @@ -139,10 +139,9 @@ jsonxx::Object Option::ToJson() const else if (optArray) { opt << "type" << "array"; std::vector strValues = optArray->GetDefault(); - std::vector::iterator strIter; jsonxx::Array values; - for (strIter = strValues.begin(); strIter != strValues.end(); ++strIter) { - values << (*strIter); + for (const std::string &value : strValues) { + values << value; } opt << "default" << values; } @@ -150,10 +149,9 @@ jsonxx::Object Option::ToJson() const opt << "type" << "std::string-list"; opt << "default" << optIntMap->GetDefaultStrValue(); std::vector strValues = optIntMap->GetStrValues(false); - std::vector::iterator strIter; jsonxx::Array values; - for (strIter = strValues.begin(); strIter != strValues.end(); ++strIter) { - values << (*strIter); + for (const std::string &value : strValues) { + values << value; } opt << "values" << values; } diff --git a/src/plistinterface.cpp b/src/plistinterface.cpp index 157210045f2..2b6038ed2d3 100644 --- a/src/plistinterface.cpp +++ b/src/plistinterface.cpp @@ -104,9 +104,8 @@ FunctorCode PlistInterface::InterfacePreparePlist(PreparePlistFunctor &functor, this->SetIDStrs(); - std::vector::iterator iter; - for (iter = m_ids.begin(); iter != m_ids.end(); ++iter) { - functor.InsertInterfaceIDPair(*iter, this); + for (const std::string &id : m_ids) { + functor.InsertInterfaceIDPair(id, this); } return FUNCTOR_CONTINUE; diff --git a/src/toolkit.cpp b/src/toolkit.cpp index e9cfcc77356..8911ade8f58 100644 --- a/src/toolkit.cpp +++ b/src/toolkit.cpp @@ -1440,10 +1440,9 @@ std::string Toolkit::GetElementAttr(const std::string &xmlId) element->GetAttributes(&attributes); // Fill the JSON object - ArrayOfStrAttr::iterator iter; - for (iter = attributes.begin(); iter != attributes.end(); ++iter) { - o << (*iter).first << (*iter).second; - // LogInfo("Element %s - %s", (*iter).first.c_str(), (*iter).second.c_str()); + for (const auto &attribute : attributes) { + o << attribute.first << attribute.second; + // LogInfo("Element %s - %s", attribute.first.c_str(), attribute.second.c_str()); } return o.json(); } diff --git a/src/verticalaligner.cpp b/src/verticalaligner.cpp index 55fc027e876..2093b5d993a 100644 --- a/src/verticalaligner.cpp +++ b/src/verticalaligner.cpp @@ -336,9 +336,8 @@ StaffAlignment::~StaffAlignment() void StaffAlignment::ClearPositioners() { - ArrayOfFloatingPositioners::iterator iter; - for (iter = m_floatingPositioners.begin(); iter != m_floatingPositioners.end(); ++iter) { - delete *iter; + for (FloatingPositioner *positioner : m_floatingPositioners) { + delete positioner; } m_floatingPositioners.clear(); From ab29568d14c851b1ffed404857fd1faa43e29530 Mon Sep 17 00:00:00 2001 From: Laurent Pugin Date: Mon, 18 Nov 2024 10:58:23 +0100 Subject: [PATCH 3/5] Additional simplifications --- src/adjustfloatingpositionerfunctor.cpp | 6 +- src/ioabc.cpp | 83 ++++++++++++------------- src/iomusxml.cpp | 80 ++++++++++++------------ 3 files changed, 84 insertions(+), 85 deletions(-) diff --git a/src/adjustfloatingpositionerfunctor.cpp b/src/adjustfloatingpositionerfunctor.cpp index 205b7eb4466..969ee0fc864 100644 --- a/src/adjustfloatingpositionerfunctor.cpp +++ b/src/adjustfloatingpositionerfunctor.cpp @@ -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); } } diff --git a/src/ioabc.cpp b/src/ioabc.cpp index 029c9ef0495..48f958c5dfe 100644 --- a/src/ioabc.cpp +++ b/src/ioabc.cpp @@ -257,8 +257,8 @@ void ABCInput::AddLayerElement() // otherwise we can have beam or tuplet (for now) Beam *beam = new Beam(); // add stacked notes to the current element - for (auto iter = m_noteStack.begin(); iter != m_noteStack.end(); ++iter) { - beam->AddChild(*iter); + for (LayerElement *element : m_noteStack) { + beam->AddChild(element); } if (beam->FindDescendantByType(NOTE)) { LayerElement *element = NULL; @@ -376,11 +376,11 @@ void ABCInput::AddDynamic(LayerElement *element) { assert(element); - for (auto it = m_dynam.begin(); it != m_dynam.end(); ++it) { + for (const std::string &str : m_dynam) { Dynam *dynam = new Dynam(); dynam->SetStartid("#" + element->GetID()); Text *text = new Text(); - text->SetText(UTF8to32(*it)); + text->SetText(UTF8to32(str)); dynam->AddChild(text); m_controlElements.push_back(std::make_pair(m_layer->GetID(), dynam)); } @@ -833,26 +833,26 @@ void ABCInput::parseReferenceNumber(const std::string &referenceNumberString) void ABCInput::PrintInformationFields(Score *score) { PgHead *pgHead = new PgHead(); - for (auto it = m_title.begin(); it != m_title.end(); ++it) { + for (auto it : m_title) { Rend *titleRend = new Rend(); titleRend->SetHalign(HORIZONTALALIGNMENT_center); titleRend->SetValign(VERTICALALIGNMENT_middle); - if (it != m_title.begin()) { + if (it != m_title.front()) { data_FONTSIZE fontsize; fontsize.SetTerm(FONTSIZETERM_small); titleRend->SetFontsize(fontsize); } Text *text = new Text(); - text->SetText(UTF8to32(it->first)); + text->SetText(UTF8to32(it.first)); titleRend->AddChild(text); pgHead->AddChild(titleRend); } - for (auto it = m_composer.begin(); it != m_composer.end(); ++it) { + for (auto it : m_composer) { Rend *compRend = new Rend(); compRend->SetHalign(HORIZONTALALIGNMENT_right); compRend->SetValign(VERTICALALIGNMENT_bottom); Text *composer = new Text(); - composer->SetText(UTF8to32(it->first)); + composer->SetText(UTF8to32(it.first)); compRend->AddChild(composer); if (!m_origin.empty()) { Text *origin = new Text(); @@ -883,10 +883,10 @@ void ABCInput::CreateHeader() pugi::xml_node fileTitle = fileTitleStmt.append_child("title"); fileTitle.text().set(m_filename.c_str()); if (!m_composer.empty()) { - for (auto it = m_composer.begin(); it != m_composer.end(); ++it) { + for (auto it : m_composer) { pugi::xml_node composer = fileTitleStmt.append_child("composer"); - composer.text().set((it->first).c_str()); - composer.append_attribute("xml:id").set_value(StringFormat("abcLine%02d", it->second).c_str()); + composer.text().set((it.first).c_str()); + composer.append_attribute("xml:id").set_value(StringFormat("abcLine%02d", it.second).c_str()); composer.append_attribute("analog").set_value("abc:C"); } } @@ -897,10 +897,10 @@ void ABCInput::CreateHeader() // // if (!m_notes.empty()) { pugi::xml_node notes = fileDesc.append_child("notesStmt"); - for (auto it = m_notes.begin(); it != m_notes.end(); ++it) { + for (auto it : m_notes) { pugi::xml_node annot = notes.append_child("annot"); - annot.text().set((it->first).c_str()); - annot.append_attribute("xml:id").set_value(StringFormat("abcLine%02d", it->second).c_str()); + annot.text().set((it.first).c_str()); + annot.append_attribute("xml:id").set_value(StringFormat("abcLine%02d", it.second).c_str()); annot.append_attribute("analog").set_value("abc:N"); } } @@ -931,13 +931,12 @@ void ABCInput::CreateWorkEntry() pugi::xml_node work = m_workList.append_child("work"); work.append_attribute("n").set_value(m_mdiv->GetN().c_str()); work.append_attribute("data").set_value(StringFormat("#%s", m_mdiv->GetID().c_str()).c_str()); - for (auto it = m_title.begin(); it != m_title.end(); ++it) { + for (auto it : m_title) { pugi::xml_node title = work.append_child("title"); - title.text().set((it->first).c_str()); - if (it->second != 0) - title.append_attribute("xml:id").set_value(StringFormat("abcLine%02d", it->second).c_str()); + title.text().set((it.first).c_str()); + if (it.second != 0) title.append_attribute("xml:id").set_value(StringFormat("abcLine%02d", it.second).c_str()); title.append_attribute("analog").set_value("abc:T"); - if (it == m_title.begin()) { + if (it == m_title.front()) { title.append_attribute("type").set_value("main"); } else { @@ -945,29 +944,29 @@ void ABCInput::CreateWorkEntry() } } if (!m_composer.empty()) { - for (auto it = m_composer.begin(); it != m_composer.end(); ++it) { + for (auto it : m_composer) { pugi::xml_node composer = work.append_child("composer"); - composer.text().set((it->first).c_str()); - composer.append_attribute("xml:id").set_value(StringFormat("abcLine%02d", it->second).c_str()); + composer.text().set((it.first).c_str()); + composer.append_attribute("xml:id").set_value(StringFormat("abcLine%02d", it.second).c_str()); composer.append_attribute("analog").set_value("abc:C"); } } if (!m_history.empty()) { pugi::xml_node history = work.append_child("history"); history.append_attribute("analog").set_value("abc:H"); - for (auto it = m_history.begin(); it != m_history.end(); ++it) { + for (auto it : m_history) { pugi::xml_node histLine = history.append_child("p"); - histLine.text().set((it->first).c_str()); - histLine.append_attribute("xml:id").set_value(StringFormat("abcLine%02d", it->second).c_str()); + histLine.text().set((it.first).c_str()); + histLine.append_attribute("xml:id").set_value(StringFormat("abcLine%02d", it.second).c_str()); } } if (!m_info.empty()) { pugi::xml_node notes = work.append_child("notesStmt"); - for (auto it = m_info.begin(); it != m_info.end(); ++it) { + for (auto it : m_info) { pugi::xml_node annot = notes.append_child("annot"); - annot.text().set((it->first).first.c_str()); - annot.append_attribute("xml:id").set_value(StringFormat("abcLine%02d", it->first.second).c_str()); - annot.append_attribute("analog").set_value(StringFormat("abc:%c", it->second).c_str()); + annot.text().set((it.first).first.c_str()); + annot.append_attribute("xml:id").set_value(StringFormat("abcLine%02d", it.first.second).c_str()); + annot.append_attribute("analog").set_value(StringFormat("abc:%c", it.second).c_str()); } } } @@ -976,20 +975,20 @@ void ABCInput::FlushControlElements(Score *score, Section *section) { Layer *layer = NULL; Measure *measure = NULL; - for (auto iter = m_controlElements.begin(); iter != m_controlElements.end(); ++iter) { - if (!measure || (layer && layer->GetID() != iter->first)) { - layer = dynamic_cast(section->FindDescendantByID(iter->first)); + for (auto iter : m_controlElements) { + if (!measure || (layer && layer->GetID() != iter.first)) { + layer = dynamic_cast(section->FindDescendantByID(iter.first)); } if (!layer) { LogWarning("ABC import: Element '%s' could not be assigned to layer '%s'", - iter->second->GetClassName().c_str(), iter->first.c_str()); - delete iter->second; - iter->second = NULL; + iter.second->GetClassName().c_str(), iter.first.c_str()); + delete iter.second; + iter.second = NULL; continue; } measure = vrv_cast(layer->GetFirstAncestor(MEASURE)); assert(measure); - measure->AddChild(iter->second); + measure->AddChild(iter.second); } if (!section->GetParent()) { score->AddChild(section); @@ -1520,9 +1519,9 @@ void ABCInput::readMusicCode(const std::string &musicCode, Section *section) m_tieStack.back()->SetEndid("#" + m_ID); m_tieStack.clear(); } - for (auto it = m_slurStack.begin(); it != m_slurStack.end(); ++it) { - if (!((*it)->HasStartid())) { - (*it)->SetStartid("#" + m_ID); + for (Slur *slur : m_slurStack) { + if (!slur->HasStartid()) { + slur->SetStartid("#" + m_ID); } } } @@ -1726,8 +1725,8 @@ void ABCInput::readMusicCode(const std::string &musicCode, Section *section) section->AddChild(measure); m_layer = new Layer(); m_layer->SetN(1); - for (auto it = m_tempoStack.begin(); it != m_tempoStack.end(); ++it) { - measure->AddChild(*it); + for (ControlElement *tempo : m_tempoStack) { + measure->AddChild(tempo); } m_tempoStack.clear(); } diff --git a/src/iomusxml.cpp b/src/iomusxml.cpp index a4420bfd6ab..ec2c107ec9d 100644 --- a/src/iomusxml.cpp +++ b/src/iomusxml.cpp @@ -574,8 +574,8 @@ void MusicXmlInput::OpenTie(Note *note, Tie *tie, int layerNum) void MusicXmlInput::CloseTie(Note *note, int layerNum) { // add all notes with identical pitch/oct to m_tieStopStack - for (auto iter = m_tieStack.begin(); iter != m_tieStack.end(); ++iter) { - if (note->IsEnharmonicWith(iter->m_note)) { + for (const musicxml::OpenTie &tie : m_tieStack) { + if (note->IsEnharmonicWith(tie.m_note)) { m_tieStopStack.push_back(musicxml::CloseTie(note, layerNum)); } } @@ -1093,37 +1093,37 @@ bool MusicXmlInput::ReadMusicXml(pugi::xml_node root) ProcessClefChangeQueue(section); Measure *measure = NULL; - for (auto iter = m_controlElements.begin(); iter != m_controlElements.end(); ++iter) { - if (!measure || (measure->GetN() != iter->first)) { - AttNNumberLikeComparison comparisonMeasure(MEASURE, iter->first); + for (auto iter : m_controlElements) { + if (!measure || (measure->GetN() != iter.first)) { + AttNNumberLikeComparison comparisonMeasure(MEASURE, iter.first); measure = vrv_cast(section->FindDescendantByComparison(&comparisonMeasure, 1)); } if (!measure) { LogWarning("MusicXML import: Element '%s' could not be added to measure %s", - iter->second->GetClassName().c_str(), iter->first.c_str()); - delete iter->second; + iter.second->GetClassName().c_str(), iter.first.c_str()); + delete iter.second; continue; } - measure->AddChild(iter->second); + measure->AddChild(iter.second); } // manage endings stack: create new elements and move the corresponding measures into them if (!m_endingStack.empty()) { - for (auto iter = m_endingStack.begin(); iter != m_endingStack.end(); ++iter) { + for (auto iter : m_endingStack) { std::string logString = ""; - logString = logString + "MusicXML import: Ending number='" + iter->second.m_endingNumber.c_str() - + "', type='" + iter->second.m_endingType.c_str() + "', text='" + iter->second.m_endingText + "' ("; - std::vector measureList = iter->first; + logString = logString + "MusicXML import: Ending number='" + iter.second.m_endingNumber.c_str() + + "', type='" + iter.second.m_endingType.c_str() + "', text='" + iter.second.m_endingText + "' ("; + std::vector measureList = iter.first; Ending *ending = new Ending(); - if (iter->second.m_endingText + if (iter.second.m_endingText .empty()) { // some musicXML exporters tend to ignore the text, so take @number instead. - ending->SetN(iter->second.m_endingNumber); + ending->SetN(iter.second.m_endingNumber); } else { - ending->SetN(iter->second.m_endingText); + ending->SetN(iter.second.m_endingText); } ending->SetLendsym(LINESTARTENDSYMBOL_angledown); // default, does not need to be written - if (iter->second.m_endingType == "discontinue") { + if (iter.second.m_endingType == "discontinue") { ending->SetLendsym(LINESTARTENDSYMBOL_none); // no ending symbol } // replace first with element @@ -1158,29 +1158,29 @@ bool MusicXmlInput::ReadMusicXml(pugi::xml_node root) m_tieStack.clear(); } if (!m_slurStack.empty()) { // There are slurs left open - for (auto iter = m_slurStack.begin(); iter != m_slurStack.end(); ++iter) { - LogWarning("MusicXML import: slur %d from measure %s could not be ended", iter->second.m_number, - iter->second.m_measureNum.c_str()); + for (auto iter : m_slurStack) { + LogWarning("MusicXML import: slur %d from measure %s could not be ended", iter.second.m_number, + iter.second.m_measureNum.c_str()); } m_slurStack.clear(); } if (!m_slurStopStack.empty()) { // There are slurs ends without opening - for (auto iter = m_slurStopStack.begin(); iter != m_slurStopStack.end(); ++iter) { + for (auto iter : m_slurStopStack) { LogWarning("MusicXML import: slur ending for element '%s' could not be " "matched to a start element", - iter->first->GetID().c_str()); + iter.first->GetID().c_str()); } m_slurStopStack.clear(); } if (!m_glissStack.empty()) { - for (auto iter = m_glissStack.begin(); iter != m_glissStack.end(); ++iter) { - LogWarning("MusicXML import: gliss for '%s' could not be closed", (*iter)->GetID().c_str()); + for (Gliss *gliss : m_glissStack) { + LogWarning("MusicXML import: gliss for '%s' could not be closed", gliss->GetID().c_str()); } m_glissStack.clear(); } if (!m_trillStack.empty()) { // open trills without ending - for (auto iter = m_trillStack.begin(); iter != m_trillStack.end(); ++iter) { - LogWarning("MusicXML import: trill extender for '%s' could not be ended", iter->first->GetID().c_str()); + for (auto iter : m_trillStack) { + LogWarning("MusicXML import: trill extender for '%s' could not be ended", iter.first->GetID().c_str()); } m_trillStack.clear(); } @@ -1594,15 +1594,15 @@ bool MusicXmlInput::ReadMusicXmlPart(pugi::xml_node node, Section *section, shor // clean up part specific stacks if (!m_openDashesStack.empty()) { // open dashes without ending - for (auto iter = m_openDashesStack.begin(); iter != m_openDashesStack.end(); ++iter) { + for (auto iter : m_openDashesStack) { LogWarning( - "MusicXML import: dashes/extender lines for '%s' could not be closed", iter->first->GetID().c_str()); + "MusicXML import: dashes/extender lines for '%s' could not be closed", iter.first->GetID().c_str()); } m_openDashesStack.clear(); } if (!m_bracketStack.empty()) { // open brackets without ending - for (auto iter = m_bracketStack.begin(); iter != m_bracketStack.end(); ++iter) { - LogWarning("MusicXML import: bracketSpan for '%s' could not be closed", iter->first->GetID().c_str()); + for (auto iter : m_bracketStack) { + LogWarning("MusicXML import: bracketSpan for '%s' could not be closed", iter.first->GetID().c_str()); } m_bracketStack.clear(); } @@ -1723,7 +1723,7 @@ bool MusicXmlInput::ReadMusicXmlMeasure( m_hairpinStopStack.clear(); m_tieStopStack.clear(); - for (auto staff : measure->GetChildren()) { + for (Object *staff : measure->GetChildren()) { if (!staff->Is(STAFF)) { continue; } @@ -2556,7 +2556,7 @@ void MusicXmlInput::ReadMusicXmlFigures(pugi::xml_node node, Measure *measure, c Harm *harm = new Harm(); Fb *fb = new Fb(); - for (auto &fig : figures) { + for (F *fig : figures) { fb->AddChild(fig); } harm->AddChild(fb); @@ -3572,10 +3572,10 @@ void MusicXmlInput::ReadMusicXmlNote( const std::string direction = xmlArpeggiate.node().attribute("direction").as_string(); bool added = false; if (!m_ArpeggioStack.empty()) { // check existing arpeggios - for (auto iter = m_ArpeggioStack.begin(); iter != m_ArpeggioStack.end(); ++iter) { - if (iter->second.m_arpegN == arpegN && onset == iter->second.m_timeStamp) { + for (auto iter : m_ArpeggioStack) { + if (iter.second.m_arpegN == arpegN && onset == iter.second.m_timeStamp) { // don't add other chord notes, because the chord is already referenced. - if (!isChord) iter->first->GetPlistInterface()->AddRef("#" + element->GetID()); + if (!isChord) iter.first->GetPlistInterface()->AddRef("#" + element->GetID()); added = true; // so that no new Arpeg gets created below break; } @@ -3694,15 +3694,15 @@ void MusicXmlInput::ReadMusicXmlNote( m_pedalStack.clear(); } if (!m_bracketStack.empty()) { - for (auto iter = m_bracketStack.begin(); iter != m_bracketStack.end(); ++iter) { - if (!(iter->first)->HasStaff()) - iter->first->SetStaff(staff->AttNInteger::StrToXsdPositiveIntegerList(std::to_string(staff->GetN()))); + for (auto iter : m_bracketStack) { + if (!(iter.first)->HasStaff()) + iter.first->SetStaff(staff->AttNInteger::StrToXsdPositiveIntegerList(std::to_string(staff->GetN()))); } } if (!m_tempoStack.empty()) { - for (auto iter = m_tempoStack.begin(); iter != m_tempoStack.end(); ++iter) { - if (!(*iter)->HasStaff()) - (*iter)->SetStaff(staff->AttNInteger::StrToXsdPositiveIntegerList(std::to_string(staff->GetN()))); + for (Tempo *tempo : m_tempoStack) { + if (!tempo->HasStaff()) + tempo->SetStaff(staff->AttNInteger::StrToXsdPositiveIntegerList(std::to_string(staff->GetN()))); } m_tempoStack.clear(); } From b2db2dbd00e872be6aba8aefb19c87a7b290e6b9 Mon Sep 17 00:00:00 2001 From: Laurent Pugin Date: Mon, 18 Nov 2024 11:14:18 +0100 Subject: [PATCH 4/5] Use references --- src/ioabc.cpp | 22 +++++++++++----------- src/iomei.cpp | 4 ++-- src/iomusxml.cpp | 18 +++++++++--------- src/iopae.cpp | 2 +- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/ioabc.cpp b/src/ioabc.cpp index 48f958c5dfe..efd6a30fb63 100644 --- a/src/ioabc.cpp +++ b/src/ioabc.cpp @@ -275,8 +275,8 @@ void ABCInput::AddLayerElement() beam = NULL; } else { - for (auto iter = m_noteStack.begin(); iter != m_noteStack.end(); ++iter) { - m_layer->AddChild(*iter); + for (LayerElement *element : m_noteStack) { + m_layer->AddChild(element); } } // clean-up leftover data, if any @@ -833,7 +833,7 @@ void ABCInput::parseReferenceNumber(const std::string &referenceNumberString) void ABCInput::PrintInformationFields(Score *score) { PgHead *pgHead = new PgHead(); - for (auto it : m_title) { + for (const auto &it : m_title) { Rend *titleRend = new Rend(); titleRend->SetHalign(HORIZONTALALIGNMENT_center); titleRend->SetValign(VERTICALALIGNMENT_middle); @@ -847,7 +847,7 @@ void ABCInput::PrintInformationFields(Score *score) titleRend->AddChild(text); pgHead->AddChild(titleRend); } - for (auto it : m_composer) { + for (const auto &it : m_composer) { Rend *compRend = new Rend(); compRend->SetHalign(HORIZONTALALIGNMENT_right); compRend->SetValign(VERTICALALIGNMENT_bottom); @@ -883,7 +883,7 @@ void ABCInput::CreateHeader() pugi::xml_node fileTitle = fileTitleStmt.append_child("title"); fileTitle.text().set(m_filename.c_str()); if (!m_composer.empty()) { - for (auto it : m_composer) { + for (const auto &it : m_composer) { pugi::xml_node composer = fileTitleStmt.append_child("composer"); composer.text().set((it.first).c_str()); composer.append_attribute("xml:id").set_value(StringFormat("abcLine%02d", it.second).c_str()); @@ -897,7 +897,7 @@ void ABCInput::CreateHeader() // // if (!m_notes.empty()) { pugi::xml_node notes = fileDesc.append_child("notesStmt"); - for (auto it : m_notes) { + for (const auto &it : m_notes) { pugi::xml_node annot = notes.append_child("annot"); annot.text().set((it.first).c_str()); annot.append_attribute("xml:id").set_value(StringFormat("abcLine%02d", it.second).c_str()); @@ -931,7 +931,7 @@ void ABCInput::CreateWorkEntry() pugi::xml_node work = m_workList.append_child("work"); work.append_attribute("n").set_value(m_mdiv->GetN().c_str()); work.append_attribute("data").set_value(StringFormat("#%s", m_mdiv->GetID().c_str()).c_str()); - for (auto it : m_title) { + for (const auto &it : m_title) { pugi::xml_node title = work.append_child("title"); title.text().set((it.first).c_str()); if (it.second != 0) title.append_attribute("xml:id").set_value(StringFormat("abcLine%02d", it.second).c_str()); @@ -944,7 +944,7 @@ void ABCInput::CreateWorkEntry() } } if (!m_composer.empty()) { - for (auto it : m_composer) { + for (const auto &it : m_composer) { pugi::xml_node composer = work.append_child("composer"); composer.text().set((it.first).c_str()); composer.append_attribute("xml:id").set_value(StringFormat("abcLine%02d", it.second).c_str()); @@ -954,7 +954,7 @@ void ABCInput::CreateWorkEntry() if (!m_history.empty()) { pugi::xml_node history = work.append_child("history"); history.append_attribute("analog").set_value("abc:H"); - for (auto it : m_history) { + for (const auto &it : m_history) { pugi::xml_node histLine = history.append_child("p"); histLine.text().set((it.first).c_str()); histLine.append_attribute("xml:id").set_value(StringFormat("abcLine%02d", it.second).c_str()); @@ -962,7 +962,7 @@ void ABCInput::CreateWorkEntry() } if (!m_info.empty()) { pugi::xml_node notes = work.append_child("notesStmt"); - for (auto it : m_info) { + for (const auto &it : m_info) { pugi::xml_node annot = notes.append_child("annot"); annot.text().set((it.first).first.c_str()); annot.append_attribute("xml:id").set_value(StringFormat("abcLine%02d", it.first.second).c_str()); @@ -975,7 +975,7 @@ void ABCInput::FlushControlElements(Score *score, Section *section) { Layer *layer = NULL; Measure *measure = NULL; - for (auto iter : m_controlElements) { + for (auto &iter : m_controlElements) { if (!measure || (layer && layer->GetID() != iter.first)) { layer = dynamic_cast(section->FindDescendantByID(iter.first)); } diff --git a/src/iomei.cpp b/src/iomei.cpp index 3e5436e9441..dbdfe48d2ab 100644 --- a/src/iomei.cpp +++ b/src/iomei.cpp @@ -3180,7 +3180,7 @@ void MEIOutput::WriteTimeSpanningInterface(pugi::xml_node element, TimeSpanningI void MEIOutput::WriteUnsupportedAttr(pugi::xml_node element, Object *object) { - for (auto &pair : object->m_unsupported) { + for (const auto &pair : object->m_unsupported) { if (element.attribute(pair.first.c_str())) { LogDebug("Attribute '%s' for '%s' is not supported", pair.first.c_str(), object->GetClassName().c_str()); } @@ -4099,7 +4099,7 @@ bool MEIInput::ReadIncipits(pugi::xml_node root) int incipCount = 0; bool success = true; - for (auto &incipItem : incipSet) { + for (const auto &incipItem : incipSet) { if (!success) break; pugi::xml_node incip = incipItem.node(); pugi::xml_node incipCode = incip.child("incipCode"); diff --git a/src/iomusxml.cpp b/src/iomusxml.cpp index ec2c107ec9d..2ef83d1258d 100644 --- a/src/iomusxml.cpp +++ b/src/iomusxml.cpp @@ -280,11 +280,11 @@ void MusicXmlInput::InsertClefToLayer(Staff *staff, Layer *layer, Clef *clef, in // Since AddClef handles #sameas clef only for the future layers, we need to check any previous existing layers for // the same staff to see if we need to insert #sameas clef to them. ListOfObjects staffLayers = staff->FindAllDescendantsByType(LAYER, false); - for (const auto listLayer : staffLayers) { + for (const auto &listLayer : staffLayers) { Layer *otherLayer = vrv_cast(listLayer); if (m_layerTimes.find(otherLayer) == m_layerTimes.end()) continue; // Get first element for the same (or higher if same is not present) duration - const auto start = m_layerTimes.at(otherLayer).lower_bound(scoreOnset); + const auto &start = m_layerTimes.at(otherLayer).lower_bound(scoreOnset); // Add either clef or #sameas, depending on the layer we're adding to Clef *clefToAdd = NULL; if (listLayer == layer) { @@ -3572,7 +3572,7 @@ void MusicXmlInput::ReadMusicXmlNote( const std::string direction = xmlArpeggiate.node().attribute("direction").as_string(); bool added = false; if (!m_ArpeggioStack.empty()) { // check existing arpeggios - for (auto iter : m_ArpeggioStack) { + for (const auto &iter : m_ArpeggioStack) { if (iter.second.m_arpegN == arpegN && onset == iter.second.m_timeStamp) { // don't add other chord notes, because the chord is already referenced. if (!isChord) iter.first->GetPlistInterface()->AddRef("#" + element->GetID()); @@ -3657,7 +3657,7 @@ void MusicXmlInput::ReadMusicXmlNote( // add StartIDs to dir, dynam, and pedal if (!m_dirStack.empty()) { - for (auto &dir : m_dirStack) { + for (Dir *dir : m_dirStack) { if (!dir->HasStaff()) { dir->SetStaff(staff->AttNInteger::StrToXsdPositiveIntegerList(std::to_string(staff->GetN()))); } @@ -3665,7 +3665,7 @@ void MusicXmlInput::ReadMusicXmlNote( m_dirStack.clear(); } if (!m_dynamStack.empty()) { - for (auto &dynam : m_dynamStack) { + for (Dynam *dynam : m_dynamStack) { if (!dynam->HasStaff()) { dynam->SetStaff(staff->AttNInteger::StrToXsdPositiveIntegerList(std::to_string(staff->GetN()))); } @@ -3673,20 +3673,20 @@ void MusicXmlInput::ReadMusicXmlNote( m_dynamStack.clear(); } if (!m_harmStack.empty()) { - for (auto &harm : m_harmStack) { + for (Harm *harm : m_harmStack) { harm->SetStaff(staff->AttNInteger::StrToXsdPositiveIntegerList(std::to_string(staff->GetN()))); } m_harmStack.clear(); } if (!m_octaveStack.empty()) { - for (auto &oct : m_octaveStack) { + for (Octave *oct : m_octaveStack) { oct->SetStaff(staff->AttNInteger::StrToXsdPositiveIntegerList(std::to_string(staff->GetN()))); oct->SetStartid(m_ID); } m_octaveStack.clear(); } if (!m_pedalStack.empty()) { - for (auto &ped : m_pedalStack) { + for (Pedal *ped : m_pedalStack) { if (!ped->HasStaff()) { ped->SetStaff(staff->AttNInteger::StrToXsdPositiveIntegerList(std::to_string(staff->GetN()))); } @@ -3694,7 +3694,7 @@ void MusicXmlInput::ReadMusicXmlNote( m_pedalStack.clear(); } if (!m_bracketStack.empty()) { - for (auto iter : m_bracketStack) { + for (const auto &iter : m_bracketStack) { if (!(iter.first)->HasStaff()) iter.first->SetStaff(staff->AttNInteger::StrToXsdPositiveIntegerList(std::to_string(staff->GetN()))); } diff --git a/src/iopae.cpp b/src/iopae.cpp index 29bd597c393..0110464722d 100644 --- a/src/iopae.cpp +++ b/src/iopae.cpp @@ -4755,7 +4755,7 @@ bool PAEInput::CheckContentPostBuild() ClassIdsComparison noteOrRest({ NOTE, REST }); ListOfObjects containers; m_doc->FindAllDescendantsByComparison(&containers, &comparison); - for (auto &container : containers) { + for (const auto &container : containers) { ListOfObjects notesOrRests; container->FindAllDescendantsByComparison(¬esOrRests, ¬eOrRest); if ((int)notesOrRests.size() < 1) { From 411f28d53a0ad74d8154200ba423981db99e9100 Mon Sep 17 00:00:00 2001 From: Laurent Pugin Date: Mon, 18 Nov 2024 11:53:10 +0100 Subject: [PATCH 5/5] Use reference --- src/doc.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc.cpp b/src/doc.cpp index e829d336cac..22ccb41b889 100644 --- a/src/doc.cpp +++ b/src/doc.cpp @@ -763,7 +763,7 @@ void Doc::PrepareData() if (!prepareDelayedTurns.GetDelayedTurns().empty()) { for (auto &staves : layerTree.child) { - for (auto layers : staves.second.child) { + for (auto &layers : staves.second.child) { filters.Clear(); // Create ad comparison object for each type / @n AttNIntegerComparison matchStaff(STAFF, staves.first);