[Toponaming] create ElementMap class (#9175)
* Copypaste ElementMap * Add MappedNameRef * Fix missing include * Copypaste `findTagInElementName` * fix error introduced _somewhere_ * refactor toponaming constants * Move `findTagInElementName` in `MappedName` * reintroduce workaround to compile ElementMap * Added missing functions copied from complexgeodata * fix last compile errors, reorder and format files * remove recursive refs to ComplexGeoData * Add more comments * fixed comments and added tests * added FIXME, make functions private, misc fixes * Move static functions from complexGeoData to PostfixStringReferences. Rename to ElementNamingUtils * Fix broken includes due to previous change * Revert constants from string to const char* * added childmap tests and made hasher public * Make functions private * Added remaining tests * removed bool return from `erase` functions * fix missing appexport Co-authored-by: John Dupuy <jdupuy98@gmail.com>
This commit is contained in:
@@ -27,10 +27,10 @@
|
||||
# include <cstdlib>
|
||||
#endif
|
||||
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
#include "ComplexGeoData.h"
|
||||
|
||||
#include <Base/BoundBox.h>
|
||||
#include <Base/Placement.h>
|
||||
#include <Base/Rotation.h>
|
||||
@@ -166,102 +166,3 @@ bool ComplexGeoData::getCenterOfGravity(Base::Vector3d&) const
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::string &ComplexGeoData::elementMapPrefix() {
|
||||
static std::string prefix(";");
|
||||
return prefix;
|
||||
}
|
||||
|
||||
const char *ComplexGeoData::isMappedElement(const char *name) {
|
||||
if(name && boost::starts_with(name,elementMapPrefix()))
|
||||
return name+elementMapPrefix().size();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::string ComplexGeoData::newElementName(const char *name) {
|
||||
if(!name)
|
||||
return std::string();
|
||||
const char *dot = strrchr(name,'.');
|
||||
if(!dot || dot==name)
|
||||
return name;
|
||||
const char *c = dot-1;
|
||||
for(;c!=name;--c) {
|
||||
if(*c == '.') {
|
||||
++c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(isMappedElement(c))
|
||||
return std::string(name,dot-name);
|
||||
return name;
|
||||
}
|
||||
|
||||
std::string ComplexGeoData::oldElementName(const char *name) {
|
||||
if(!name)
|
||||
return std::string();
|
||||
const char *dot = strrchr(name,'.');
|
||||
if(!dot || dot==name)
|
||||
return name;
|
||||
const char *c = dot-1;
|
||||
for(;c!=name;--c) {
|
||||
if(*c == '.') {
|
||||
++c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(isMappedElement(c))
|
||||
return std::string(name,c-name)+(dot+1);
|
||||
return name;
|
||||
}
|
||||
|
||||
std::string ComplexGeoData::noElementName(const char *name) {
|
||||
if(!name)
|
||||
return std::string();
|
||||
auto element = findElementName(name);
|
||||
if(element)
|
||||
return std::string(name,element-name);
|
||||
return name;
|
||||
}
|
||||
|
||||
const char *ComplexGeoData::findElementName(const char *subname) {
|
||||
if(!subname || !subname[0] || isMappedElement(subname))
|
||||
return subname;
|
||||
const char *dot = strrchr(subname,'.');
|
||||
if(!dot)
|
||||
return subname;
|
||||
const char *element = dot+1;
|
||||
if(dot==subname || isMappedElement(element))
|
||||
return element;
|
||||
for(--dot;dot!=subname;--dot) {
|
||||
if(*dot == '.') {
|
||||
++dot;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(isMappedElement(dot))
|
||||
return dot;
|
||||
return element;
|
||||
}
|
||||
|
||||
const std::string &ComplexGeoData::tagPostfix() {
|
||||
static std::string postfix(elementMapPrefix() + ":T");
|
||||
return postfix;
|
||||
}
|
||||
|
||||
const std::string &ComplexGeoData::indexPostfix() {
|
||||
static std::string postfix(elementMapPrefix() + ":I");
|
||||
return postfix;
|
||||
}
|
||||
|
||||
const std::string &ComplexGeoData::missingPrefix() {
|
||||
static std::string prefix("?");
|
||||
return prefix;
|
||||
}
|
||||
|
||||
bool ComplexGeoData::hasMissingElement(const char *subname) {
|
||||
if(!subname)
|
||||
return false;
|
||||
auto dot = strrchr(subname,'.');
|
||||
if(dot)
|
||||
subname = dot+1;
|
||||
return boost::starts_with(subname,missingPrefix());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user