123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- /*
- * 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_MUTATION_H__
- #define _PYTHON_MUTATION_H__
-
- #include "config.h"
-
- #include <errno.h>
- #include <float.h>
-
- #define PY_SSIZE_T_CLEAN
- #include <Python.h>
- #include "structmember.h"
-
- #include "python_const.h"
- #include "rpn_mutate.h"
- #include "rpn_if_mutate.h"
- #include "rpn_ifs_mutate.h"
-
- /**@file python_mutation.h
- * @brief Python types (named tuple) & utility to manipulate mutation
- * parameters
- * @ingroup python_ext
- */
-
-
- /**@defgroup pymod_pyrpn_RPNMutationParams pyrpn.RPNMutationParams
- * @brief namedtuple storing mutation parameters
- * @ingroup pymod_pyrpn */
- /**@brief RPNMutationParams named tuple with mutation parameters */
- extern PyTypeObject rpn_mutation_params_SeqDesc;
- /**@brief @ref rpn_mutation_params_SeqDesc named tuple description */
- extern PyStructSequence_Desc rpn_mutation_params_desc;
-
-
- extern PyTypeObject ifs_mutation_weights_SeqDesc;
- extern PyStructSequence_Desc ifs_mutation_weights_desc;
-
-
- /**@brief Initialize mutation related types & stuff. Adds references
- * to pyrpn module given in argument
- * @param pyrpn_mod pyrpn python module instance
- * @return 0 if no error else -1 */
- int pyrpn_python_mutation_init(PyObject *pyrpn_mod);
-
- /**@brief Try to convert a python object into a rpn_mutation_params_t
- * @param py_params The python object
- * @param params A pointer on the parameters to initialize
- * @return -1 on failure and raise an exception
- * @ingroup pymod_pyrpn_RPNExpr
- */
- int pyrpn_pyobj_to_mutation_params(PyObject* py_params, rpn_mutation_params_t *params);
-
- int pyrpn_mutation_params_to_pyobj(const rpn_mutation_params_t *params,
- PyObject **res);
-
-
- int pyrpn_pyobj_to_ifs_mutation_weights(PyObject *py_params,
- ifs_mutation_weights_t *w);
-
- int pyrpn_ifs_mut_weight_to_pyobj(const ifs_mutation_weights_t *w,
- PyObject **mut_weights);
-
- /**@brief Set the mutation type weight from a PyObject* sequence
- * @param w The IFS mutation weight structure to edit
- * @param mut_type_weight Should be a sequence of 2 float values
- * @return 0 if OK -1 on error (and PyErr_Occurred() == true)
- */
- int pyrpn_ifs_mut_params_mut_type_weight(ifs_mutation_weights_t *w,
- PyObject *mut_type_weight);
-
- /**@brief Set the mutation weight range from a PyObject* sequence
- * @param w The IFS mutation weight structure to edit
- * @param weight_range Should be a sequence of 2 float values
- * @return 0 if OK -1 on error (and PyErr_Occurred() == true)
- */
- int pyrpn_ifs_mut_params_weight_range(ifs_mutation_weights_t *w,
- PyObject *weight_range);
-
- /**@brief Set the IF mutation weight from a PyObject* sequence
- * @note Check that the sequence length correspond to the if_count
- * in the ifs_mutation_weights_t struct
- * @note If current w_mut_if field is NULL allocate it
- * @param w The IFS mutation weight structure to edit
- * @param weight_range Should be a sequence of if_count float values
- * @param do_realloc If != 0 reallocate the w_mut_if field to correspond to
- * if_count
- * @return 0 if OK -1 on error (and PyErr_Occurred() == true)
- */
- int pyrpn_ifs_mut_params_weight_mut_if(ifs_mutation_weights_t *w,
- PyObject *mut_if_weight, short do_realloc);
-
- /**@brief Set the IF component weights from a PyObject* sequence
- * @note The function cannot check the length validity of the given
- * sequence (except that empty sequence are invalid).
- * @param w The IFS mutation weight structure to edit
- * @param mut_type_weight Should be a sequence of 2 float values
- * @return 0 if OK -1 on error (and PyErr_Occurred() == true)
- */
- int pyrpn_ifs_mut_params_if_comp_weight(ifs_mutation_weights_t *w,
- PyObject *if_comp_weight);
-
- /**@brief Set the RPN mutation parameters from a PyObject*
- * @param w The IFS mutation weight structure to edit
- * @param mutation_params Can be a valid value for a RPNMutationParams
- * or a sequence of valid values for a RPNMutationParams
- * of len w->if_count
- * @return 0 if OK -1 on error (and PyErr_Occurred() == true)
- */
- int pyrpn_ifs_mut_params_mutation_params(ifs_mutation_weights_t *w,
- PyObject *mutation_params);
-
- #endif
|