Skip to content

Commit

Permalink
Merge pull request rism-digital#3929 from brdvd/refactor/find-referen…
Browse files Browse the repository at this point in the history
…ced-objects

Use set for referenced objects
  • Loading branch information
lpugin authored Jan 31, 2025
2 parents 25a12df + 39df4c4 commit 24f6169
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
6 changes: 3 additions & 3 deletions include/vrv/findfunctor.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ class FindAllReferencedObjectsFunctor : public Functor {
* @name Constructors, destructors
*/
///@{
FindAllReferencedObjectsFunctor(ListOfObjects *elements);
FindAllReferencedObjectsFunctor(SetOfObjects *elements);
virtual ~FindAllReferencedObjectsFunctor() = default;
///@}

Expand Down Expand Up @@ -437,8 +437,8 @@ class FindAllReferencedObjectsFunctor : public Functor {
public:
//
private:
// The array of all matching objects
ListOfObjects *m_elements;
// The set of all matching objects
SetOfObjects *m_elements;
// A flag indicating if milestone references should be included as well
bool m_milestoneReferences;
};
Expand Down
2 changes: 1 addition & 1 deletion include/vrv/iomei.h
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ class MEIOutput : public Output {

bool m_ignoreHeader;
bool m_removeIds;
ListOfObjects m_referredObjects;
SetOfObjects m_referredObjects;
};

//----------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions include/vrv/vrvdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,10 @@ typedef std::list<Object *> ListOfObjects;

typedef std::list<const Object *> ListOfConstObjects;

typedef std::set<Object *> SetOfObjects;

typedef std::set<const Object *> SetOfConstObjects;

typedef std::vector<Note *> ChordNoteGroup;

typedef std::vector<std::tuple<Alignment *, Alignment *, int>> ArrayOfAdjustmentTuples;
Expand Down
23 changes: 13 additions & 10 deletions src/findfunctor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ FunctorCode FindExtremeByComparisonFunctor::VisitObject(const Object *object)
// FindAllReferencedObjectsFunctor
//----------------------------------------------------------------------------

FindAllReferencedObjectsFunctor::FindAllReferencedObjectsFunctor(ListOfObjects *elements) : Functor()
FindAllReferencedObjectsFunctor::FindAllReferencedObjectsFunctor(SetOfObjects *elements) : Functor()
{
m_elements = elements;
m_milestoneReferences = false;
Expand All @@ -265,43 +265,46 @@ FunctorCode FindAllReferencedObjectsFunctor::VisitObject(Object *object)
if (object->HasInterface(INTERFACE_ALT_SYM)) {
AltSymInterface *interface = object->GetAltSymInterface();
assert(interface);
if (interface->GetAltSymbolDef()) m_elements->push_back(interface->GetAltSymbolDef());
if (interface->GetAltSymbolDef()) m_elements->insert(interface->GetAltSymbolDef());
}
if (object->HasInterface(INTERFACE_LINKING)) {
LinkingInterface *interface = object->GetLinkingInterface();
assert(interface);
if (interface->GetNextLink()) m_elements->push_back(interface->GetNextLink());
if (interface->GetSameasLink()) m_elements->push_back(interface->GetSameasLink());
if (interface->GetNextLink()) m_elements->insert(interface->GetNextLink());
if (interface->GetSameasLink()) m_elements->insert(interface->GetSameasLink());
}
if (object->HasInterface(INTERFACE_PLIST)) {
PlistInterface *interface = object->GetPlistInterface();
assert(interface);
for (Object *object : interface->GetRefs()) {
m_elements->push_back(object);
m_elements->insert(object);
}
}
if (object->HasInterface(INTERFACE_TIME_POINT) || object->HasInterface(INTERFACE_TIME_SPANNING)) {
TimePointInterface *interface = object->GetTimePointInterface();
assert(interface);
if (interface->GetStart() && !interface->GetStart()->Is(TIMESTAMP_ATTR))
m_elements->push_back(interface->GetStart());
if (interface->GetStart() && !interface->GetStart()->Is(TIMESTAMP_ATTR)) {
m_elements->insert(interface->GetStart());
}
}
if (object->HasInterface(INTERFACE_TIME_SPANNING)) {
TimeSpanningInterface *interface = object->GetTimeSpanningInterface();
assert(interface);
if (interface->GetEnd() && !interface->GetEnd()->Is(TIMESTAMP_ATTR)) m_elements->push_back(interface->GetEnd());
if (interface->GetEnd() && !interface->GetEnd()->Is(TIMESTAMP_ATTR)) {
m_elements->insert(interface->GetEnd());
}
}
if (object->Is(NOTE)) {
Note *note = vrv_cast<Note *>(object);
assert(note);
// The note has a stem.sameas that was resolved the a note, then that one is referenced
if (note->HasStemSameas() && note->HasStemSameasNote()) {
m_elements->push_back(note->GetStemSameasNote());
m_elements->insert(note->GetStemSameasNote());
}
}
// These will also be referred to as milestones in page-based MEI
if (m_milestoneReferences && object->IsMilestoneElement()) {
m_elements->push_back(object);
m_elements->insert(object);
}

// continue until the end
Expand Down
7 changes: 2 additions & 5 deletions src/iomei.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ bool MEIOutput::Export()
// When saving page-based MEI we also want to keep IDs for milestone elements
findAllReferencedObjects.IncludeMilestoneReferences(this->IsPageBasedMEI());
m_doc->Process(findAllReferencedObjects);
m_referredObjects.unique();
}

try {
Expand Down Expand Up @@ -1459,10 +1458,8 @@ std::string MEIOutput::IDToMeiStr(Object *element)

void MEIOutput::WriteXmlId(pugi::xml_node currentNode, Object *object)
{
if (m_removeIds) {
ListOfObjects::iterator it = std::find(m_referredObjects.begin(), m_referredObjects.end(), object);
if (it == m_referredObjects.end()) return;
m_referredObjects.erase(it);
if (m_removeIds && !m_referredObjects.contains(object)) {
return;
}
currentNode.append_attribute("xml:id") = IDToMeiStr(object).c_str();
}
Expand Down

0 comments on commit 24f6169

Please sign in to comment.