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 module ffmpeg.libavutil.eval;
27 
28 extern (C):
29 import ffmpeg; @nogc nothrow:
30 
31 struct AVExpr;
32 
33 /**
34  * Parse and evaluate an expression.
35  * Note, this is significantly slower than av_expr_eval().
36  *
37  * @param res a pointer to a double where is put the result value of
38  * the expression, or NAN in case of error
39  * @param s expression as a zero terminated string, for example "1+2^3+5*5+sin(2/3)"
40  * @param const_names NULL terminated array of zero terminated strings of constant identifiers, for example {"PI", "E", 0}
41  * @param const_values a zero terminated array of values for the identifiers from const_names
42  * @param func1_names NULL terminated array of zero terminated strings of funcs1 identifiers
43  * @param funcs1 NULL terminated array of function pointers for functions which take 1 argument
44  * @param func2_names NULL terminated array of zero terminated strings of funcs2 identifiers
45  * @param funcs2 NULL terminated array of function pointers for functions which take 2 arguments
46  * @param opaque a pointer which will be passed to all functions from funcs1 and funcs2
47  * @param log_ctx parent logging context
48  * @return >= 0 in case of success, a negative value corresponding to an
49  * AVERROR code otherwise
50  */
51 int av_expr_parse_and_eval (
52     double* res,
53     const(char)* s,
54     const(char*)* const_names,
55     const(double)* const_values,
56     const(char*)* func1_names,
57     double function (void*, double)* funcs1,
58     const(char*)* func2_names,
59     double function (void*, double, double)* funcs2,
60     void* opaque,
61     int log_offset,
62     void* log_ctx);
63 
64 /**
65  * Parse an expression.
66  *
67  * @param expr a pointer where is put an AVExpr containing the parsed
68  * value in case of successful parsing, or NULL otherwise.
69  * The pointed to AVExpr must be freed with av_expr_free() by the user
70  * when it is not needed anymore.
71  * @param s expression as a zero terminated string, for example "1+2^3+5*5+sin(2/3)"
72  * @param const_names NULL terminated array of zero terminated strings of constant identifiers, for example {"PI", "E", 0}
73  * @param func1_names NULL terminated array of zero terminated strings of funcs1 identifiers
74  * @param funcs1 NULL terminated array of function pointers for functions which take 1 argument
75  * @param func2_names NULL terminated array of zero terminated strings of funcs2 identifiers
76  * @param funcs2 NULL terminated array of function pointers for functions which take 2 arguments
77  * @param log_ctx parent logging context
78  * @return >= 0 in case of success, a negative value corresponding to an
79  * AVERROR code otherwise
80  */
81 int av_expr_parse (
82     AVExpr** expr,
83     const(char)* s,
84     const(char*)* const_names,
85     const(char*)* func1_names,
86     double function (void*, double)* funcs1,
87     const(char*)* func2_names,
88     double function (void*, double, double)* funcs2,
89     int log_offset,
90     void* log_ctx);
91 
92 /**
93  * Evaluate a previously parsed expression.
94  *
95  * @param const_values a zero terminated array of values for the identifiers from av_expr_parse() const_names
96  * @param opaque a pointer which will be passed to all functions from funcs1 and funcs2
97  * @return the value of the expression
98  */
99 double av_expr_eval (AVExpr* e, const(double)* const_values, void* opaque);
100 
101 /**
102  * Free a parsed expression previously created with av_expr_parse().
103  */
104 void av_expr_free (AVExpr* e);
105 
106 /**
107  * Parse the string in numstr and return its value as a double. If
108  * the string is empty, contains only whitespaces, or does not contain
109  * an initial substring that has the expected syntax for a
110  * floating-point number, no conversion is performed. In this case,
111  * returns a value of zero and the value returned in tail is the value
112  * of numstr.
113  *
114  * @param numstr a string representing a number, may contain one of
115  * the International System number postfixes, for example 'K', 'M',
116  * 'G'. If 'i' is appended after the postfix, powers of 2 are used
117  * instead of powers of 10. The 'B' postfix multiplies the value by
118  * 8, and can be appended after another postfix or used alone. This
119  * allows using for example 'KB', 'MiB', 'G' and 'B' as postfix.
120  * @param tail if non-NULL puts here the pointer to the char next
121  * after the last parsed character
122  */
123 double av_strtod (const(char)* numstr, char** tail);
124 
125 /* AVUTIL_EVAL_H */