Sketcher: SketchGeometryExtension refactor InternalGeometry string conversion

=============================================================================

Minor refactoring to centralise string to enum conversion in a single place
This commit is contained in:
Abdullah Tahiri
2020-11-14 06:54:01 +01:00
committed by abdullahtahiriyo
parent 72fa70add8
commit 91ac9d2951
4 changed files with 28 additions and 22 deletions

View File

@@ -98,3 +98,21 @@ PyObject * SketchGeometryExtension::getPyObject(void)
return new SketchGeometryExtensionPy(new SketchGeometryExtension(*this));
}
bool SketchGeometryExtension::getInternalTypeFromName(std::string str, InternalType::InternalType &type)
{
auto pos = std::find_if( SketchGeometryExtension::internaltype2str.begin(),
SketchGeometryExtension::internaltype2str.end(),
[str](const char * val) {
return strcmp(val,str.c_str())==0;}
);
if( pos != SketchGeometryExtension::internaltype2str.end()) {
int index = std::distance( SketchGeometryExtension::internaltype2str.begin(), pos );
type = static_cast<InternalType::InternalType>(index);
return true;
}
return false;
}