duckstation

duckstation, but archived from the revision just before upstream changed it to a proprietary software project, this version is the libre one
git clone https://git.neptards.moe/u3shit/duckstation.git
Log | Files | Refs | README | LICENSE

eval.h (6600B)


      1 /*
      2  * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
      3  *
      4  * This file is part of FFmpeg.
      5  *
      6  * FFmpeg is free software; you can redistribute it and/or
      7  * modify it under the terms of the GNU Lesser General Public
      8  * License as published by the Free Software Foundation; either
      9  * version 2.1 of the License, or (at your option) any later version.
     10  *
     11  * FFmpeg is distributed in the hope that it will be useful,
     12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     14  * Lesser General Public License for more details.
     15  *
     16  * You should have received a copy of the GNU Lesser General Public
     17  * License along with FFmpeg; if not, write to the Free Software
     18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     19  */
     20 
     21 /**
     22  * @file
     23  * simple arithmetic expression evaluator
     24  */
     25 
     26 #ifndef AVUTIL_EVAL_H
     27 #define AVUTIL_EVAL_H
     28 
     29 typedef struct AVExpr AVExpr;
     30 
     31 /**
     32  * Parse and evaluate an expression.
     33  * Note, this is significantly slower than av_expr_eval().
     34  *
     35  * @param res a pointer to a double where is put the result value of
     36  * the expression, or NAN in case of error
     37  * @param s expression as a zero terminated string, for example "1+2^3+5*5+sin(2/3)"
     38  * @param const_names NULL terminated array of zero terminated strings of constant identifiers, for example {"PI", "E", 0}
     39  * @param const_values a zero terminated array of values for the identifiers from const_names
     40  * @param func1_names NULL terminated array of zero terminated strings of funcs1 identifiers
     41  * @param funcs1 NULL terminated array of function pointers for functions which take 1 argument
     42  * @param func2_names NULL terminated array of zero terminated strings of funcs2 identifiers
     43  * @param funcs2 NULL terminated array of function pointers for functions which take 2 arguments
     44  * @param opaque a pointer which will be passed to all functions from funcs1 and funcs2
     45  * @param log_offset log level offset, can be used to silence error messages
     46  * @param log_ctx parent logging context
     47  * @return >= 0 in case of success, a negative value corresponding to an
     48  * AVERROR code otherwise
     49  */
     50 int av_expr_parse_and_eval(double *res, const char *s,
     51                            const char * const *const_names, const double *const_values,
     52                            const char * const *func1_names, double (* const *funcs1)(void *, double),
     53                            const char * const *func2_names, double (* const *funcs2)(void *, double, double),
     54                            void *opaque, int log_offset, void *log_ctx);
     55 
     56 /**
     57  * Parse an expression.
     58  *
     59  * @param expr a pointer where is put an AVExpr containing the parsed
     60  * value in case of successful parsing, or NULL otherwise.
     61  * The pointed to AVExpr must be freed with av_expr_free() by the user
     62  * when it is not needed anymore.
     63  * @param s expression as a zero terminated string, for example "1+2^3+5*5+sin(2/3)"
     64  * @param const_names NULL terminated array of zero terminated strings of constant identifiers, for example {"PI", "E", 0}
     65  * @param func1_names NULL terminated array of zero terminated strings of funcs1 identifiers
     66  * @param funcs1 NULL terminated array of function pointers for functions which take 1 argument
     67  * @param func2_names NULL terminated array of zero terminated strings of funcs2 identifiers
     68  * @param funcs2 NULL terminated array of function pointers for functions which take 2 arguments
     69  * @param log_offset log level offset, can be used to silence error messages
     70  * @param log_ctx parent logging context
     71  * @return >= 0 in case of success, a negative value corresponding to an
     72  * AVERROR code otherwise
     73  */
     74 int av_expr_parse(AVExpr **expr, const char *s,
     75                   const char * const *const_names,
     76                   const char * const *func1_names, double (* const *funcs1)(void *, double),
     77                   const char * const *func2_names, double (* const *funcs2)(void *, double, double),
     78                   int log_offset, void *log_ctx);
     79 
     80 /**
     81  * Evaluate a previously parsed expression.
     82  *
     83  * @param e the AVExpr to evaluate
     84  * @param const_values a zero terminated array of values for the identifiers from av_expr_parse() const_names
     85  * @param opaque a pointer which will be passed to all functions from funcs1 and funcs2
     86  * @return the value of the expression
     87  */
     88 double av_expr_eval(AVExpr *e, const double *const_values, void *opaque);
     89 
     90 /**
     91  * Track the presence of variables and their number of occurrences in a parsed expression
     92  *
     93  * @param e the AVExpr to track variables in
     94  * @param counter a zero-initialized array where the count of each variable will be stored
     95  * @param size size of array
     96  * @return 0 on success, a negative value indicates that no expression or array was passed
     97  * or size was zero
     98  */
     99 int av_expr_count_vars(AVExpr *e, unsigned *counter, int size);
    100 
    101 /**
    102  * Track the presence of user provided functions and their number of occurrences
    103  * in a parsed expression.
    104  *
    105  * @param e the AVExpr to track user provided functions in
    106  * @param counter a zero-initialized array where the count of each function will be stored
    107  *                if you passed 5 functions with 2 arguments to av_expr_parse()
    108  *                then for arg=2 this will use up to 5 entries.
    109  * @param size size of array
    110  * @param arg number of arguments the counted functions have
    111  * @return 0 on success, a negative value indicates that no expression or array was passed
    112  * or size was zero
    113  */
    114 int av_expr_count_func(AVExpr *e, unsigned *counter, int size, int arg);
    115 
    116 /**
    117  * Free a parsed expression previously created with av_expr_parse().
    118  */
    119 void av_expr_free(AVExpr *e);
    120 
    121 /**
    122  * Parse the string in numstr and return its value as a double. If
    123  * the string is empty, contains only whitespaces, or does not contain
    124  * an initial substring that has the expected syntax for a
    125  * floating-point number, no conversion is performed. In this case,
    126  * returns a value of zero and the value returned in tail is the value
    127  * of numstr.
    128  *
    129  * @param numstr a string representing a number, may contain one of
    130  * the International System number postfixes, for example 'K', 'M',
    131  * 'G'. If 'i' is appended after the postfix, powers of 2 are used
    132  * instead of powers of 10. The 'B' postfix multiplies the value by
    133  * 8, and can be appended after another postfix or used alone. This
    134  * allows using for example 'KB', 'MiB', 'G' and 'B' as postfix.
    135  * @param tail if non-NULL puts here the pointer to the char next
    136  * after the last parsed character
    137  */
    138 double av_strtod(const char *numstr, char **tail);
    139 
    140 #endif /* AVUTIL_EVAL_H */