rpnifs/rpn_if_default.h

165 lines
5.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 __rpn_if_default__h__
#define __rpn_if_default__h__
/**@file rpn_if_default.h Defines default IF
* @ingroup ifs_if_default
* @ingroup ifs_if
* @brief Default IF definitions
*/
/**@defgroup ifs_if_default Default functions
* @ingroup ifs_if
* @brief Simple iterated functions functions
*
* Defines default @ref rpn_if_param_s.res_f and @ref rpn_if_param_s.arg_f
* functions.
*/
#include "config.h"
#include "rpn_if.h"
/**@weakgroup ifs_if_default_posflag Default IF position flags
* @ingroup ifs_if_default
* @{ */
#define RPN_IF_POSITION_LINEAR 0 ///< One expr for position
#define RPN_IF_POSITION_XY 1 ///< two expr for position
#define RPN_IF_POSITION_XDIM 2 ///< X expr for position
#define RPN_IF_POSITION_OF_LOOP 0 ///< Loop on position overflow
#define RPN_IF_POSITION_OF_ERR 16 ///< Trigger error on position overflow
/**@}*/
/**@weakgroup ifs_if_default_resflag Default IF position flags
* @ingroup ifs_if_default
* @{ */
#define RPN_IF_RES_BOOL 0 ///< Set to one when position occurs
#define RPN_IF_RES_CONST 1 ///< Set to a constant value
#define RPN_IF_RES_CONST_RGBA 2 ///< Set to a constant RGB using alpha channel
#define RPN_IF_RES_COUNT 3 ///< Count number of time position occurs
#define RPN_IF_RES_XFUN 4 ///< Set to result of rpn_expr
#define RPN_IF_RES_RGB 5 ///< Set result to RGB color from rpn_expr
#define RPN_IF_RES_RGBA 6 ///< Set result to RGB using alpha channel from rpn_expr
/**@}*/
/**@brief Alias for struct @ref rpn_if_default_data_s */
typedef struct rpn_if_default_data_s rpn_if_default_data_t;
/**@brief Stores default IF data
*
* Stores flags and size limit
*/
struct rpn_if_default_data_s
{
/**@brief Flag defining position coordinate handling */
short pos_flag;
/**@brief Flag defining result handling */
short res_flag;
/**@brief Stores size limits given pos_flag
*
* @note If NULL no limit
* - For @ref RPN_IF_POSITION_LINEAR size_lim is a single size_t
* - For @ref RPN_IF_POSITION_XY size_lim is two size_t (height and width)
* - For @ref RPN_IF_POSITION_XDIM *size_lim is the size of size_lim
*/
size_t *size_lim;
/**@brief Store constant values to set mem giver res_flag
* - For @ref RPN_IF_RES_CONST const_val points on a single value
* - For @ref RPN_IF_RES_CONST_RGBA const_val points on 4 values
* - Else const_val is set to NULL
*/
rpn_value_t *const_val;
};
/**@brief Create a new @ref rpn_if_param_s corresponding to given flags
* @ingroup ifs_if_default
*
* @param pos_flag Binary OR combination of RPN_IF_POSITION_*
* (@ref ifs_if_default_posflag )
* @param pos_flag Binary OR combination of RPN_IF_RES_*
* (@ref ifs_if_default_posflag )
* @param lim Depends on pos_flag parameter (
* see @ref rpn_if_default_data_s::size_lim )
* @param val Depends on res_flag parameter (
* see @ref rpn_if_default_data_s::const_val )
* @returns A new @ref rpn_if_param_t or NULL on error
* @todo Implementation/testing
*/
rpn_if_param_t* rpn_if_default_params(short pos_flag, short res_flag,
const size_t *lim, const rpn_value_t *val, unsigned char rpn_stack_sz);
/**@brief Default argf function ( see @ref rpn_if_param_s.arg_f ) */
int rpn_if_argf_default(rpn_if_t *rif, size_t pos, rpn_value_t *args);
/**@brief Default result function ( see @ref rpn_if_param_s.res_f ) */
int rpn_if_resf_default(rpn_if_t *rif, size_t *pos, rpn_value_t *data);
/**@brief Set the first expression argument from position
* @param rif Expressions
* @param pos Memory map offset
* @param args pointer on expressions arguments
* @note Other arguments are set using the generic @ref rpn_if_argf_default
* function
*/
int rpn_if_argf_linear(rpn_if_t *rif, size_t pos, rpn_value_t *args);
/**@brief Transform 1st expression result to position
* @param rif Expressions
* @param pos Pointer on resulting position in memory map
* @param data Pointer on resulting data
* @note Data from position fecth is done by generic @ref rpn_if_resf_default
* function
*/
int rpn_if_resf_linear(rpn_if_t *rif, size_t *pos, rpn_value_t *data);
/**@brief Set the 1st & 2nd argument from position
* @param rif Expressions
* @param pos Memory map offset
* @param args pointer on expression arguments
* @note Other arguments are set using the generic @ref rpn_if_argf_default
* function
*/
int rpn_if_argf_xy(rpn_if_t *rif, size_t pos, rpn_value_t *args);
/**@brief Transform 1st and 2nd result into a memory map's offset
* @param rif Expressions
* @param pos Memory map offset pointer
* @param data Pointer on resulting data
* @note Data from position fetch is done by generic @ref rpn_if_resf_default
* function
*/
int rpn_if_resf_xy(rpn_if_t *rif, size_t *pos, rpn_value_t *data);
/**@brief Set X first arguments from position
* @param rif Expressions
* @param pos Memory map offset
* @param args Pointer on expression arguments
* @note Other arguments are set using the generic @ref rpn_if_argf_default
* function
*/
int rpn_if_argf_xdim(rpn_if_t *rif, size_t pos, rpn_value_t *args);
/**@brief Transform X arguments into a memory map's offset
* @param rif Expressions
* @param pos Memory map offset pointer
* @param data Pointer on resulting data
* @note Data from position fetch is done by generic @ref rpn_if_resf_default
* function
*/
int rpn_if_resf_xdim(rpn_if_t *rif, size_t *pos, rpn_value_t *data);
#endif