Part: Default geometry extensions make sure built-in types are initialised
This commit is contained in:
@@ -34,7 +34,7 @@ namespace Part {
|
||||
{
|
||||
TYPESYSTEM_HEADER();
|
||||
public:
|
||||
GeometryDefaultExtension() = default;
|
||||
inline GeometryDefaultExtension();
|
||||
GeometryDefaultExtension(const T& val, std::string name = std::string());
|
||||
virtual ~GeometryDefaultExtension() = default;
|
||||
|
||||
@@ -63,7 +63,8 @@ namespace Part {
|
||||
//
|
||||
// Warnings:
|
||||
// - The default constructor relies on the default constructor of T for initialisation. Built-in types
|
||||
// so constructed will be uninitialised. Use the specific constructor from a T to initiliase it.
|
||||
// so constructed will be uninitialised. Use the specific constructor from a T to initiliase it. Note
|
||||
// that the default constructor is required by the type system (see TYPESYSTEM_SOURCE_TEMPLATE_T).
|
||||
//
|
||||
// Default assumptions:
|
||||
// - T can be constructed from T
|
||||
@@ -85,6 +86,19 @@ namespace Part {
|
||||
// 5. Provide specialisations if your type does not meet the assumptions above (e.g. for serialisation) (cpp file)
|
||||
// 6. Register your type and corresponding python type in AppPart.cpp
|
||||
|
||||
template <typename T>
|
||||
inline GeometryDefaultExtension<T>::GeometryDefaultExtension(){ }
|
||||
|
||||
// Specialised constructors go here so that specialisation is before the template instantiation
|
||||
// Specialised default constructors are inline, because a full specialisation otherwise shall go in the cpp file, but there it would be after the template instantiation.
|
||||
template <>
|
||||
inline GeometryDefaultExtension<long>::GeometryDefaultExtension():value(0){}
|
||||
|
||||
// instantiate the types so that other translation units (python wrappers) can access template
|
||||
//constructors other than the default.
|
||||
template class GeometryDefaultExtension<long>;
|
||||
template class GeometryDefaultExtension<std::string>;
|
||||
|
||||
// Prefer alias to typedef item 9
|
||||
using GeometryIntExtension = GeometryDefaultExtension<long>;
|
||||
using GeometryStringExtension = GeometryDefaultExtension<std::string>;
|
||||
|
||||
@@ -48,7 +48,7 @@ std::string GeometryIntExtensionPy::representation(void) const
|
||||
|
||||
PyObject *GeometryIntExtensionPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
|
||||
{
|
||||
// create a new instance of PointPy and the Twin object
|
||||
// create a new instance of the python object and the Twin object
|
||||
return new GeometryIntExtensionPy(new GeometryIntExtension);
|
||||
}
|
||||
|
||||
@@ -68,11 +68,18 @@ int GeometryIntExtensionPy::PyInit(PyObject* args, PyObject* /*kwd*/)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
PyErr_Clear();
|
||||
char * pystr;
|
||||
if (PyArg_ParseTuple(args, "ls", &Id,&pystr)) {
|
||||
this->getGeometryIntExtensionPtr()->setValue(Id);
|
||||
this->getGeometryIntExtensionPtr()->setName(pystr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyErr_SetString(PyExc_TypeError, "GeometryIntExtension constructor accepts:\n"
|
||||
"-- empty parameter list\n"
|
||||
"-- long int\n");
|
||||
"-- long int\n"
|
||||
"-- long int, string\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ std::string GeometryStringExtensionPy::representation(void) const
|
||||
|
||||
PyObject *GeometryStringExtensionPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Python wrapper
|
||||
{
|
||||
// create a new instance of PointPy and the Twin object
|
||||
// create a new instance of the python object and the Twin object
|
||||
return new GeometryStringExtensionPy(new GeometryStringExtension);
|
||||
}
|
||||
|
||||
@@ -70,11 +70,19 @@ int GeometryStringExtensionPy::PyInit(PyObject* args, PyObject* /*kwd*/)
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyErr_Clear();
|
||||
char * pystr;
|
||||
if (PyArg_ParseTuple(args, "ss", &pstr, &pystr)) {
|
||||
this->getGeometryStringExtensionPtr()->setValue(pstr);
|
||||
this->getGeometryStringExtensionPtr()->setName(pystr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
PyErr_SetString(PyExc_TypeError, "GeometryStringExtension constructor accepts:\n"
|
||||
"-- empty parameter list\n"
|
||||
"-- string\n");
|
||||
"-- string\n"
|
||||
"-- string, string\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user