rpnifs/python_if.h

139 lines
3.9 KiB
C

/*
* Copyright (C) 2020 Weber Yann
*
* This file is part of pyrpn.
*
* pyrpn is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* pyrpn 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with pyrpn. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _PYTHON_IF_H__
#define _PYTHON_IF_H__
#include "config.h"
#include <errno.h>
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include "structmember.h"
#include "rpn_if.h"
#include "rpn_if_default.h"
#include "python_rpnexpr.h"
/**@defgroup python_if RPN Iterated Function Python class
* @ingroup python_module
* @brief Exposed Python class : RPNIterExpr
*
* Iterated expression are composed of RPN expressions, they are able to
* iterate taking their parameters from a memory array and setting back values
* in it on each iteration.
*
* @see ifs_if
*/
/**@file python_if.h
* @brief Python RPNIterExpr type headers
* @ingroup python_if
*
* This file is the header of the RPNIterExpr Python class
*/
/**@brief A single instance of this object is used for parameters representation */
extern PyTypeObject rpnif_params_SeqDesc;
extern PyStructSequence_Desc rpnif_params_desc;
/**@brief RPNIterExpr Python class methods list
* @ingroup python_if */
extern PyMethodDef RPNIterExpr_methods[];
/**@brief RPNIterExpr Python class members list
* @ingroup python_if */
extern PyMemberDef RPNIterExpr_members[];
/**@brief RPNIterExpr Python class type definition
* @ingroup python_if */
extern PyTypeObject RPNIterExprType;
/**@brief Structure holding RPNIterExpr objects
* @ingroup python_if */
typedef struct
{
PyObject_VAR_HEAD;
/** @brief Number of dimention in map */
size_t ndim;
/**@brief Pointer on @ref rpn_if_s */
rpn_if_t *rif;
} PyRPNIterExpr_t;
/**@brief RpnIterExpr __new__ method
* @param subtype Type of object being created (pyrpn.RPNIterExpr)
* @param args positional arguments for subtype
* @param kwargs keyword argumenrs for subtype
* @return The new Python RPNIterExpr object
*/
PyObject* rpnif_new(PyTypeObject *subtype, PyObject* args, PyObject* kwds);
/**@brief RpnIterExpr constructor
* @param self New RPNIterExpr instance
* @param args Positional arguments list
* @param kwds Keywords arguments dict
* @return 0 if no error else -1
* @ingroup python_if
*/
int rpnif_init(PyObject *self, PyObject *args, PyObject *kwds);
/**@brief RPNIterExpr __del__ method
* @param self RPNExpr instance
* @ingroup python_type
*/
void rpnif_del(PyObject *self);
int rpnif_getbuffer(PyObject *self, Py_buffer *view, int flags);
void rpnif_releasebuffer(PyObject *self, Py_buffer *view);
PyObject *rpnif_get_params(PyObject *self);
/**@brief RPNIterExpr __getstate__ method for pickling
* @param cls RPNIterExpr type object
* @param noargs Not an argument...
* @return A bytes Python instance suitable as argument for
* @ref rpnexpr_setstate
*/
PyObject* rpnif_getstate(PyObject *cls, PyObject *noargs);
/**@brief RPNIterExpr __setstate__ method for pickling
* @param cls RPNIterExpr type object
* @param state Should by a bytes Python instance returned by @ref
* rpnexpr_getstate
* @return A bytes Python instance suitable as argument for
* @ref rpnexpr_setstate
*/
PyObject* rpnif_setstate(PyObject *cls, PyObject *state);
/**@brief RPNIterExpr.__repr__()
* @param self RPNIterExpr instance
* @ingroup python_type
*/
PyObject* rpnif_repr(PyObject *self);
/**@brief RPNIterExpr.__str__()
* @param self RPNIterExpr instance
* @ingroup python_type
*/
PyObject* rpnif_str(PyObject *self);
#endif