Statistics
| Branch: | Revision:

ffmpeg / libavcodec / eval.h @ 9ace13b4

History | View | Annotate | Download (5.14 KB)

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 AVCODEC_EVAL_H
27
#define AVCODEC_EVAL_H
28

    
29
typedef struct AVExpr AVExpr;
30

    
31
/**
32
 * Parses and evaluates an expression.
33
 * Note, this is significantly slower than ff_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_name NULL terminated array of zero terminated strings of constant identifers for example {"PI", "E", 0}
39
 * @param const_value a zero terminated array of values for the identifers from const_name
40
 * @param func1_name NULL terminated array of zero terminated strings of func1 identifers
41
 * @param func1 NULL terminated array of function pointers for functions which take 1 argument
42
 * @param func2_name NULL terminated array of zero terminated strings of func2 identifers
43
 * @param func2 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 func1 and func2
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 ff_parse_and_eval_expr(double *res, const char *s,
50
                              const char * const *const_name, const double *const_value,
51
                              const char * const *func1_name, double (* const *func1)(void *, double),
52
                              const char * const *func2_name, double (* const *func2)(void *, double, double),
53
                              void *opaque, int log_offset, void *log_ctx);
54

    
55
/**
56
 * Parses 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 ff_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_name NULL terminated array of zero terminated strings of constant identifers for example {"PI", "E", 0}
64
 * @param func1_name NULL terminated array of zero terminated strings of func1 identifers
65
 * @param func1 NULL terminated array of function pointers for functions which take 1 argument
66
 * @param func2_name NULL terminated array of zero terminated strings of func2 identifers
67
 * @param func2 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 ff_parse_expr(AVExpr **expr, const char *s,
73
                      const char * const *const_name,
74
                      const char * const *func1_name, double (* const *func1)(void *, double),
75
                      const char * const *func2_name, double (* const *func2)(void *, double, double),
76
                      int log_offset, void *log_ctx);
77

    
78
/**
79
 * Evaluates a previously parsed expression.
80
 *
81
 * @param const_value a zero terminated array of values for the identifers from ff_parse const_name
82
 * @param opaque a pointer which will be passed to all functions from func1 and func2
83
 * @return the value of the expression
84
 */
85
double ff_eval_expr(AVExpr * e, const double *const_value, void *opaque);
86

    
87
/**
88
 * Frees a parsed expression previously created with ff_parse_expr().
89
 */
90
void ff_free_expr(AVExpr *e);
91

    
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
108
 */
109
double av_strtod(const char *numstr, char **tail);
110

    
111
#endif /* AVCODEC_EVAL_H */