diff --git a/src/App/Extension.cpp b/src/App/Extension.cpp index 5ec6242da7..0a150a9b40 100644 --- a/src/App/Extension.cpp +++ b/src/App/Extension.cpp @@ -57,11 +57,11 @@ App::PropertyData App::Extension::propertyData; void App::Extension::init() { - assert(Extension::classTypeId == Base::Type::badType() && "don't init() twice!"); + assert(Extension::classTypeId.isBad() && "don't init() twice!"); /* Set up entry in the type system. */ Extension::classTypeId = - Base::Type::createType(Base::Type::badType(), "App::Extension", Extension::create); + Base::Type::createType(Base::Type::BadType, "App::Extension", Extension::create); } using namespace App; @@ -194,11 +194,11 @@ void Extension::initExtensionSubclass(Base::Type& toInit, Base::Type::instantiationMethod method) { // don't init twice! - assert(toInit == Base::Type::badType()); + assert(toInit.isBad()); // get the parent class Base::Type parentType(Base::Type::fromName(ParentName)); // forgot init parent! - assert(parentType != Base::Type::badType()); + assert(!parentType.isBad()); // create the new type toInit = Base::Type::createType(parentType, ClassName, method); diff --git a/src/App/Extension.h b/src/App/Extension.h index 8ee6b31098..80fadace14 100644 --- a/src/App/Extension.h +++ b/src/App/Extension.h @@ -59,7 +59,7 @@ private: \ #define EXTENSION_TYPESYSTEM_SOURCE_P(_class_) \ Base::Type _class_::getExtensionClassTypeId(void) { return _class_::classTypeId; } \ Base::Type _class_::getExtensionTypeId(void) const { return _class_::classTypeId; } \ -Base::Type _class_::classTypeId = Base::Type::badType(); \ +Base::Type _class_::classTypeId = Base::Type::BadType; \ void * _class_::create(void){\ return new _class_ ();\ } @@ -68,7 +68,7 @@ void * _class_::create(void){\ #define EXTENSION_TYPESYSTEM_SOURCE_ABSTRACT_P(_class_) \ Base::Type _class_::getExtensionClassTypeId(void) { return _class_::classTypeId; } \ Base::Type _class_::getExtensionTypeId(void) const { return _class_::classTypeId; } \ -Base::Type _class_::classTypeId = Base::Type::badType(); \ +Base::Type _class_::classTypeId = Base::Type::BadType; \ void * _class_::create(void){return 0;} /// define to implement a subclass of Base::BaseClass @@ -79,7 +79,7 @@ void _class_::init(void){\ } #define EXTENSION_TYPESYSTEM_SOURCE_TEMPLATE(_class_) \ -template<> Base::Type _class_::classTypeId = Base::Type::badType(); \ +template<> Base::Type _class_::classTypeId = Base::Type::BadType; \ template<> Base::Type _class_::getExtensionClassTypeId(void) { return _class_::classTypeId; } \ template<> Base::Type _class_::getExtensionTypeId(void) const { return _class_::classTypeId; } \ template<> void * _class_::create(void){\ diff --git a/src/App/ProjectFile.cpp b/src/App/ProjectFile.cpp index 7cc7490100..2363111746 100644 --- a/src/App/ProjectFile.cpp +++ b/src/App/ProjectFile.cpp @@ -363,7 +363,7 @@ Base::Type ProjectFile::getTypeId(const std::string& name) const // // if (!xmlDocument) { - return Base::Type::badType(); + return Base::Type::BadType; } DOMNodeList* nodes = xmlDocument->getElementsByTagName(XStrLiteral("Objects").unicodeForm()); @@ -388,7 +388,7 @@ Base::Type ProjectFile::getTypeId(const std::string& name) const } } - return Base::Type::badType(); + return Base::Type::BadType; } std::list ProjectFile::getPropertyFiles(const std::string& name) const diff --git a/src/App/PropertyContainer.h b/src/App/PropertyContainer.h index 835803219d..d89c515149 100644 --- a/src/App/PropertyContainer.h +++ b/src/App/PropertyContainer.h @@ -382,7 +382,7 @@ void _class_::init(void){\ } #define TYPESYSTEM_SOURCE_TEMPLATE(_class_) \ -template<> Base::Type _class_::classTypeId = Base::Type::badType(); \ +template<> Base::Type _class_::classTypeId = Base::Type::BadType; \ template<> Base::Type _class_::getClassTypeId(void) { return _class_::classTypeId; } \ template<> Base::Type _class_::getTypeId(void) const { return _class_::classTypeId; } \ template<> void * _class_::create(void){\ diff --git a/src/App/PropertyStandard.cpp b/src/App/PropertyStandard.cpp index c1c8e2c95c..b7eda1a93e 100644 --- a/src/App/PropertyStandard.cpp +++ b/src/App/PropertyStandard.cpp @@ -3453,17 +3453,10 @@ unsigned int PropertyPersistentObject::getMemSize() const void PropertyPersistentObject::setValue(const char* type) { - if (!type) { - type = ""; - } - if (type[0]) { - Base::Type::importModule(type); - Base::Type t = Base::Type::fromName(type); + if (!Base::Tools::isNullOrEmpty(type)) { + Base::Type t = Base::Type::getTypeIfDerivedFrom(type, Persistence::getClassTypeId()); if (t.isBad()) { - throw Base::TypeError("Invalid type"); - } - if (!t.isDerivedFrom(Persistence::getClassTypeId())) { - throw Base::TypeError("Type must be derived from Base::Persistence"); + throw Base::TypeError("Invalid type or type must be derived from Base::Persistence"); } if (_pObject && _pObject->getTypeId() == t) { return; diff --git a/src/Base/BaseClass.cpp b/src/Base/BaseClass.cpp index 301cb5c33b..16c0ee8341 100644 --- a/src/Base/BaseClass.cpp +++ b/src/Base/BaseClass.cpp @@ -32,7 +32,7 @@ using namespace Base; -Type BaseClass::classTypeId = Base::Type::badType(); // NOLINT +Type BaseClass::classTypeId = Base::Type::BadType; //************************************************************************** @@ -56,15 +56,14 @@ BaseClass::~BaseClass() = default; void BaseClass::init() { - assert(BaseClass::classTypeId == Type::badType() && "don't init() twice!"); + assert(BaseClass::classTypeId.isBad() && "don't init() twice!"); /* Make sure superclass gets initialized before subclass. */ /*assert(strcmp(#_parentclass_), "inherited"));*/ /*Type parentType(Type::fromName(#_parentclass_));*/ - /*assert(parentType != Type::badType() && "you forgot init() on parentclass!");*/ + /*assert(!parentType.isBad() && "you forgot init() on parentclass!");*/ /* Set up entry in the type system. */ - BaseClass::classTypeId = - Type::createType(Type::badType(), "Base::BaseClass", BaseClass::create); + BaseClass::classTypeId = Type::createType(Type::BadType, "Base::BaseClass", BaseClass::create); } Type BaseClass::getClassTypeId() @@ -84,11 +83,11 @@ void BaseClass::initSubclass(Base::Type& toInit, Type::instantiationMethod method) { // don't init twice! - assert(toInit == Base::Type::badType()); + assert(toInit.isBad()); // get the parent class Base::Type parentType(Base::Type::fromName(ParentName)); // forgot init parent! - assert(parentType != Base::Type::badType()); + assert(!parentType.isBad()); // create the new type toInit = Base::Type::createType(parentType, ClassName, method); diff --git a/src/Base/BaseClass.h b/src/Base/BaseClass.h index 33d7ced2f2..3c3dced6d8 100644 --- a/src/Base/BaseClass.h +++ b/src/Base/BaseClass.h @@ -65,7 +65,7 @@ private: { \ return _class_::classTypeId; \ } \ - Base::Type _class_::classTypeId = Base::Type::badType(); \ + Base::Type _class_::classTypeId = Base::Type::BadType; \ void* _class_::create(void) \ { \ return new _class_(); \ @@ -99,7 +99,7 @@ private: { \ return _class_::classTypeId; \ } \ - Base::Type _class_::classTypeId = Base::Type::badType(); \ + Base::Type _class_::classTypeId = Base::Type::BadType; \ void* _class_::create(void) \ { \ return 0; \ diff --git a/src/Base/BaseClassPyImp.cpp b/src/Base/BaseClassPyImp.cpp index d432672264..ac17bb9bc3 100644 --- a/src/Base/BaseClassPyImp.cpp +++ b/src/Base/BaseClassPyImp.cpp @@ -44,7 +44,7 @@ PyObject* BaseClassPy::isDerivedFrom(PyObject* args) } Base::Type type = Base::Type::fromName(name); - bool valid = (type != Base::Type::badType() && getBaseClassPtr()->isDerivedFrom(type)); + bool valid = (!type.isBad() && getBaseClassPtr()->isDerivedFrom(type)); return PyBool_FromLong(valid ? 1 : 0); } diff --git a/src/Base/Type.cpp b/src/Base/Type.cpp index 421833305f..63eb34245a 100644 --- a/src/Base/Type.cpp +++ b/src/Base/Type.cpp @@ -33,61 +33,84 @@ using namespace Base; +static_assert(sizeof(Base::Type) == sizeof(Type::TypeId), + "Base::Type has been designed to be small to be passed around by value efficiently. " + "The size of Base::Type has changed. Be careful when adding more data members."); + +static_assert( + sizeof(Base::Type) <= 2 * sizeof(void*), + "Base::Type has been designed to be small to be passed around by value efficiently. " + "When the size grows larger than ~2 words, consider passing by const reference instead. " + "Exact limit depends on the architecture and ABI."); struct Base::TypeData { - TypeData(const char* theName, - const Type type = Type::badType(), - const Type theParent = Type::badType(), - Type::instantiationMethod method = nullptr) - : name(theName) - , parent(theParent) + TypeData(const char* name, + const Type type, + const Type parent, + const Type::instantiationMethod instMethod) + : name(name) + , parent(parent) , type(type) - , instMethod(method) + , instMethod(instMethod) {} - std::string name; - Type parent; - Type type; - Type::instantiationMethod instMethod; + const std::string name; + const Type parent; + const Type type; + const Type::instantiationMethod instMethod; }; +namespace +{ +constexpr const char* BadTypeName = "BadType"; +} + std::map Type::typemap; std::vector Type::typedata; std::set Type::loadModuleSet; +const Type Type::BadType; + +Type::instantiationMethod Type::getInstantiationMethod() const +{ + assert(typedata.size() >= 1 && "Type::init() must be called before creating instances"); + assert(typedata.size() > index && "Type index out of bounds"); + if (isBad() || typedata.size() <= index) { + return nullptr; + } + return typedata[index]->instMethod; +} + void* Type::createInstance() const { - instantiationMethod method = typedata[index]->instMethod; + const auto method = getInstantiationMethod(); return method ? (*method)() : nullptr; } bool Type::canInstantiate() const { - instantiationMethod method = typedata[index]->instMethod; + const auto method = getInstantiationMethod(); return method != nullptr; } -void* Type::createInstanceByName(const char* TypeName, bool bLoadModule) +void* Type::createInstanceByName(const char* typeName, bool loadModule) { // if not already, load the module - if (bLoadModule) { - importModule(TypeName); + if (loadModule) { + importModule(typeName); } // now the type should be in the type map - Type type = fromName(TypeName); - if (type == badType()) { - return nullptr; - } - + const Type type = fromName(typeName); + // let createInstance handle isBad check return type.createInstance(); } -void Type::importModule(const char* TypeName) +void Type::importModule(const char* typeName) { // cut out the module name - const std::string mod = getModuleName(TypeName); + const std::string mod = getModuleName(typeName); // ignore base modules if (mod == "App" || mod == "Gui" || mod == "Base") { @@ -95,45 +118,38 @@ void Type::importModule(const char* TypeName) } // remember already loaded modules - const auto pos = loadModuleSet.find(mod); - if (pos != loadModuleSet.end()) { + if (loadModuleSet.contains(mod)) { return; } // lets load the module Interpreter().loadModule(mod.c_str()); #ifdef FC_LOGLOADMODULE - Console().Log("Act: Module %s loaded through class %s \n", Mod.c_str(), TypeName); + Console().Log("Act: Module %s loaded through class %s \n", Mod.c_str(), typeName); #endif loadModuleSet.insert(mod); } -std::string Type::getModuleName(const char* ClassName) +const std::string Type::getModuleName(const char* className) { - std::string_view classNameView(ClassName); + std::string_view classNameView(className); auto pos = classNameView.find("::"); return pos != std::string_view::npos ? std::string(classNameView.substr(0, pos)) : std::string(); } -Type Type::badType() -{ - Type bad; - bad.index = 0; - return bad; -} - -Type Type::createType(const Type& parent, const char* name, instantiationMethod method) +const Type Type::createType(const Type parent, const char* name, instantiationMethod method) { + assert(name && name[0] != '\0' && "Type name must not be empty"); + Type newType; newType.index = static_cast(Type::typedata.size()); - TypeData* typeData = new TypeData(name, newType, parent, method); - Type::typedata.push_back(typeData); + Type::typedata.emplace_back(new TypeData(name, newType, parent, method)); // add to dictionary for fast lookup - Type::typemap[name] = newType.getKey(); + Type::typemap.emplace(name, newType.getKey()); return newType; } @@ -141,11 +157,9 @@ Type Type::createType(const Type& parent, const char* name, instantiationMethod void Type::init() { - assert(Type::typedata.empty()); - - - Type::typedata.push_back(new TypeData("BadType")); - Type::typemap["BadType"] = 0; + assert(Type::typedata.size() == 0 && "Type::init() should only be called once"); + typedata.emplace_back(new TypeData(BadTypeName, BadType, BadType, nullptr)); + typemap[BadTypeName] = 0; } void Type::destruct() @@ -158,58 +172,59 @@ void Type::destruct() loadModuleSet.clear(); } -Type Type::fromName(const char* name) +const Type Type::fromName(const char* name) { - std::map::const_iterator pos; - - pos = typemap.find(name); - if (pos != typemap.end()) { - return typedata[pos->second]->type; + const auto pos = typemap.find(name); + if (pos == typemap.end()) { + return Type::BadType; } - return Type::badType(); + return typedata[pos->second]->type; } -Type Type::fromKey(unsigned int key) +const Type Type::fromKey(TypeId key) { if (key < typedata.size()) { return typedata[key]->type; } - return Type::badType(); + return BadType; } const char* Type::getName() const { + assert(typedata.size() >= 1 + && "Type::init() must be called before fetching names, even for bad types"); return typedata[index]->name.c_str(); } -Type Type::getParent() const +const Type Type::getParent() const { + assert(typedata.size() >= 1 + && "Type::init() must be called before fetching parents, even for bad types"); return typedata[index]->parent; } -bool Type::isDerivedFrom(const Type& type) const +bool Type::isDerivedFrom(const Type type) const { - Type temp(*this); do { if (temp == type) { return true; } temp = temp.getParent(); - } while (temp != badType()); + } while (!temp.isBad()); return false; } -int Type::getAllDerivedFrom(const Type& type, std::vector& List) +int Type::getAllDerivedFrom(const Type type, std::vector& list) { int cnt = 0; for (auto it : typedata) { if (it->type.isDerivedFrom(type)) { - List.push_back(it->type); + list.push_back(it->type); cnt++; } } @@ -221,17 +236,15 @@ int Type::getNumTypes() return static_cast(typedata.size()); } -Type Type::getTypeIfDerivedFrom(const char* name, const Type& parent, bool bLoadModule) +const Type Type::getTypeIfDerivedFrom(const char* name, const Type parent, bool loadModule) { - if (bLoadModule) { + if (loadModule) { importModule(name); } - Type type = fromName(name); - - if (type.isDerivedFrom(parent)) { + if (const Type type(fromName(name)); type.isDerivedFrom(parent)) { return type; } - return Type::badType(); + return BadType; } diff --git a/src/Base/Type.h b/src/Base/Type.h index fad31905db..adba866cef 100644 --- a/src/Base/Type.h +++ b/src/Base/Type.h @@ -77,9 +77,10 @@ struct TypeData; information: super classes must be registered before any of their derived classes are. */ -class BaseExport Type +class BaseExport Type final { public: + using TypeId = unsigned int; /// Construction Type(const Type& type) = default; Type(Type&& type) = default; @@ -87,34 +88,39 @@ public: /// Destruction ~Type() = default; - /// creates a instance of this type - void* createInstance() const; + /// Creates an instance of this type + [[nodiscard]] void* createInstance() const; /// Checks whether this type can instantiate - bool canInstantiate() const; - /// creates a instance of the named type - static void* createInstanceByName(const char* TypeName, bool bLoadModule = false); - static void importModule(const char* TypeName); + [[nodiscard]] bool canInstantiate() const; + /// Creates an instance of the named type + [[nodiscard]] static void* createInstanceByName(const char* typeName, bool loadModule = false); using instantiationMethod = void* (*)(); - static Type fromName(const char* name); - static Type fromKey(unsigned int key); - const char* getName() const; - Type getParent() const; - bool isDerivedFrom(const Type& type) const; - - static int getAllDerivedFrom(const Type& type, std::vector& List); + /// Returns a type object by name + [[nodiscard]] static const Type fromName(const char* name); + /// Returns a type object by key + [[nodiscard]] static const Type fromKey(TypeId key); + /// Returns the name of the type + [[nodiscard]] const char* getName() const; + /// Returns the parent type + [[nodiscard]] const Type getParent() const; + /// Checks whether this type is derived from "type" + [[nodiscard]] bool isDerivedFrom(const Type type) const; + /// Returns all descendants from the given type + static int getAllDerivedFrom(const Type type, std::vector& list); /// Returns the given named type if is derived from parent type, otherwise return bad type - static Type - getTypeIfDerivedFrom(const char* name, const Type& parent, bool bLoadModule = false); - - static int getNumTypes(); - - static Type - createType(const Type& parent, const char* name, instantiationMethod method = nullptr); - - unsigned int getKey() const; - bool isBad() const; + [[nodiscard]] static const Type + getTypeIfDerivedFrom(const char* name, const Type parent, bool loadModule = false); + /// Returns the number of types created so far + [[nodiscard]] static int getNumTypes(); + /// Creates a new type with the given name, parent and instantiation method + [[nodiscard]] static const Type + createType(const Type parent, const char* name, instantiationMethod method = nullptr); + /// Returns the inner index of the type + [[nodiscard]] TypeId getKey() const; + /// Checks if the type is invalid + [[nodiscard]] bool isBad() const; Type& operator=(const Type& type) = default; Type& operator=(Type&& type) = default; @@ -126,23 +132,28 @@ public: bool operator>=(const Type& type) const; bool operator>(const Type& type) const; - static Type badType(); + static const Type BadType; static void init(); static void destruct(); - static std::string getModuleName(const char* ClassName); - + /// Returns the name of the module the class is defined in + static const std::string getModuleName(const char* className); private: - unsigned int index {0}; + [[nodiscard]] instantiationMethod getInstantiationMethod() const; + static void importModule(const char* TypeName); - static std::map typemap; - static std::vector typedata; + TypeId index {BadTypeIndex}; + + static std::map typemap; + static std::vector typedata; // use pointer to hide implementation details static std::set loadModuleSet; + + static constexpr TypeId BadTypeIndex = 0; }; -inline unsigned int Type::getKey() const +inline Type::TypeId Type::getKey() const { return this->index; } @@ -179,7 +190,7 @@ inline bool Type::operator>(const Type& type) const inline bool Type::isBad() const { - return (this->index == 0); + return this->index == BadTypeIndex; } } // namespace Base diff --git a/src/Base/TypePyImp.cpp b/src/Base/TypePyImp.cpp index c997bb69c4..7dc9336584 100644 --- a/src/Base/TypePyImp.cpp +++ b/src/Base/TypePyImp.cpp @@ -76,8 +76,7 @@ PyObject* TypePy::getBadType(PyObject* args) return nullptr; } - Base::Type type = Base::Type::badType(); - return new TypePy(new Base::Type(type)); + return new TypePy(new Base::Type(Base::Type::BadType)); } PyObject* TypePy::getParent(PyObject* args) @@ -122,7 +121,7 @@ PyObject* TypePy::isDerivedFrom(PyObject* args) return nullptr; } while (false); - bool val = (type != Base::Type::badType() && getBaseTypePtr()->isDerivedFrom(type)); + bool val = (!type.isBad() && getBaseTypePtr()->isDerivedFrom(type)); return PyBool_FromLong(val ? 1 : 0); } diff --git a/src/Gui/DAGView/DAGFilter.cpp b/src/Gui/DAGView/DAGFilter.cpp index e331d52d2e..1545143a27 100644 --- a/src/Gui/DAGView/DAGFilter.cpp +++ b/src/Gui/DAGView/DAGFilter.cpp @@ -44,7 +44,7 @@ FilterOrigin::FilterOrigin() : FilterBase() bool FilterOrigin::goFilter(const Vertex &vertexIn, const Graph &graphIn, const GraphLinkContainer &linkIn) const { Base::Type originType = Base::Type::fromName("App::Origin"); - assert (originType != Base::Type::badType()); + assert (!originType.isBad()); //if child of origin hide. InEdgeIterator it, itEnd; for (boost::tie(it, itEnd) = boost::in_edges(vertexIn, graphIn); it != itEnd; ++it) @@ -72,7 +72,7 @@ bool FilterTyped::goFilter(const Gui::DAG::Vertex& vertexIn, const Graph& graphI if (type.empty()) return false; Base::Type theType = Base::Type::fromName(type.c_str()); - if (theType == Base::Type::badType()) + if (theType.isBad()) return false; const GraphLinkRecord &sourceRecord = findRecord(vertexIn, linkIn); diff --git a/src/Gui/DAGView/DAGModel.cpp b/src/Gui/DAGView/DAGModel.cpp index 9dc8a902a9..a699d94470 100644 --- a/src/Gui/DAGView/DAGModel.cpp +++ b/src/Gui/DAGView/DAGModel.cpp @@ -1186,11 +1186,11 @@ void Model::visiblyIsolate(Gui::DAG::Vertex sourceIn) std::vector out; Base::Type type; type = Base::Type::fromName("App::DocumentObjectGroup"); - if (type != Base::Type::badType()) out.push_back(type); + if (!type.isBad()) out.push_back(type); type = Base::Type::fromName("App::Part"); - if (type != Base::Type::badType()) out.push_back(type); + if (!type.isBad()) out.push_back(type); type = Base::Type::fromName("PartDesign::Body"); - if (type != Base::Type::badType()) out.push_back(type); + if (!type.isBad()) out.push_back(type); return out; }; diff --git a/src/Gui/Dialogs/DlgAddPropertyVarSet.cpp b/src/Gui/Dialogs/DlgAddPropertyVarSet.cpp index 312666ded2..1b505e7365 100644 --- a/src/Gui/Dialogs/DlgAddPropertyVarSet.cpp +++ b/src/Gui/Dialogs/DlgAddPropertyVarSet.cpp @@ -441,7 +441,7 @@ void DlgAddPropertyVarSet::checkGroup() { void DlgAddPropertyVarSet::checkType() { std::string type = ui->comboBoxType->currentText().toStdString(); - if (Base::Type::fromName(type.c_str()) == Base::Type::badType()) { + if (Base::Type::fromName(type.c_str()).isBad()) { throw CreatePropertyException("Invalid name"); } } diff --git a/src/Gui/Dialogs/DlgExpressionInput.cpp b/src/Gui/Dialogs/DlgExpressionInput.cpp index 98e279af6a..0b1116d0c5 100644 --- a/src/Gui/Dialogs/DlgExpressionInput.cpp +++ b/src/Gui/Dialogs/DlgExpressionInput.cpp @@ -179,7 +179,7 @@ Base::Type DlgExpressionInput::determineTypeVarSet() std::string unitTypeString = impliedUnit.getTypeString(); if (unitTypeString.empty()) { // no type was provided - return Base::Type::badType(); + return Base::Type::BadType; } std::string typeString = "App::Property" + unitTypeString; @@ -190,7 +190,7 @@ Base::Type DlgExpressionInput::determineTypeVarSet() bool DlgExpressionInput::typeOkForVarSet() { std::string unitType = impliedUnit.getTypeString(); - return determineTypeVarSet() != Base::Type::badType(); + return !determineTypeVarSet().isBad(); } void DlgExpressionInput::initializeVarSets() diff --git a/src/Gui/Selection/Selection.cpp b/src/Gui/Selection/Selection.cpp index 801be68e77..9aa562fcf2 100644 --- a/src/Gui/Selection/Selection.cpp +++ b/src/Gui/Selection/Selection.cpp @@ -332,7 +332,7 @@ std::vector SelectionSingleton::getObjectList(const char* pDocN std::map SortMap; // check the type - if (typeId == Base::Type::badType()) + if (typeId.isBad()) return temp; App::Document *pcDoc = nullptr; @@ -543,7 +543,7 @@ vector SelectionSingleton::getObjectsOfType(const Base::Ty std::vector SelectionSingleton::getObjectsOfType(const char* typeName, const char* pDocName, ResolveMode resolve) const { Base::Type typeId = Base::Type::fromName(typeName); - if (typeId == Base::Type::badType()) + if (typeId.isBad()) return {}; return getObjectsOfType(typeId, pDocName, resolve); } @@ -565,7 +565,7 @@ unsigned int SelectionSingleton::countObjectsOfType(const Base::Type& typeId, co unsigned int SelectionSingleton::countObjectsOfType(const char* typeName, const char* pDocName, ResolveMode resolve) const { Base::Type typeId = Base::Type::fromName(typeName); - if (typeId == Base::Type::badType()) + if (typeId.isBad()) return 0; return countObjectsOfType(typeId, pDocName, resolve); } diff --git a/src/Mod/Measure/App/MeasureDistance.cpp b/src/Mod/Measure/App/MeasureDistance.cpp index aa748856df..c2a5695d55 100644 --- a/src/Mod/Measure/App/MeasureDistance.cpp +++ b/src/Mod/Measure/App/MeasureDistance.cpp @@ -415,12 +415,12 @@ std::vector MeasureDistanceDetached::getSubject() const Base::Type MeasureDistanceType::getClassTypeId() { - return Base::Type::badType(); + return Base::Type::BadType; } Base::Type MeasureDistanceType::getTypeId() const { - return Base::Type::badType(); + return Base::Type::BadType; } void MeasureDistanceType::init() @@ -436,7 +436,7 @@ void* MeasureDistanceType::create() return new MeasureDistanceDetached(); } -Base::Type MeasureDistanceType::classTypeId = Base::Type::badType(); +Base::Type MeasureDistanceType::classTypeId = Base::Type::BadType; // Migrate old MeasureDistance Type diff --git a/src/Mod/Part/App/GeometryDefaultExtension.h b/src/Mod/Part/App/GeometryDefaultExtension.h index 1e3bc41fff..439c1dc229 100644 --- a/src/Mod/Part/App/GeometryDefaultExtension.h +++ b/src/Mod/Part/App/GeometryDefaultExtension.h @@ -87,7 +87,7 @@ namespace Part { // 6. Register your type and corresponding python type in AppPart.cpp template - Base::Type GeometryDefaultExtension::classTypeId{Base::Type::badType()}; + Base::Type GeometryDefaultExtension::classTypeId{Base::Type::BadType}; // Must be explicitly declared here template<> void * GeometryDefaultExtension::create(); diff --git a/src/Mod/Part/App/GeometryPyImp.cpp b/src/Mod/Part/App/GeometryPyImp.cpp index 8cc3b90743..9c7488270a 100644 --- a/src/Mod/Part/App/GeometryPyImp.cpp +++ b/src/Mod/Part/App/GeometryPyImp.cpp @@ -242,7 +242,7 @@ PyObject* GeometryPy::getExtensionOfType(PyObject *args) Base::Type type = Base::Type::fromName(o); - if(type != Base::Type::badType()) { + if(!type.isBad()) { try { std::shared_ptr ext(this->getGeometryPtr()->getExtension(type)); @@ -313,7 +313,7 @@ PyObject* GeometryPy::hasExtensionOfType(PyObject *args) Base::Type type = Base::Type::fromName(o); - if(type != Base::Type::badType()) { + if(!type.isBad()) { try { return Py::new_reference_to(Py::Boolean(this->getGeometryPtr()->hasExtension(type))); } @@ -360,7 +360,7 @@ PyObject* GeometryPy::deleteExtensionOfType(PyObject *args) Base::Type type = Base::Type::fromName(o); - if(type != Base::Type::badType()) { + if(!type.isBad()) { try { this->getGeometryPtr()->deleteExtension(type); Py_Return; diff --git a/src/Mod/Sketcher/App/ExternalGeometryFacadePyImp.cpp b/src/Mod/Sketcher/App/ExternalGeometryFacadePyImp.cpp index cebe5f27b1..ef0166f24f 100644 --- a/src/Mod/Sketcher/App/ExternalGeometryFacadePyImp.cpp +++ b/src/Mod/Sketcher/App/ExternalGeometryFacadePyImp.cpp @@ -302,7 +302,7 @@ PyObject* ExternalGeometryFacadePy::getExtensionOfType(PyObject* args) Base::Type type = Base::Type::fromName(o); - if (type != Base::Type::badType()) { + if (!type.isBad()) { try { std::shared_ptr ext( this->getExternalGeometryFacadePtr()->getExtension(type)); @@ -379,7 +379,7 @@ PyObject* ExternalGeometryFacadePy::hasExtensionOfType(PyObject* args) Base::Type type = Base::Type::fromName(o); - if (type != Base::Type::badType()) { + if (!type.isBad()) { try { return Py::new_reference_to( Py::Boolean(this->getExternalGeometryFacadePtr()->hasExtension(type))); @@ -427,7 +427,7 @@ PyObject* ExternalGeometryFacadePy::deleteExtensionOfType(PyObject* args) Base::Type type = Base::Type::fromName(o); - if (type != Base::Type::badType()) { + if (!type.isBad()) { try { this->getExternalGeometryFacadePtr()->deleteExtension(type); Py_Return; diff --git a/src/Mod/Sketcher/App/GeometryFacadePyImp.cpp b/src/Mod/Sketcher/App/GeometryFacadePyImp.cpp index 1aa73bad22..8a0ee1d17a 100644 --- a/src/Mod/Sketcher/App/GeometryFacadePyImp.cpp +++ b/src/Mod/Sketcher/App/GeometryFacadePyImp.cpp @@ -278,7 +278,7 @@ PyObject* GeometryFacadePy::getExtensionOfType(PyObject* args) Base::Type type = Base::Type::fromName(o); - if (type != Base::Type::badType()) { + if (!type.isBad()) { try { std::shared_ptr ext( this->getGeometryFacadePtr()->getExtension(type)); @@ -355,7 +355,7 @@ PyObject* GeometryFacadePy::hasExtensionOfType(PyObject* args) Base::Type type = Base::Type::fromName(o); - if (type != Base::Type::badType()) { + if (!type.isBad()) { try { return Py::new_reference_to( Py::Boolean(this->getGeometryFacadePtr()->hasExtension(type))); @@ -403,7 +403,7 @@ PyObject* GeometryFacadePy::deleteExtensionOfType(PyObject* args) Base::Type type = Base::Type::fromName(o); - if (type != Base::Type::badType()) { + if (!type.isBad()) { try { this->getGeometryFacadePtr()->deleteExtension(type); Py_Return; diff --git a/src/Mod/Sketcher/Gui/CommandConstraints.cpp b/src/Mod/Sketcher/Gui/CommandConstraints.cpp index 0706d22c2e..d46109ce7f 100644 --- a/src/Mod/Sketcher/Gui/CommandConstraints.cpp +++ b/src/Mod/Sketcher/Gui/CommandConstraints.cpp @@ -1526,7 +1526,7 @@ public: selIdPair.GeoId = GeoEnum::GeoUndef; selIdPair.PosId = Sketcher::PointPos::none; std::stringstream ss; - Base::Type newselGeoType = Base::Type::badType(); + Base::Type newselGeoType = Base::Type::BadType; int VtId = getPreselectPoint(); int CrvId = getPreselectCurve(); @@ -1662,7 +1662,7 @@ protected: SelIdPair selIdPair; getIdsFromName(selElement, Obj, selIdPair.GeoId, selIdPair.PosId); - Base::Type newselGeoType = Base::Type::badType(); + Base::Type newselGeoType = Base::Type::BadType; if (isEdge(selIdPair.GeoId, selIdPair.PosId)) { const Part::Geometry* geo = Obj->getGeometry(selIdPair.GeoId); newselGeoType = geo->getTypeId(); diff --git a/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp b/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp index 3d5695a50f..e5df986f5d 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp @@ -463,7 +463,7 @@ private: icons.emplace( std::piecewise_construct, - std::forward_as_tuple(Base::Type::badType()), + std::forward_as_tuple(Base::Type::BadType), std::forward_as_tuple( std::initializer_list< std::pair>> { @@ -479,14 +479,14 @@ private: auto typekey = icons.find(type); if (typekey == icons.end()) {// Not supported Geometry Type - Defaults to invalid icon - typekey = icons.find(Base::Type::badType()); + typekey = icons.find(Base::Type::BadType); pos = Sketcher::PointPos::none; } auto poskey = typekey->second.find(pos); if (poskey == typekey->second.end()) {// invalid PointPos for type - Provide Invalid icon - typekey = icons.find(Base::Type::badType()); + typekey = icons.find(Base::Type::BadType); pos = Sketcher::PointPos::none; poskey = typekey->second.find(pos); }