yading@11: /* yading@11: * Copyright (c) 2002 Michael Niedermayer yading@11: * yading@11: * This file is part of FFmpeg. yading@11: * yading@11: * FFmpeg is free software; you can redistribute it and/or yading@11: * modify it under the terms of the GNU Lesser General Public yading@11: * License as published by the Free Software Foundation; either yading@11: * version 2.1 of the License, or (at your option) any later version. yading@11: * yading@11: * FFmpeg is distributed in the hope that it will be useful, yading@11: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@11: * Lesser General Public License for more details. yading@11: * yading@11: * You should have received a copy of the GNU Lesser General Public yading@11: * License along with FFmpeg; if not, write to the Free Software yading@11: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@11: */ yading@11: yading@11: /** yading@11: * @file yading@11: * simple arithmetic expression evaluator yading@11: */ yading@11: yading@11: #ifndef AVUTIL_EVAL_H yading@11: #define AVUTIL_EVAL_H yading@11: yading@11: #include "avutil.h" yading@11: yading@11: typedef struct AVExpr AVExpr; yading@11: yading@11: /** yading@11: * Parse and evaluate an expression. yading@11: * Note, this is significantly slower than av_expr_eval(). yading@11: * yading@11: * @param res a pointer to a double where is put the result value of yading@11: * the expression, or NAN in case of error yading@11: * @param s expression as a zero terminated string, for example "1+2^3+5*5+sin(2/3)" yading@11: * @param const_names NULL terminated array of zero terminated strings of constant identifiers, for example {"PI", "E", 0} yading@11: * @param const_values a zero terminated array of values for the identifiers from const_names yading@11: * @param func1_names NULL terminated array of zero terminated strings of funcs1 identifiers yading@11: * @param funcs1 NULL terminated array of function pointers for functions which take 1 argument yading@11: * @param func2_names NULL terminated array of zero terminated strings of funcs2 identifiers yading@11: * @param funcs2 NULL terminated array of function pointers for functions which take 2 arguments yading@11: * @param opaque a pointer which will be passed to all functions from funcs1 and funcs2 yading@11: * @param log_ctx parent logging context yading@11: * @return 0 in case of success, a negative value corresponding to an yading@11: * AVERROR code otherwise yading@11: */ yading@11: int av_expr_parse_and_eval(double *res, const char *s, yading@11: const char * const *const_names, const double *const_values, yading@11: const char * const *func1_names, double (* const *funcs1)(void *, double), yading@11: const char * const *func2_names, double (* const *funcs2)(void *, double, double), yading@11: void *opaque, int log_offset, void *log_ctx); yading@11: yading@11: /** yading@11: * Parse an expression. yading@11: * yading@11: * @param expr a pointer where is put an AVExpr containing the parsed yading@11: * value in case of successful parsing, or NULL otherwise. yading@11: * The pointed to AVExpr must be freed with av_expr_free() by the user yading@11: * when it is not needed anymore. yading@11: * @param s expression as a zero terminated string, for example "1+2^3+5*5+sin(2/3)" yading@11: * @param const_names NULL terminated array of zero terminated strings of constant identifiers, for example {"PI", "E", 0} yading@11: * @param func1_names NULL terminated array of zero terminated strings of funcs1 identifiers yading@11: * @param funcs1 NULL terminated array of function pointers for functions which take 1 argument yading@11: * @param func2_names NULL terminated array of zero terminated strings of funcs2 identifiers yading@11: * @param funcs2 NULL terminated array of function pointers for functions which take 2 arguments yading@11: * @param log_ctx parent logging context yading@11: * @return 0 in case of success, a negative value corresponding to an yading@11: * AVERROR code otherwise yading@11: */ yading@11: int av_expr_parse(AVExpr **expr, const char *s, yading@11: const char * const *const_names, yading@11: const char * const *func1_names, double (* const *funcs1)(void *, double), yading@11: const char * const *func2_names, double (* const *funcs2)(void *, double, double), yading@11: int log_offset, void *log_ctx); yading@11: yading@11: /** yading@11: * Evaluate a previously parsed expression. yading@11: * yading@11: * @param const_values a zero terminated array of values for the identifiers from av_expr_parse() const_names yading@11: * @param opaque a pointer which will be passed to all functions from funcs1 and funcs2 yading@11: * @return the value of the expression yading@11: */ yading@11: double av_expr_eval(AVExpr *e, const double *const_values, void *opaque); yading@11: yading@11: /** yading@11: * Free a parsed expression previously created with av_expr_parse(). yading@11: */ yading@11: void av_expr_free(AVExpr *e); yading@11: yading@11: /** yading@11: * Parse the string in numstr and return its value as a double. If yading@11: * the string is empty, contains only whitespaces, or does not contain yading@11: * an initial substring that has the expected syntax for a yading@11: * floating-point number, no conversion is performed. In this case, yading@11: * returns a value of zero and the value returned in tail is the value yading@11: * of numstr. yading@11: * yading@11: * @param numstr a string representing a number, may contain one of yading@11: * the International System number postfixes, for example 'K', 'M', yading@11: * 'G'. If 'i' is appended after the postfix, powers of 2 are used yading@11: * instead of powers of 10. The 'B' postfix multiplies the value for yading@11: * 8, and can be appended after another postfix or used alone. This yading@11: * allows using for example 'KB', 'MiB', 'G' and 'B' as postfix. yading@11: * @param tail if non-NULL puts here the pointer to the char next yading@11: * after the last parsed character yading@11: */ yading@11: double av_strtod(const char *numstr, char **tail); yading@11: yading@11: #endif /* AVUTIL_EVAL_H */