annotate eval.h @ 978:009d2ce554b2 libavutil

Remove macro duplication between common.h and intmath.h
author mru
date Wed, 07 Jul 2010 17:27:43 +0000
parents e34e8d654ded
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
932
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
1 /*
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
2 * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
3 *
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
4 * This file is part of FFmpeg.
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
5 *
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
6 * FFmpeg is free software; you can redistribute it and/or
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
9 * version 2.1 of the License, or (at your option) any later version.
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
10 *
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
11 * FFmpeg is distributed in the hope that it will be useful,
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
14 * Lesser General Public License for more details.
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
15 *
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
17 * License along with FFmpeg; if not, write to the Free Software
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
19 */
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
20
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
21 /**
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
22 * @file
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
23 * simple arithmetic expression evaluator
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
24 */
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
25
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
26 #ifndef AVUTIL_EVAL_H
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
27 #define AVUTIL_EVAL_H
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
28
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
29 typedef struct AVExpr AVExpr;
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
30
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
31 /**
957
e34e8d654ded Fix grammar errors in documentation
mru
parents: 932
diff changeset
32 * Parse and evaluate an expression.
932
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
33 * Note, this is significantly slower than av_eval_expr().
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
34 *
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
35 * @param res a pointer to a double where is put the result value of
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
36 * the expression, or NAN in case of error
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
37 * @param s expression as a zero terminated string, for example "1+2^3+5*5+sin(2/3)"
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
38 * @param const_names NULL terminated array of zero terminated strings of constant identifiers, for example {"PI", "E", 0}
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
39 * @param const_values a zero terminated array of values for the identifiers from const_names
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
40 * @param func1_names NULL terminated array of zero terminated strings of funcs1 identifiers
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
41 * @param funcs1 NULL terminated array of function pointers for functions which take 1 argument
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
42 * @param func2_names NULL terminated array of zero terminated strings of funcs2 identifiers
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
43 * @param funcs2 NULL terminated array of function pointers for functions which take 2 arguments
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
44 * @param opaque a pointer which will be passed to all functions from funcs1 and funcs2
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
45 * @param log_ctx parent logging context
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
46 * @return 0 in case of success, a negative value corresponding to an
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
47 * AVERROR code otherwise
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
48 */
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
49 int av_parse_and_eval_expr(double *res, const char *s,
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
50 const char * const *const_names, const double *const_values,
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
51 const char * const *func1_names, double (* const *funcs1)(void *, double),
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
52 const char * const *func2_names, double (* const *funcs2)(void *, double, double),
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
53 void *opaque, int log_offset, void *log_ctx);
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
54
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
55 /**
957
e34e8d654ded Fix grammar errors in documentation
mru
parents: 932
diff changeset
56 * Parse an expression.
932
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
57 *
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
58 * @param expr a pointer where is put an AVExpr containing the parsed
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
59 * value in case of successfull parsing, or NULL otherwise.
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
60 * The pointed to AVExpr must be freed with av_free_expr() by the user
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
61 * when it is not needed anymore.
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
62 * @param s expression as a zero terminated string, for example "1+2^3+5*5+sin(2/3)"
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
63 * @param const_names NULL terminated array of zero terminated strings of constant identifiers, for example {"PI", "E", 0}
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
64 * @param func1_names NULL terminated array of zero terminated strings of funcs1 identifiers
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
65 * @param funcs1 NULL terminated array of function pointers for functions which take 1 argument
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
66 * @param func2_names NULL terminated array of zero terminated strings of funcs2 identifiers
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
67 * @param funcs2 NULL terminated array of function pointers for functions which take 2 arguments
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
68 * @param log_ctx parent logging context
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
69 * @return 0 in case of success, a negative value corresponding to an
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
70 * AVERROR code otherwise
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
71 */
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
72 int av_parse_expr(AVExpr **expr, const char *s,
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
73 const char * const *const_names,
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
74 const char * const *func1_names, double (* const *funcs1)(void *, double),
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
75 const char * const *func2_names, double (* const *funcs2)(void *, double, double),
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
76 int log_offset, void *log_ctx);
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
77
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
78 /**
957
e34e8d654ded Fix grammar errors in documentation
mru
parents: 932
diff changeset
79 * Evaluate a previously parsed expression.
932
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
80 *
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
81 * @param const_values a zero terminated array of values for the identifiers from av_parse_expr() const_names
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
82 * @param opaque a pointer which will be passed to all functions from funcs1 and funcs2
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
83 * @return the value of the expression
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
84 */
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
85 double av_eval_expr(AVExpr *e, const double *const_values, void *opaque);
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
86
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
87 /**
957
e34e8d654ded Fix grammar errors in documentation
mru
parents: 932
diff changeset
88 * Free a parsed expression previously created with av_parse_expr().
932
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
89 */
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
90 void av_free_expr(AVExpr *e);
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
91
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
92 /**
957
e34e8d654ded Fix grammar errors in documentation
mru
parents: 932
diff changeset
93 * Parse the string in numstr and return its value as a double. If
932
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
94 * the string is empty, contains only whitespaces, or does not contain
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
95 * an initial substring that has the expected syntax for a
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
96 * floating-point number, no conversion is performed. In this case,
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
97 * returns a value of zero and the value returned in tail is the value
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
98 * of numstr.
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
99 *
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
100 * @param numstr a string representing a number, may contain one of
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
101 * the International System number postfixes, for example 'K', 'M',
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
102 * 'G'. If 'i' is appended after the postfix, powers of 2 are used
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
103 * instead of powers of 10. The 'B' postfix multiplies the value for
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
104 * 8, and can be appended after another postfix or used alone. This
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
105 * allows using for example 'KB', 'MiB', 'G' and 'B' as postfix.
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
106 * @param tail if non-NULL puts here the pointer to the char next
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
107 * after the last parsed character
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
108 */
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
109 double av_strtod(const char *numstr, char **tail);
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
110
be49bac1a894 Move eval.c and eval.h from libavcodec to libavutil, and make the eval
stefano
parents:
diff changeset
111 #endif /* AVUTIL_EVAL_H */