Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F96561120
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
Sat, Dec 28, 03:19
Size
2 KB
Mime Type
text/x-c
Expires
Mon, Dec 30, 03:19 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
23175995
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