Move eval.c and eval.h from libavcodec to libavutil, and make the eval
[libav.git] / libavutil / eval.h
CommitLineData
b2f86c17 1/*
b2f86c17
PI
2 * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
3 *
b78e7197
DB
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
b2f86c17
PI
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
b78e7197 9 * version 2.1 of the License, or (at your option) any later version.
b2f86c17 10 *
b78e7197 11 * FFmpeg is distributed in the hope that it will be useful,
b2f86c17
PI
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
b78e7197 17 * License along with FFmpeg; if not, write to the Free Software
b2f86c17
PI
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/**
ba87f080 22 * @file
8c216473 23 * simple arithmetic expression evaluator
b2f86c17
PI
24 */
25
0b99215c
SS
26#ifndef AVUTIL_EVAL_H
27#define AVUTIL_EVAL_H
b2f86c17 28
a3731cad 29typedef struct AVExpr AVExpr;
5fccafdb 30
21d4d5da
MN
31/**
32 * Parses and evaluates an expression.
0b99215c 33 * Note, this is significantly slower than av_eval_expr().
f54978f1 34 *
9ace13b4
SS
35 * @param res a pointer to a double where is put the result value of
36 * the expression, or NAN in case of error
94f49823
SS
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
9711439b 41 * @param funcs1 NULL terminated array of function pointers for functions which take 1 argument
94f49823 42 * @param func2_names NULL terminated array of zero terminated strings of funcs2 identifiers
9711439b
SS
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
2b65bb45 45 * @param log_ctx parent logging context
9ace13b4
SS
46 * @return 0 in case of success, a negative value corresponding to an
47 * AVERROR code otherwise
21d4d5da 48 */
0b99215c 49int av_parse_and_eval_expr(double *res, const char *s,
9711439b
SS
50 const char * const *const_names, const double *const_values,
51 const char * const *func1_names, double (* const *funcs1)(void *, double),
52 const char * const *func2_names, double (* const *funcs2)(void *, double, double),
b851dd9e 53 void *opaque, int log_offset, void *log_ctx);
b2f86c17 54
21d4d5da 55/**
94e57758 56 * Parses an expression.
f54978f1 57 *
9ace13b4
SS
58 * @param expr a pointer where is put an AVExpr containing the parsed
59 * value in case of successfull parsing, or NULL otherwise.
0b99215c 60 * The pointed to AVExpr must be freed with av_free_expr() by the user
9ace13b4 61 * when it is not needed anymore.
94f49823
SS
62 * @param s expression as a zero terminated string, for example "1+2^3+5*5+sin(2/3)"
63 * @param const_names NULL terminated array of zero terminated strings of constant identifiers, for example {"PI", "E", 0}
64 * @param func1_names NULL terminated array of zero terminated strings of funcs1 identifiers
9711439b 65 * @param funcs1 NULL terminated array of function pointers for functions which take 1 argument
94f49823 66 * @param func2_names NULL terminated array of zero terminated strings of funcs2 identifiers
9711439b 67 * @param funcs2 NULL terminated array of function pointers for functions which take 2 arguments
2b65bb45 68 * @param log_ctx parent logging context
9ace13b4
SS
69 * @return 0 in case of success, a negative value corresponding to an
70 * AVERROR code otherwise
21d4d5da 71 */
0b99215c 72int av_parse_expr(AVExpr **expr, const char *s,
9711439b
SS
73 const char * const *const_names,
74 const char * const *func1_names, double (* const *funcs1)(void *, double),
75 const char * const *func2_names, double (* const *funcs2)(void *, double, double),
b851dd9e 76 int log_offset, void *log_ctx);
f54978f1 77
21d4d5da
MN
78/**
79 * Evaluates a previously parsed expression.
f54978f1 80 *
0b99215c 81 * @param const_values a zero terminated array of values for the identifiers from av_parse_expr() const_names
9711439b 82 * @param opaque a pointer which will be passed to all functions from funcs1 and funcs2
21d4d5da
MN
83 * @return the value of the expression
84 */
0b99215c 85double av_eval_expr(AVExpr *e, const double *const_values, void *opaque);
f8fea468 86
80ed7014 87/**
0b99215c 88 * Frees a parsed expression previously created with av_parse_expr().
80ed7014 89 */
0b99215c 90void av_free_expr(AVExpr *e);
85b4eb08 91
d171a651
SS
92/**
93 * Parses the string in numstr and returns its value as a double. If
94 * the string is empty, contains only whitespaces, or does not contain
95 * an initial substring that has the expected syntax for a
96 * floating-point number, no conversion is performed. In this case,
97 * returns a value of zero and the value returned in tail is the value
98 * of numstr.
99 *
100 * @param numstr a string representing a number, may contain one of
101 * the International System number postfixes, for example 'K', 'M',
102 * 'G'. If 'i' is appended after the postfix, powers of 2 are used
103 * instead of powers of 10. The 'B' postfix multiplies the value for
104 * 8, and can be appended after another postfix or used alone. This
105 * allows using for example 'KB', 'MiB', 'G' and 'B' as postfix.
106 * @param tail if non-NULL puts here the pointer to the char next
107 * after the last parsed character
1c2744d1
SS
108 */
109double av_strtod(const char *numstr, char **tail);
110
0b99215c 111#endif /* AVUTIL_EVAL_H */