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