]> git.sesse.net Git - ffmpeg/blob - libavutil/eval.h
Fix grammar errors in documentation
[ffmpeg] / libavutil / eval.h
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_eval_expr().
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_ctx parent logging context
46  * @return 0 in case of success, a negative value corresponding to an
47  * AVERROR code otherwise
48  */
49 int av_parse_and_eval_expr(double *res, const char *s,
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),
53                            void *opaque, int log_offset, void *log_ctx);
54
55 /**
56  * Parse an expression.
57  *
58  * @param expr a pointer where is put an AVExpr containing the parsed
59  * value in case of successfull parsing, or NULL otherwise.
60  * The pointed to AVExpr must be freed with av_free_expr() by the user
61  * when it is not needed anymore.
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
65  * @param funcs1 NULL terminated array of function pointers for functions which take 1 argument
66  * @param func2_names NULL terminated array of zero terminated strings of funcs2 identifiers
67  * @param funcs2 NULL terminated array of function pointers for functions which take 2 arguments
68  * @param log_ctx parent logging context
69  * @return 0 in case of success, a negative value corresponding to an
70  * AVERROR code otherwise
71  */
72 int av_parse_expr(AVExpr **expr, const char *s,
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),
76                   int log_offset, void *log_ctx);
77
78 /**
79  * Evaluate a previously parsed expression.
80  *
81  * @param const_values a zero terminated array of values for the identifiers from av_parse_expr() const_names
82  * @param opaque a pointer which will be passed to all functions from funcs1 and funcs2
83  * @return the value of the expression
84  */
85 double av_eval_expr(AVExpr *e, const double *const_values, void *opaque);
86
87 /**
88  * Free a parsed expression previously created with av_parse_expr().
89  */
90 void av_free_expr(AVExpr *e);
91
92 /**
93  * Parse the string in numstr and return 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
108  */
109 double av_strtod(const char *numstr, char **tail);
110
111 #endif /* AVUTIL_EVAL_H */