Toponaming move makEFace as makeElementFace and dependencies

This commit is contained in:
Zheng, Lei
2024-01-17 20:38:50 -05:00
committed by bgbsww
parent af76942a0b
commit e425b5b2db
8 changed files with 543 additions and 22 deletions

View File

@@ -247,6 +247,10 @@ public:
}
// NOTE: getElementHistory is now in ElementMap
long getElementHistory(const MappedName & name,
MappedName *original=nullptr, std::vector<MappedName> *history=nullptr) const {
return _elementMap->getElementHistory(name, Tag, original, history);
};
void setMappedChildElements(const std::vector<Data::ElementMap::MappedChildElements> & children);
std::vector<Data::ElementMap::MappedChildElements> getMappedChildElements() const;

View File

@@ -20,5 +20,114 @@
* *
**************************************************************************************************/
// NOLINTNEXTLINE
#include "PreCompiled.h"
#ifndef _PreComp_
# include <cstdlib>
# include <unordered_set>
#endif
#include "MappedElement.h"
using namespace Data;
bool ElementNameComp::operator()(const MappedName &a, const MappedName &b) const {
size_t size = std::min(a.size(),b.size());
if(!size)
return a.size()<b.size();
size_t i=0;
if(b[0] == '#') {
if(a[0]!='#')
return true;
// If both string starts with '#', compare the following hex digits by
// its integer value.
int res = 0;
for(i=1;i<size;++i) {
unsigned char ac = (unsigned char)a[i];
unsigned char bc = (unsigned char)b[i];
if(std::isxdigit(bc)) {
if(!std::isxdigit(ac))
return true;
if(res==0) {
if(ac<bc)
res = -1;
else if(ac>bc)
res = 1;
}
}else if(std::isxdigit(ac))
return false;
else
break;
}
if(res < 0)
return true;
else if(res > 0)
return false;
for (; i<size; ++i) {
char ac = a[i];
char bc = b[i];
if (ac < bc)
return true;
if (ac > bc)
return false;
}
return a.size()<b.size();
}
else if (a[0] == '#')
return false;
// If the string does not start with '#', compare the non-digits prefix
// using lexical order.
for(i=0;i<size;++i) {
unsigned char ac = (unsigned char)a[i];
unsigned char bc = (unsigned char)b[i];
if(!std::isdigit(bc)) {
if(std::isdigit(ac))
return true;
if(ac<bc)
return true;
if(ac>bc)
return false;
} else if(!std::isdigit(ac)) {
return false;
} else
break;
}
// Then compare the following digits part by integer value
int res = 0;
for(;i<size;++i) {
unsigned char ac = (unsigned char)a[i];
unsigned char bc = (unsigned char)b[i];
if(std::isdigit(bc)) {
if(!std::isdigit(ac))
return true;
if(res==0) {
if(ac<bc)
res = -1;
else if(ac>bc)
res = 1;
}
}else if(std::isdigit(ac))
return false;
else
break;
}
if(res < 0)
return true;
else if(res > 0)
return false;
// Finally, compare the remaining tail using lexical order
for (; i<size; ++i) {
char ac = a[i];
char bc = b[i];
if (ac < bc)
return true;
if (ac > bc)
return false;
}
return a.size()<b.size();
}

View File

@@ -26,6 +26,7 @@
#include "IndexedName.h"
#include "MappedName.h"
namespace App
{
class DocumentObject;
@@ -98,6 +99,22 @@ struct AppExport MappedElement
}
};
struct AppExport ElementNameComp {
/** Comparison function to make topo name more stable
*
* The sorting decompose the name into either of the following two forms
* '#' + hex_digits + tail
* non_digits + digits + tail
*
* The non-digits part is compared lexically, while the digits part is
* compared by its integer value.
*
* The reason for this is to prevent name with bigger digits (usually means
* comes late in history) comes early when sorting.
*/
bool operator()(const MappedName &a, const MappedName &b) const;
};
}// namespace Data