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