libavcodec/eval.c File Reference

simple arithmetic expression evaluator. More...

#include "avcodec.h"
#include "eval.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

Go to the source code of this file.

Data Structures

struct  Parser
struct  ff_expr_s

Defines

#define NAN   0.0/0.0
#define VARS   10

Functions

static double av_strtod (const char *name, char **tail)
 strtod() function extended with 'k', 'M', 'G', 'ki', 'Mi', 'Gi' and 'B' postfixes.
static int strmatch (const char *s, const char *prefix)
static double eval_expr (Parser *p, AVEvalExpr *e)
static AVEvalExprparse_expr (Parser *p)
void ff_eval_free (AVEvalExpr *e)
static AVEvalExprparse_primary (Parser *p)
static AVEvalExprnew_eval_expr (int type, int value, AVEvalExpr *p0, AVEvalExpr *p1)
static AVEvalExprparse_pow (Parser *p, int *sign)
static AVEvalExprparse_factor (Parser *p)
static AVEvalExprparse_term (Parser *p)
static AVEvalExprparse_subexpr (Parser *p)
static int verify_expr (AVEvalExpr *e)
AVEvalExprff_parse (const char *s, const char *const *const_name, double(**func1)(void *, double), const char **func1_name, double(**func2)(void *, double, double), const char **func2_name, const char **error)
 Parses a expression.
double ff_parse_eval (AVEvalExpr *e, const double *const_value, void *opaque)
 Evaluates a previously parsed expression.
double ff_eval2 (const char *s, const double *const_value, const char *const *const_name, double(**func1)(void *, double), const char **func1_name, double(**func2)(void *, double, double), const char **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 NAN   0.0/0.0

Definition at line 40 of file eval.c.

Referenced by eval_expr(), and ff_eval2().

#define VARS   10

Definition at line 58 of file eval.c.

Referenced by eval_expr().


Function Documentation

static double av_strtod ( const char *  name,
char **  tail 
) [static]

strtod() function extended with 'k', 'M', 'G', 'ki', 'Mi', 'Gi' and 'B' postfixes.

This allows using f.e. kB, MiB, G and B as a postfix. This function assumes that the unit of numbers is bits not bytes.

Definition at line 89 of file eval.c.

Referenced by parse_primary().

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

Definition at line 147 of file eval.c.

Referenced by ff_parse_eval().

double ff_eval2 ( const char *  s,
const double *  const_value,
const char *const *  const_name,
double(**)(void *, double)  func1,
const char **  func1_name,
double(**)(void *, double, double)  func2,
const char **  func2_name,
void *  opaque,
const char **  error 
)

Parses and evaluates an expression.

Note, this is significantly slower than ff_parse_eval()

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

void ff_eval_free ( AVEvalExpr e  ) 

Definition at line 187 of file eval.c.

Referenced by ff_eval2(), ff_eval_free(), ff_parse(), ff_rate_control_uninit(), parse_primary(), and Release().

AVEvalExpr* ff_parse ( const char *  s,
const char *const *  const_name,
double(**)(void *, double)  func1,
const char **  func1_name,
double(**)(void *, double, double)  func2,
const char **  func2_name,
const char **  error 
)

Parses a 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:
AVEvalExpr which must be freed with ff_eval_free by the user when it is not needed anymore NULL if anything went wrong

Definition at line 378 of file eval.c.

Referenced by Configure(), ff_eval2(), and ff_rate_control_init().

double ff_parse_eval ( AVEvalExpr 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_eval2(), get_qscale(), and Process().

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

Definition at line 300 of file eval.c.

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

static AVEvalExpr * parse_expr ( Parser p  )  [static]

Definition at line 345 of file eval.c.

Referenced by ff_parse(), and parse_primary().

static AVEvalExpr* parse_factor ( Parser p  )  [static]

Definition at line 315 of file eval.c.

Referenced by parse_term().

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

Definition at line 309 of file eval.c.

Referenced by parse_factor().

static AVEvalExpr* parse_primary ( Parser p  )  [static]

Definition at line 194 of file eval.c.

Referenced by parse_pow().

static AVEvalExpr* parse_subexpr ( Parser p  )  [static]

Definition at line 336 of file eval.c.

Referenced by parse_expr().

static AVEvalExpr* parse_term ( Parser p  )  [static]

Definition at line 327 of file eval.c.

Referenced by parse_subexpr().

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

Definition at line 121 of file eval.c.

Referenced by parse_primary().

static int verify_expr ( AVEvalExpr e  )  [static]

Definition at line 364 of file eval.c.

Referenced by ff_parse().


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 62 of file eval.c.

Referenced by av_strtod().


Generated on Fri Oct 26 02:35:43 2012 for FFmpeg by  doxygen 1.5.8