Core/Mod: modernize C++11
* use nullptr
This commit is contained in:
@@ -188,13 +188,13 @@ PyMethodDef Application::Methods[] = {
|
||||
PyObject* Application::sLoadFile(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
char *path, *doc="",*mod="";
|
||||
if (!PyArg_ParseTuple(args, "s|ss", &path, &doc, &mod)) // convert args: Python->C
|
||||
return 0; // NULL triggers exception
|
||||
if (!PyArg_ParseTuple(args, "s|ss", &path, &doc, &mod))
|
||||
return nullptr;
|
||||
try {
|
||||
Base::FileInfo fi(path);
|
||||
if (!fi.isFile() || !fi.exists()) {
|
||||
PyErr_Format(PyExc_IOError, "File %s doesn't exist.", path);
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::string module = mod;
|
||||
@@ -203,7 +203,7 @@ PyObject* Application::sLoadFile(PyObject * /*self*/, PyObject *args)
|
||||
std::vector<std::string> modules = GetApplication().getImportModules(ext.c_str());
|
||||
if (modules.empty()) {
|
||||
PyErr_Format(PyExc_IOError, "Filetype %s is not supported.", ext.c_str());
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
else {
|
||||
module = modules.front();
|
||||
@@ -226,7 +226,7 @@ PyObject* Application::sLoadFile(PyObject * /*self*/, PyObject *args)
|
||||
catch (const std::exception& e) {
|
||||
// might be subclass from zipios
|
||||
PyErr_Format(PyExc_IOError, "Invalid project file %s: %s", path, e.what());
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,15 +285,15 @@ PyObject* Application::sNewDocument(PyObject * /*self*/, PyObject *args, PyObjec
|
||||
PyObject* Application::sSetActiveDocument(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
char *pstr = 0;
|
||||
if (!PyArg_ParseTuple(args, "s", &pstr)) // convert args: Python->C
|
||||
return NULL; // NULL triggers exception
|
||||
if (!PyArg_ParseTuple(args, "s", &pstr))
|
||||
return nullptr;
|
||||
|
||||
try {
|
||||
GetApplication().setActiveDocument(pstr);
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
PyErr_SetString(Base::BaseExceptionFreeCADError, e.what());
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Py_Return;
|
||||
@@ -302,22 +302,22 @@ PyObject* Application::sSetActiveDocument(PyObject * /*self*/, PyObject *args)
|
||||
PyObject* Application::sCloseDocument(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
char *pstr = 0;
|
||||
if (!PyArg_ParseTuple(args, "s", &pstr)) // convert args: Python->C
|
||||
return NULL; // NULL triggers exception
|
||||
if (!PyArg_ParseTuple(args, "s", &pstr))
|
||||
return nullptr;
|
||||
|
||||
Document* doc = GetApplication().getDocument(pstr);
|
||||
if (!doc) {
|
||||
PyErr_Format(PyExc_NameError, "Unknown document '%s'", pstr);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
if (!doc->isClosable()) {
|
||||
PyErr_Format(PyExc_RuntimeError, "The document '%s' is not closable for the moment", pstr);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (GetApplication().closeDocument(pstr) == false) {
|
||||
PyErr_Format(PyExc_RuntimeError, "Closing the document '%s' failed", pstr);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Py_Return;
|
||||
@@ -326,19 +326,19 @@ PyObject* Application::sCloseDocument(PyObject * /*self*/, PyObject *args)
|
||||
PyObject* Application::sSaveDocument(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
char *pDoc;
|
||||
if (!PyArg_ParseTuple(args, "s", &pDoc)) // convert args: Python->C
|
||||
return NULL; // NULL triggers exception
|
||||
if (!PyArg_ParseTuple(args, "s", &pDoc))
|
||||
return nullptr;
|
||||
|
||||
Document* doc = GetApplication().getDocument(pDoc);
|
||||
if ( doc ) {
|
||||
if ( doc->save() == false ) {
|
||||
PyErr_Format(Base::BaseExceptionFreeCADError, "Cannot save document '%s'", pDoc);
|
||||
return 0L;
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
else {
|
||||
PyErr_Format(PyExc_NameError, "Unknown document '%s'", pDoc);
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Py_Return;
|
||||
@@ -347,8 +347,8 @@ PyObject* Application::sSaveDocument(PyObject * /*self*/, PyObject *args)
|
||||
PyObject* Application::sSaveDocumentAs(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
char *pDoc, *pFileName;
|
||||
if (!PyArg_ParseTuple(args, "ss", &pDoc, &pFileName)) // convert args: Python->C
|
||||
return NULL; // NULL triggers exception
|
||||
if (!PyArg_ParseTuple(args, "ss", &pDoc, &pFileName))
|
||||
return nullptr;
|
||||
|
||||
Document* doc = GetApplication().getDocument(pDoc);
|
||||
if (doc) {
|
||||
@@ -364,8 +364,8 @@ PyObject* Application::sSaveDocumentAs(PyObject * /*self*/, PyObject *args)
|
||||
#endif
|
||||
PyObject* Application::sActiveDocument(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, "")) // convert args: Python->C
|
||||
return NULL; // NULL triggers exception
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
return nullptr;
|
||||
|
||||
Document* doc = GetApplication().getActiveDocument();
|
||||
if (doc) {
|
||||
@@ -380,13 +380,13 @@ PyObject* Application::sActiveDocument(PyObject * /*self*/, PyObject *args)
|
||||
PyObject* Application::sGetDocument(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
char *pstr=0;
|
||||
if (!PyArg_ParseTuple(args, "s", &pstr)) // convert args: Python->C
|
||||
return NULL; // NULL triggers exception
|
||||
if (!PyArg_ParseTuple(args, "s", &pstr))
|
||||
return nullptr;
|
||||
|
||||
Document* doc = GetApplication().getDocument(pstr);
|
||||
if ( !doc ) {
|
||||
PyErr_Format(PyExc_NameError, "Unknown document '%s'", pstr);
|
||||
return 0L;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return doc->getPyObject();
|
||||
@@ -395,8 +395,8 @@ PyObject* Application::sGetDocument(PyObject * /*self*/, PyObject *args)
|
||||
PyObject* Application::sGetParam(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
char *pstr=0;
|
||||
if (!PyArg_ParseTuple(args, "s", &pstr)) // convert args: Python->C
|
||||
return NULL; // NULL triggers exception
|
||||
if (!PyArg_ParseTuple(args, "s", &pstr))
|
||||
return nullptr;
|
||||
|
||||
PY_TRY {
|
||||
return GetPyObject(GetApplication().GetParameterGroupByPath(pstr));
|
||||
@@ -407,7 +407,7 @@ PyObject* Application::sSaveParameter(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
char *pstr = "User parameter";
|
||||
if (!PyArg_ParseTuple(args, "|s", &pstr))
|
||||
return NULL;
|
||||
return nullptr;
|
||||
|
||||
PY_TRY {
|
||||
ParameterManager* param = App::GetApplication().GetParameterSet(pstr);
|
||||
@@ -415,13 +415,13 @@ PyObject* Application::sSaveParameter(PyObject * /*self*/, PyObject *args)
|
||||
std::stringstream str;
|
||||
str << "No parameter set found with name: " << pstr;
|
||||
PyErr_SetString(PyExc_ValueError, str.str().c_str());
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
else if (!param->HasSerializer()) {
|
||||
std::stringstream str;
|
||||
str << "Parameter set cannot be serialized: " << pstr;
|
||||
PyErr_SetString(PyExc_RuntimeError, str.str().c_str());
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
param->SaveDocument();
|
||||
@@ -435,8 +435,8 @@ PyObject* Application::sGetConfig(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
char *pstr;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s", &pstr)) // convert args: Python->C
|
||||
return NULL; // NULL triggers exception
|
||||
if (!PyArg_ParseTuple(args, "s", &pstr))
|
||||
return nullptr;
|
||||
const std::map<std::string, std::string>& Map = GetApplication().Config();
|
||||
|
||||
std::map<std::string, std::string>::const_iterator it = Map.find(pstr);
|
||||
@@ -451,8 +451,8 @@ PyObject* Application::sGetConfig(PyObject * /*self*/, PyObject *args)
|
||||
|
||||
PyObject* Application::sDumpConfig(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, "") ) // convert args: Python->C
|
||||
return NULL; // NULL triggers exception
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
return nullptr;
|
||||
|
||||
PyObject *dict = PyDict_New();
|
||||
for (std::map<std::string,std::string>::iterator It= GetApplication()._mConfig.begin();
|
||||
@@ -466,8 +466,8 @@ PyObject* Application::sSetConfig(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
char *pstr,*pstr2;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "ss", &pstr,&pstr2)) // convert args: Python->C
|
||||
return NULL; // NULL triggers exception
|
||||
if (!PyArg_ParseTuple(args, "ss", &pstr,&pstr2))
|
||||
return nullptr;
|
||||
|
||||
GetApplication()._mConfig[pstr] = pstr2;
|
||||
|
||||
@@ -477,8 +477,8 @@ PyObject* Application::sSetConfig(PyObject * /*self*/, PyObject *args)
|
||||
|
||||
PyObject* Application::sGetVersion(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, "")) // convert args: Python->C
|
||||
return NULL; // NULL triggers exception
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
return nullptr;
|
||||
|
||||
Py::List list;
|
||||
const std::map<std::string, std::string>& cfg = Application::Config();
|
||||
@@ -515,7 +515,7 @@ PyObject* Application::sAddImportType(PyObject * /*self*/, PyObject *args)
|
||||
char *psKey,*psMod;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "ss", &psKey,&psMod))
|
||||
return NULL;
|
||||
return nullptr;
|
||||
|
||||
GetApplication().addImportType(psKey,psMod);
|
||||
|
||||
@@ -538,8 +538,8 @@ PyObject* Application::sGetImportType(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
char* psKey=0;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "|s", &psKey)) // convert args: Python->C
|
||||
return NULL; // NULL triggers exception
|
||||
if (!PyArg_ParseTuple(args, "|s", &psKey))
|
||||
return nullptr;
|
||||
|
||||
if (psKey) {
|
||||
Py::List list;
|
||||
@@ -579,7 +579,7 @@ PyObject* Application::sAddExportType(PyObject * /*self*/, PyObject *args)
|
||||
char *psKey,*psMod;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "ss", &psKey,&psMod))
|
||||
return NULL;
|
||||
return nullptr;
|
||||
|
||||
GetApplication().addExportType(psKey,psMod);
|
||||
|
||||
@@ -602,8 +602,8 @@ PyObject* Application::sGetExportType(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
char* psKey=0;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "|s", &psKey)) // convert args: Python->C
|
||||
return NULL; // NULL triggers exception
|
||||
if (!PyArg_ParseTuple(args, "|s", &psKey))
|
||||
return nullptr;
|
||||
|
||||
if (psKey) {
|
||||
Py::List list;
|
||||
@@ -721,8 +721,8 @@ PyObject* Application::sGetHomePath(PyObject * /*self*/, PyObject *args)
|
||||
PyObject* Application::sListDocuments(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
PyObject *sort = Py_False;
|
||||
if (!PyArg_ParseTuple(args, "|O",&sort)) // convert args: Python->C
|
||||
return NULL; // NULL triggers exception
|
||||
if (!PyArg_ParseTuple(args, "|O",&sort))
|
||||
return nullptr;
|
||||
PY_TRY {
|
||||
PyObject *pDict = PyDict_New();
|
||||
PyObject *pKey;
|
||||
@@ -749,7 +749,7 @@ PyObject* Application::sAddDocObserver(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
PyObject* o;
|
||||
if (!PyArg_ParseTuple(args, "O",&o))
|
||||
return NULL;
|
||||
return nullptr;
|
||||
PY_TRY {
|
||||
DocumentObserverPython::addObserver(Py::Object(o));
|
||||
Py_Return;
|
||||
@@ -760,7 +760,7 @@ PyObject* Application::sRemoveDocObserver(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
PyObject* o;
|
||||
if (!PyArg_ParseTuple(args, "O",&o))
|
||||
return NULL;
|
||||
return nullptr;
|
||||
PY_TRY {
|
||||
DocumentObserverPython::removeObserver(Py::Object(o));
|
||||
Py_Return;
|
||||
@@ -772,7 +772,7 @@ PyObject *Application::sSetLogLevel(PyObject * /*self*/, PyObject *args)
|
||||
char *tag;
|
||||
PyObject *pcObj;
|
||||
if (!PyArg_ParseTuple(args, "sO", &tag, &pcObj))
|
||||
return NULL;
|
||||
return nullptr;
|
||||
PY_TRY{
|
||||
int l;
|
||||
if (PyUnicode_Check(pcObj)) {
|
||||
@@ -792,7 +792,7 @@ PyObject *Application::sSetLogLevel(PyObject * /*self*/, PyObject *args)
|
||||
else {
|
||||
Py_Error(Base::BaseExceptionFreeCADError,
|
||||
"Unknown Log Level (use 'Default', 'Error', 'Warning', 'Message', 'Log', 'Trace' or an integer)");
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
}else
|
||||
l = PyLong_AsLong(pcObj);
|
||||
@@ -816,7 +816,7 @@ PyObject *Application::sGetLogLevel(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
char *tag;
|
||||
if (!PyArg_ParseTuple(args, "s", &tag))
|
||||
return NULL;
|
||||
return nullptr;
|
||||
|
||||
PY_TRY{
|
||||
int l = -1;
|
||||
@@ -856,7 +856,7 @@ PyObject *Application::sCheckLinkDepth(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
short depth = 0;
|
||||
if (!PyArg_ParseTuple(args, "h", &depth))
|
||||
return NULL;
|
||||
return nullptr;
|
||||
|
||||
PY_TRY {
|
||||
return Py::new_reference_to(Py::Int(GetApplication().checkLinkDepth(depth,false)));
|
||||
@@ -869,7 +869,7 @@ PyObject *Application::sGetLinksTo(PyObject * /*self*/, PyObject *args)
|
||||
int options = 0;
|
||||
short count = 0;
|
||||
if (!PyArg_ParseTuple(args, "|Oih",&pyobj,&options, &count))
|
||||
return NULL;
|
||||
return nullptr;
|
||||
|
||||
PY_TRY {
|
||||
DocumentObject *obj = 0;
|
||||
@@ -894,24 +894,27 @@ PyObject *Application::sGetDependentObjects(PyObject * /*self*/, PyObject *args)
|
||||
PyObject *obj;
|
||||
int options = 0;
|
||||
if (!PyArg_ParseTuple(args, "O|i", &obj,&options))
|
||||
return 0;
|
||||
return nullptr;
|
||||
|
||||
std::vector<App::DocumentObject*> objs;
|
||||
if(PySequence_Check(obj)) {
|
||||
if (PySequence_Check(obj)) {
|
||||
Py::Sequence seq(obj);
|
||||
for(Py_ssize_t i=0;i<seq.size();++i) {
|
||||
for (Py_ssize_t i=0;i<seq.size();++i) {
|
||||
if(!PyObject_TypeCheck(seq[i].ptr(),&DocumentObjectPy::Type)) {
|
||||
PyErr_SetString(PyExc_TypeError, "Expect element in sequence to be of type document object");
|
||||
return 0;
|
||||
}
|
||||
objs.push_back(static_cast<DocumentObjectPy*>(seq[i].ptr())->getDocumentObjectPtr());
|
||||
}
|
||||
}else if(!PyObject_TypeCheck(obj,&DocumentObjectPy::Type)) {
|
||||
}
|
||||
else if(!PyObject_TypeCheck(obj,&DocumentObjectPy::Type)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"Expect first argument to be either a document object or sequence of document objects");
|
||||
return 0;
|
||||
}else
|
||||
return nullptr;
|
||||
}
|
||||
else {
|
||||
objs.push_back(static_cast<DocumentObjectPy*>(obj)->getDocumentObjectPtr());
|
||||
}
|
||||
|
||||
PY_TRY {
|
||||
auto ret = App::Document::getDependencyList(objs,options);
|
||||
@@ -929,7 +932,7 @@ PyObject *Application::sSetActiveTransaction(PyObject * /*self*/, PyObject *args
|
||||
char *name;
|
||||
PyObject *persist = Py_False;
|
||||
if (!PyArg_ParseTuple(args, "s|O", &name,&persist))
|
||||
return 0;
|
||||
return nullptr;
|
||||
|
||||
PY_TRY {
|
||||
Py::Int ret(GetApplication().setActiveTransaction(name,PyObject_IsTrue(persist)));
|
||||
@@ -940,7 +943,7 @@ PyObject *Application::sSetActiveTransaction(PyObject * /*self*/, PyObject *args
|
||||
PyObject *Application::sGetActiveTransaction(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
return 0;
|
||||
return nullptr;
|
||||
|
||||
PY_TRY {
|
||||
int id = 0;
|
||||
@@ -959,7 +962,7 @@ PyObject *Application::sCloseActiveTransaction(PyObject * /*self*/, PyObject *ar
|
||||
PyObject *abort = Py_False;
|
||||
int id = 0;
|
||||
if (!PyArg_ParseTuple(args, "|Oi", &abort,&id))
|
||||
return 0;
|
||||
return nullptr;
|
||||
|
||||
PY_TRY {
|
||||
GetApplication().closeActiveTransaction(PyObject_IsTrue(abort),id);
|
||||
@@ -970,7 +973,7 @@ PyObject *Application::sCloseActiveTransaction(PyObject * /*self*/, PyObject *ar
|
||||
PyObject *Application::sCheckAbort(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, ""))
|
||||
return 0;
|
||||
return nullptr;
|
||||
|
||||
PY_TRY {
|
||||
Base::Sequencer().checkAbort();
|
||||
|
||||
Reference in New Issue
Block a user