handle duplicate object names

This commit is contained in:
Ramen2X 2024-03-15 13:14:42 -04:00
parent 0aacb74ca3
commit 4ef5b7e066
2 changed files with 30 additions and 0 deletions

View file

@ -12,6 +12,7 @@ public:
private:
void AddActionsToMap(si::Core *p_object);
void ProcessDuplicates();
si::Interleaf m_inlf;
size_t m_actionCount;
std::map<size_t, std::string> *m_actionMap;

View file

@ -1,5 +1,7 @@
#include "interleafhandler.h"
typedef std::map<size_t, std::string> 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;
}
}
}