libavcodec/eval.c File Reference

simple arithmetic expression evaluator. More...

#include "avcodec.h"
#include "mpegvideo.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 M_PI   3.14159265358979323846
#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 (char *s, const char **const_name, double(**func1)(void *, double), const char **func1_name, double(**func2)(void *, double, double), char **func2_name, const char **error)
 Parses a expression.
double ff_parse_eval (AVEvalExpr *e, double *const_value, void *opaque)
 Evaluates a previously parsed expression.
double ff_eval2 (char *s, double *const_value, const char **const_name, double(**func1)(void *, double), const char **func1_name, double(**func2)(void *, double, double), char **func2_name, void *opaque, const char **error)
 Parses and evaluates an expression.
attribute_deprecated double ff_eval (char *s, double *const_value, const char **const_name, double(**func1)(void *, double), const char **func1_name, double(**func2)(void *, double, double), char **func2_name, void *opaque)

Variables

static 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 M_PI   3.14159265358979323846

#define NAN   0.0/0.0

Definition at line 41 of file eval.c.

Referenced by eval_expr(), and ff_eval2().

#define VARS   10

Definition at line 59 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 90 of file eval.c.

Referenced by parse_primary().

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

Definition at line 148 of file eval.c.

Referenced by ff_parse_eval().

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

Deprecated:
Use ff_eval2 instead

Definition at line 429 of file eval.c.

double ff_eval2 ( char *  s,
double *  const_value,
const char **  const_name,
double(**)(void *, double)  func1,
const char **  func1_name,
double(**)(void *, double, double)  func2,
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 416 of file eval.c.

Referenced by av_set_string(), and ff_eval().

void ff_eval_free ( AVEvalExpr e  ) 

Definition at line 188 of file eval.c.

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

AVEvalExpr* ff_parse ( char *  s,
const char **  const_name,
double(**)(void *, double)  func1,
const char **  func1_name,
double(**)(void *, double, double)  func2,
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 379 of file eval.c.

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

double ff_parse_eval ( AVEvalExpr e,
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 408 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 301 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 346 of file eval.c.

Referenced by ff_parse(), and parse_primary().

static AVEvalExpr* parse_factor ( Parser p  )  [static]

Definition at line 316 of file eval.c.

Referenced by parse_term().

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

Definition at line 310 of file eval.c.

Referenced by parse_factor().

static AVEvalExpr* parse_primary ( Parser p  )  [static]

Definition at line 195 of file eval.c.

Referenced by parse_pow().

static AVEvalExpr* parse_subexpr ( Parser p  )  [static]

Definition at line 337 of file eval.c.

Referenced by parse_expr().

static AVEvalExpr* parse_term ( Parser p  )  [static]

Definition at line 328 of file eval.c.

Referenced by parse_subexpr().

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

Definition at line 122 of file eval.c.

Referenced by parse_primary().

static int verify_expr ( AVEvalExpr e  )  [static]

Definition at line 365 of file eval.c.

Referenced by ff_parse().


Variable Documentation

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

Referenced by av_strtod().


Generated on Thu Apr 2 07:15:41 2009 for ffmpeg by  doxygen 1.5.6