libavcodec/eval.c File Reference

simple arithmetic expression evaluator. More...

#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 AVExprparse_expr (Parser *p)
void ff_free_expr (AVExpr *e)
 Frees a parsed expression previously created with ff_parse().
static AVExprparse_primary (Parser *p)
static AVExprnew_eval_expr (int type, int value, AVExpr *p0, AVExpr *p1)
static AVExprparse_pow (Parser *p, int *sign)
static AVExprparse_factor (Parser *p)
static AVExprparse_term (Parser *p)
static AVExprparse_subexpr (Parser *p)
static int verify_expr (AVExpr *e)
AVExprff_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]


Detailed Description

simple arithmetic expression evaluator.

see http://joe.hotchkiss.com/programming/eval/eval.html

Definition in file eval.c.


Define Documentation

#define VARS   10

Definition at line 43 of file eval.c.

Referenced by eval_expr().


Function Documentation

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.

Parameters:
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().

static double eval_expr ( Parser p,
AVExpr e 
) [static]

Definition at line 128 of file eval.c.

Referenced by ff_eval_expr().

double ff_eval_expr ( AVExpr e,
const double *  const_value,
void *  opaque 
)

Evaluates a previously parsed expression.

Parameters:
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
Returns:
the value of the expression

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().

Parameters:
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
Returns:
the value of the expression

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.

Parameters:
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
Returns:
AVExpr which must be freed with ff_free_expr() by the user when it is not needed anymore NULL if anything went wrong

Definition at line 372 of file eval.c.

Referenced by ff_parse_and_eval_expr(), and ff_rate_control_init().

static AVExpr* new_eval_expr ( int  type,
int  value,
AVExpr p0,
AVExpr p1 
) [static]

Definition at line 284 of file eval.c.

Referenced by parse_expr(), parse_factor(), parse_subexpr(), and parse_term().

static AVExpr * parse_expr ( Parser p  )  [static]

Definition at line 337 of file eval.c.

Referenced by ff_parse_expr(), and parse_primary().

static AVExpr* parse_factor ( Parser p  )  [static]

Definition at line 301 of file eval.c.

Referenced by parse_term().

static AVExpr* parse_pow ( Parser p,
int *  sign 
) [static]

Definition at line 295 of file eval.c.

Referenced by parse_factor().

static AVExpr* parse_primary ( Parser p  )  [static]

Definition at line 175 of file eval.c.

Referenced by parse_pow().

static AVExpr* parse_subexpr ( Parser p  )  [static]

Definition at line 326 of file eval.c.

Referenced by parse_expr().

static AVExpr* parse_term ( Parser p  )  [static]

Definition at line 315 of file eval.c.

Referenced by parse_subexpr().

static int strmatch ( const char *  s,
const char *  prefix 
) [static]

Definition at line 102 of file eval.c.

Referenced by parse_primary().

static int verify_expr ( AVExpr e  )  [static]

Definition at line 358 of file eval.c.

Referenced by ff_parse_expr().


Variable Documentation

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().


Generated on Fri Oct 26 02:36:51 2012 for FFmpeg by  doxygen 1.5.8