comparison eval.c @ 11739:ceffa0ca7596 libavcodec

Change the order of parameters for ff_eval_expr() and ff_parse_and_eval_expr(), place the names for constants/functions before the corresponding values. This looks more readable, as the user is expected to know the names before the values.
author stefano
date Sun, 16 May 2010 23:00:22 +0000
parents 7dd2a45249a9
children c6368258b694
comparison
equal deleted inserted replaced
11738:9bfef228a117 11739:ceffa0ca7596
367 case e_gauss: return verify_expr(e->param[0]); 367 case e_gauss: return verify_expr(e->param[0]);
368 default: return verify_expr(e->param[0]) && verify_expr(e->param[1]); 368 default: return verify_expr(e->param[0]) && verify_expr(e->param[1]);
369 } 369 }
370 } 370 }
371 371
372 AVExpr *ff_parse_expr(const char *s, const char * const *const_name, 372 AVExpr *ff_parse_expr(const char *s,
373 double (* const *func1)(void *, double), const char * const *func1_name, 373 const char * const *const_name,
374 double (* const *func2)(void *, double, double), const char * const *func2_name, 374 const char * const *func1_name, double (* const *func1)(void *, double),
375 const char * const *func2_name, double (* const *func2)(void *, double, double),
375 const char **error){ 376 const char **error){
376 Parser p; 377 Parser p;
377 AVExpr *e = NULL; 378 AVExpr *e = NULL;
378 char *w = av_malloc(strlen(s) + 1); 379 char *w = av_malloc(strlen(s) + 1);
379 char *wp = w; 380 char *wp = w;
410 p.const_value= const_value; 411 p.const_value= const_value;
411 p.opaque = opaque; 412 p.opaque = opaque;
412 return eval_expr(&p, e); 413 return eval_expr(&p, e);
413 } 414 }
414 415
415 double ff_parse_and_eval_expr(const char *s, const double *const_value, const char * const *const_name, 416 double ff_parse_and_eval_expr(const char *s,
416 double (* const *func1)(void *, double), const char * const *func1_name, 417 const char * const *const_name, const double *const_value,
417 double (* const *func2)(void *, double, double), const char * const *func2_name, 418 const char * const *func1_name, double (* const *func1)(void *, double),
419 const char * const *func2_name, double (* const *func2)(void *, double, double),
418 void *opaque, const char **error){ 420 void *opaque, const char **error){
419 AVExpr * e = ff_parse_expr(s, const_name, func1, func1_name, func2, func2_name, error); 421 AVExpr *e = ff_parse_expr(s, const_name, func1_name, func1, func2_name, func2, error);
420 double d; 422 double d;
421 if (!e) return NAN; 423 if (!e) return NAN;
422 d = ff_eval_expr(e, const_value, opaque); 424 d = ff_eval_expr(e, const_value, opaque);
423 ff_free_expr(e); 425 ff_free_expr(e);
424 return d; 426 return d;
436 "E", 438 "E",
437 0 439 0
438 }; 440 };
439 int main(void){ 441 int main(void){
440 int i; 442 int i;
441 printf("%f == 12.7\n", ff_parse_and_eval_expr("1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", const_values, const_names, NULL, NULL, NULL, NULL, NULL, NULL)); 443 printf("%f == 12.7\n", ff_parse_and_eval_expr("1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", const_names, const_values, NULL, NULL, NULL, NULL, NULL, NULL));
442 printf("%f == 0.931322575\n", ff_parse_and_eval_expr("80G/80Gi", const_values, const_names, NULL, NULL, NULL, NULL, NULL, NULL)); 444 printf("%f == 0.931322575\n", ff_parse_and_eval_expr("80G/80Gi", const_names, const_values, NULL, NULL, NULL, NULL, NULL, NULL));
443 445
444 for(i=0; i<1050; i++){ 446 for(i=0; i<1050; i++){
445 START_TIMER 447 START_TIMER
446 ff_parse_and_eval_expr("1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", const_values, const_names, NULL, NULL, NULL, NULL, NULL, NULL); 448 ff_parse_and_eval_expr("1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", const_names, const_values, NULL, NULL, NULL, NULL, NULL, NULL);
447 STOP_TIMER("ff_parse_and_eval_expr") 449 STOP_TIMER("ff_parse_and_eval_expr")
448 } 450 }
449 return 0; 451 return 0;
450 } 452 }
451 #endif 453 #endif