From 4ef5b7e066ba47a67d8637d57b3925cba9679639 Mon Sep 17 00:00:00 2001 From: Ramen2X Date: Fri, 15 Mar 2024 13:14:42 -0400 Subject: [PATCH] handle duplicate object names --- include/interleafhandler.h | 1 + src/interleafhandler.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/interleafhandler.h b/include/interleafhandler.h index f0bbd47..3ca8397 100644 --- a/include/interleafhandler.h +++ b/include/interleafhandler.h @@ -12,6 +12,7 @@ public: private: void AddActionsToMap(si::Core *p_object); + void ProcessDuplicates(); si::Interleaf m_inlf; size_t m_actionCount; std::map *m_actionMap; diff --git a/src/interleafhandler.cpp b/src/interleafhandler.cpp index 86c50bd..bf87a60 100644 --- a/src/interleafhandler.cpp +++ b/src/interleafhandler.cpp @@ -1,5 +1,7 @@ #include "interleafhandler.h" +typedef std::map ActionMap; + si::Interleaf::Error InterleafHandler::ReadInterleaf(char *p_filePath) { // this is basically a wrapper function for libweaver's @@ -25,6 +27,9 @@ bool InterleafHandler::StartActionSorting() AddActionsToMap(m_inlf.GetChildAt(i)); } + // process duplicates in the map + ProcessDuplicates(); + // success return true; } @@ -55,3 +60,27 @@ void InterleafHandler::AddActionsToMap(si::Core *p_object) } } +void InterleafHandler::ProcessDuplicates() +{ + // some Interleaf files can have duplicate object names, + // which is obviously bad in the context of an enum + // where every label is expected to be unique + + ActionMap::iterator it = m_actionMap->begin(); + std::string prevName = it->second; + + for (++it; it != m_actionMap->end(); it++) { + if (it->second == prevName) { + // found a dupe, append the object ID to its name + it->second += "_" + std::to_string(it->first); + // retroactively append the object ID to the original as well + ActionMap::iterator prevIt = it; + --prevIt; + prevIt->second += "_" + std::to_string(prevIt->first); + } + else { + prevName = it->second; + } + } +} +