Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F90447924
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
Fri, Nov 1, 18:41
Size
2 KB
Mime Type
text/x-c
Expires
Sun, Nov 3, 18:41 (1 d, 22 h)
Engine
blob
Format
Raw Data
Handle
22063058
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"
/* -------------------------------------------------------------------------- */
__BEGIN_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
;
}
/* -------------------------------------------------------------------------- */
__END_AKANTU__
Event Timeline
Log In to Comment