Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90319376
python_functor.cc
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Oct 31, 11:34
Size
2 KB
Mime Type
text/x-c
Expires
Sat, Nov 2, 11:34 (2 d)
Engine
blob
Format
Raw Data
Handle
21969424
Attached To
rAKA akantu
python_functor.cc
View Options
/**
* @file python_functor.cc
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
*
* @date creation: Thu Feb 21 2013
* @date last modification: Fri Nov 13 2015
*
* @brief Python functor interface
*
* @section LICENSE
*
* Copyright (©) 2014, 2015 EPFL (Ecole Polytechnique Fédérale de Lausanne)
* Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)
*
* Akantu is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* Akantu is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Akantu. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* -------------------------------------------------------------------------- */
#include <vector>
#include "python_functor.hh"
#include "aka_common.hh"
/* -------------------------------------------------------------------------- */
namespace
akantu
{
/* -------------------------------------------------------------------------- */
PythonFunctor
::
PythonFunctor
(
PyObject
*
obj
)
:
python_obj
(
obj
){
}
/* -------------------------------------------------------------------------- */
PyObject
*
PythonFunctor
::
callFunctor
(
PyObject
*
functor
,
PyObject
*
args
,
PyObject
*
kwargs
)
const
{
if
(
!
PyCallable_Check
(
functor
))
AKANTU_EXCEPTION
(
"Provided functor is not a function"
);
PyObject
*
pValue
=
PyObject_Call
(
functor
,
args
,
kwargs
);
PyObject
*
exception_type
=
PyErr_Occurred
();
if
(
exception_type
){
PyObject
*
exception
;
PyObject
*
traceback
;
PyErr_Fetch
(
&
exception_type
,
&
exception
,
&
traceback
);
PyObject_Print
(
exception_type
,
stdout
,
Py_PRINT_RAW
);
PyObject_Print
(
exception
,
stdout
,
Py_PRINT_RAW
);
std
::
stringstream
sstr
;
sstr
<<
"Exception occured while calling the functor: "
;
PyObject
*
exception_mesg
=
PyObject_GetAttrString
(
exception
,
"message"
);
if
(
exception_mesg
&&
PyString_Check
(
exception_mesg
))
sstr
<<
PyString_AsString
(
exception_mesg
);
else
sstr
<<
PyString_AsString
(
exception
);
AKANTU_EXCEPTION
(
sstr
.
str
());
}
return
pValue
;
}
/* -------------------------------------------------------------------------- */
}
// akantu
Event Timeline
Log In to Comment