#include "libavutil/avutil.h"
#include "eval.h"
Go to the source code of this file.
Data Structures | |
struct | Parser |
struct | AVExpr |
Defines | |
#define | VARS 10 |
Functions | |
double | av_strtod (const char *numstr, char **tail) |
Parses the string in numstr and returns its value as a double. | |
static int | strmatch (const char *s, const char *prefix) |
static double | eval_expr (Parser *p, AVExpr *e) |
static AVExpr * | parse_expr (Parser *p) |
void | ff_free_expr (AVExpr *e) |
Frees a parsed expression previously created with ff_parse(). | |
static AVExpr * | parse_primary (Parser *p) |
static AVExpr * | new_eval_expr (int type, int value, AVExpr *p0, AVExpr *p1) |
static AVExpr * | parse_pow (Parser *p, int *sign) |
static AVExpr * | parse_factor (Parser *p) |
static AVExpr * | parse_term (Parser *p) |
static AVExpr * | parse_subexpr (Parser *p) |
static int | verify_expr (AVExpr *e) |
AVExpr * | ff_parse_expr (const char *s, const char *const *const_name, double(*const *func1)(void *, double), const char *const *func1_name, double(*const *func2)(void *, double, double), const char *const *func2_name, const char **error) |
Parses an expression. | |
double | ff_eval_expr (AVExpr *e, const double *const_value, void *opaque) |
Evaluates a previously parsed expression. | |
double | ff_parse_and_eval_expr (const char *s, const double *const_value, const char *const *const_name, double(*const *func1)(void *, double), const char *const *func1_name, double(*const *func2)(void *, double, double), const char *const *func2_name, void *opaque, const char **error) |
Parses and evaluates an expression. | |
Variables | |
static const int8_t | si_prefixes ['z'- 'E'+1] |
see http://joe.hotchkiss.com/programming/eval/eval.html
Definition in file eval.c.
#define VARS 10 |
double av_strtod | ( | const char * | numstr, | |
char ** | tail | |||
) |
Parses the string in numstr and returns its value as a double.
If the string is empty, contains only whitespaces, or does not contain an initial substring that has the expected syntax for a floating-point number, no conversion is performed. In this case, returns a value of zero and the value returned in tail is the value of numstr.
numstr | a string representing a number, may contain one of the International System number postfixes, for example 'K', 'M', 'G'. If 'i' is appended after the postfix, powers of 2 are used instead of powers of 10. The 'B' postfix multiplies the value for 8, and can be appended after another postfix or used alone. This allows using for example 'KB', 'MiB', 'G' and 'B' as postfix. | |
tail | if non-NULL puts here the pointer to the char next after the last parsed character |
Definition at line 70 of file eval.c.
Referenced by parse_primary().
double ff_eval_expr | ( | AVExpr * | e, | |
const double * | const_value, | |||
void * | opaque | |||
) |
Evaluates a previously parsed expression.
const_value | a zero terminated array of values for the identifers from ff_parse const_name | |
opaque | a pointer which will be passed to all functions from func1 and func2 |
Definition at line 407 of file eval.c.
Referenced by ff_parse_and_eval_expr(), and get_qscale().
void ff_free_expr | ( | AVExpr * | e | ) |
Frees a parsed expression previously created with ff_parse().
Definition at line 168 of file eval.c.
Referenced by ff_free_expr(), ff_parse_and_eval_expr(), ff_parse_expr(), ff_rate_control_uninit(), and parse_primary().
double ff_parse_and_eval_expr | ( | const char * | s, | |
const double * | const_value, | |||
const char *const * | const_name, | |||
double(**)(void *, double) | func1, | |||
const char *const * | func1_name, | |||
double(**)(void *, double, double) | func2, | |||
const char *const * | func2_name, | |||
void * | opaque, | |||
const char ** | error | |||
) |
Parses and evaluates an expression.
Note, this is significantly slower than ff_eval_expr().
s | expression as a zero terminated string for example "1+2^3+5*5+sin(2/3)" | |
func1 | NULL terminated array of function pointers for functions which take 1 argument | |
func2 | NULL terminated array of function pointers for functions which take 2 arguments | |
const_name | NULL terminated array of zero terminated strings of constant identifers for example {"PI", "E", 0} | |
func1_name | NULL terminated array of zero terminated strings of func1 identifers | |
func2_name | NULL terminated array of zero terminated strings of func2 identifers | |
error | pointer to a char* which is set to an error message if something goes wrong | |
const_value | a zero terminated array of values for the identifers from const_name | |
opaque | a pointer which will be passed to all functions from func1 and func2 |
Definition at line 415 of file eval.c.
Referenced by av_set_string3().
AVExpr* ff_parse_expr | ( | const char * | s, | |
const char *const * | const_name, | |||
double(**)(void *, double) | func1, | |||
const char *const * | func1_name, | |||
double(**)(void *, double, double) | func2, | |||
const char *const * | func2_name, | |||
const char ** | error | |||
) |
Parses an expression.
s | expression as a zero terminated string for example "1+2^3+5*5+sin(2/3)" | |
func1 | NULL terminated array of function pointers for functions which take 1 argument | |
func2 | NULL terminated array of function pointers for functions which take 2 arguments | |
const_name | NULL terminated array of zero terminated strings of constant identifers for example {"PI", "E", 0} | |
func1_name | NULL terminated array of zero terminated strings of func1 identifers | |
func2_name | NULL terminated array of zero terminated strings of func2 identifers | |
error | pointer to a char* which is set to an error message if something goes wrong |
Definition at line 372 of file eval.c.
Referenced by ff_parse_and_eval_expr(), and ff_rate_control_init().
Definition at line 284 of file eval.c.
Referenced by parse_expr(), parse_factor(), parse_subexpr(), and parse_term().
static int strmatch | ( | const char * | s, | |
const char * | prefix | |||
) | [static] |
static int verify_expr | ( | AVExpr * | e | ) | [static] |
const int8_t si_prefixes['z'- 'E'+1] [static] |
Initial value:
{ ['y'-'E']= -24, ['z'-'E']= -21, ['a'-'E']= -18, ['f'-'E']= -15, ['p'-'E']= -12, ['n'-'E']= - 9, ['u'-'E']= - 6, ['m'-'E']= - 3, ['c'-'E']= - 2, ['d'-'E']= - 1, ['h'-'E']= 2, ['k'-'E']= 3, ['K'-'E']= 3, ['M'-'E']= 6, ['G'-'E']= 9, ['T'-'E']= 12, ['P'-'E']= 15, ['E'-'E']= 18, ['Z'-'E']= 21, ['Y'-'E']= 24, }
Definition at line 47 of file eval.c.
Referenced by av_strtod().