[FFmpeg-devel] [PATCH 07/12] Use less confusing names for the parameters used by the eval API.

Stefano Sabatini stefano.sabatini-lala
Mon Apr 12 00:37:40 CEST 2010


"var" is better than "const" for something which is meant to be
a name assuming variable values inside an expression.
---
 libavcodec/eval.c |   64 ++++++++++++++++++++++++++--------------------------
 libavcodec/eval.h |   30 ++++++++++++------------
 2 files changed, 47 insertions(+), 47 deletions(-)

diff --git a/libavcodec/eval.c b/libavcodec/eval.c
index c180fff..3eab671 100644
--- a/libavcodec/eval.c
+++ b/libavcodec/eval.c
@@ -38,12 +38,12 @@
 typedef struct Parser {
     int stack_index;
     char *s;
-    const double *const_value;
-    const char * const *const_name;          // NULL terminated
+    const double *var_values;
+    const char * const *var_names;      // NULL terminated
     double (**func1)(void *, double a); // NULL terminated
-    const char **func1_name;          // NULL terminated
+    const char **func1_names;           // NULL terminated
     double (**func2)(void *, double a, double b); // NULL terminated
-    const char **func2_name;          // NULL terminated
+    const char **func2_names;           // NULL terminated
     void *opaque;
 #define VARS 10
     double var[VARS];
@@ -136,7 +136,7 @@ static double eval_expr(Parser *p, AVExpr *e)
 {
     switch (e->type) {
         case e_value:  return e->value;
-        case e_const:  return e->value * p->const_value[e->a.const_index];
+        case e_const:  return e->value * p->var_values[e->a.const_index];
         case e_func0:  return e->value * e->a.func0(eval_expr(p, e->param[0]));
         case e_func1:  return e->value * e->a.func1(p->opaque, eval_expr(p, e->param[0]));
         case e_func2:  return e->value * e->a.func2(p->opaque, eval_expr(p, e->param[0]), eval_expr(p, e->param[1]));
@@ -201,9 +201,9 @@ static int parse_primary(AVExpr **expr, Parser *p, void *log_ctx)
     d->value = 1;
 
     /* named constants */
-    for(i=0; p->const_name && p->const_name[i]; i++){
-        if(strmatch(p->s, p->const_name[i])){
-            p->s+= strlen(p->const_name[i]);
+    for(i=0; p->var_names && p->var_names[i]; i++){
+        if(strmatch(p->s, p->var_names[i])){
+            p->s+= strlen(p->var_names[i]);
             d->type = e_const;
             d->a.const_index = i;
             *expr = d;
@@ -277,8 +277,8 @@ static int parse_primary(AVExpr **expr, Parser *p, void *log_ctx)
     else if( strmatch(next, "st"    ) ) d->type = e_st;
     else if( strmatch(next, "while" ) ) d->type = e_while;
     else {
-        for(i=0; p->func1_name && p->func1_name[i]; i++){
-            if(strmatch(next, p->func1_name[i])){
+        for(i=0; p->func1_names && p->func1_names[i]; i++){
+            if(strmatch(next, p->func1_names[i])){
                 d->a.func1 = p->func1[i];
                 d->type = e_func1;
                 *expr = d;
@@ -286,8 +286,8 @@ static int parse_primary(AVExpr **expr, Parser *p, void *log_ctx)
             }
         }
 
-        for(i=0; p->func2_name && p->func2_name[i]; i++){
-            if(strmatch(next, p->func2_name[i])){
+        for(i=0; p->func2_names && p->func2_names[i]; i++){
+            if(strmatch(next, p->func2_names[i])){
                 d->a.func2 = p->func2[i];
                 d->type = e_func2;
                 *expr = d;
@@ -435,9 +435,9 @@ static int verify_expr(AVExpr *e)
     }
 }
 
-int ff_parse_expr(AVExpr **expr, 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,
+int ff_parse_expr(AVExpr **expr, const char *s, const char * const *var_names,
+                  double (**func1)(void *, double), const char **func1_names,
+                  double (**func2)(void *, double, double), const char **func2_names,
                   void *log_ctx)
 {
     Parser p;
@@ -454,11 +454,11 @@ int ff_parse_expr(AVExpr **expr, const char *s, const char * const *const_name,
 
     p.stack_index=100;
     p.s= w;
-    p.const_name = const_name;
-    p.func1      = func1;
-    p.func1_name = func1_name;
-    p.func2      = func2;
-    p.func2_name = func2_name;
+    p.var_names   = var_names;
+    p.func1       = func1;
+    p.func1_names = func1_names;
+    p.func2       = func2;
+    p.func2_names = func2_names;
 
     ret = parse_expr(expr, &p, log_ctx);
     if (ret < 0)
@@ -471,28 +471,28 @@ end:
     return ret;
 }
 
-double ff_eval_expr(AVExpr *e, const double *const_value, void *opaque)
+double ff_eval_expr(AVExpr *e, const double *var_values, void *opaque)
 {
     Parser p;
 
-    p.const_value= const_value;
+    p.var_values = var_values;
     p.opaque     = opaque;
     return eval_expr(&p, e);
 }
 
-int ff_parse_and_eval_expr(double *res, 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,
+int ff_parse_and_eval_expr(double *res, const char *s, const double *var_values, const char * const *var_names,
+                           double (**func1)(void *, double), const char **func1_names,
+                           double (**func2)(void *, double, double), const char **func2_names,
                            void *opaque, void *log_ctx)
 {
     AVExpr *e;
 
-    int ret = ff_parse_expr(&e, s, const_name, func1, func1_name, func2, func2_name, NULL);
+    int ret = ff_parse_expr(&e, s, var_names, func1, func1_names, func2, func2_names, NULL);
     if (ret < 0) {
         *res = NAN;
         return ret;
     }
-    *res = ff_eval_expr(e, const_value, opaque);
+    *res = ff_eval_expr(e, var_values, opaque);
     ff_free_expr(e);
     return 0;
 }
@@ -501,13 +501,13 @@ int ff_parse_and_eval_expr(double *res, const char *s, const double *const_value
 
 #undef printf
 
-static double const_values[]={
+static double var_values[]={
     M_PI,
     M_E,
     0
 };
 
-static const char *const_names[]={
+static const char *var_names[]={
     "PI",
     "E",
     0
@@ -518,15 +518,15 @@ int main(void)
     int i;
     double d;
 
-    ff_parse_and_eval_expr(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", const_values, const_names, NULL, NULL, NULL, NULL, NULL, NULL);
+    ff_parse_and_eval_expr(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", var_values, var_names, NULL, NULL, NULL, NULL, NULL, NULL);
     printf("%f == 12.7\n", d);
 
-    ff_parse_and_eval_expr(&d, "80G/80Gi", const_values, const_names, NULL, NULL, NULL, NULL, NULL, NULL);
+    av_parse_and_eval_expr(&d, "80G/80Gi", var_values, var_names, NULL, NULL, NULL, NULL, NULL, NULL);
     printf("%f == 0.931322575\n", d);
 
     for(i=0; i<1050; i++){
         START_TIMER
-            ff_parse_and_eval_expr(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", const_values, const_names, NULL, NULL, NULL, NULL, NULL, NULL);
+            ff_parse_and_eval_expr(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", var_values, var_names, NULL, NULL, NULL, NULL, NULL, NULL);
         STOP_TIMER("ff_parse_and_eval_expr")
     }
     return 0;
diff --git a/libavcodec/eval.h b/libavcodec/eval.h
index bb94a51..696b82e 100644
--- a/libavcodec/eval.h
+++ b/libavcodec/eval.h
@@ -35,20 +35,20 @@ typedef struct AVExpr AVExpr;
  * @param res in case of success puts here the result of the
  * expression evaluation, NAN otherwise
  * @param s expression as a zero terminated string for example "1+2^3+5*5+sin(2/3)"
+ * @param var_values a zero terminated array of values for the identifers from var_names
  * @param func1 NULL terminated array of function pointers for functions which take 1 argument
  * @param func2 NULL terminated array of function pointers for functions which take 2 arguments
- * @param const_name NULL terminated array of zero terminated strings of constant identifers for example {"PI", "E", 0}
- * @param func1_name NULL terminated array of zero terminated strings of func1 identifers
- * @param func2_name NULL terminated array of zero terminated strings of func2 identifers
- * @param const_value a zero terminated array of values for the identifers from const_name
+ * @param var_names NULL terminated array of zero terminated strings of variable identifers for example {"PI", "E", 0}
+ * @param func1_names NULL terminated array of zero terminated strings of func1 identifers
+ * @param func2_names NULL terminated array of zero terminated strings of func2 identifers
  * @param opaque a pointer which will be passed to all functions from func1 and func2
  * @return 0 in case of successfull parsing, a negative value
  * corresponding to an AVERROR code in case of parsing failure
  */
 int ff_parse_and_eval_expr(double *res, 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,
+                           const double *var_values, const char * const *var_names,
+                           double (**func1)(void *, double), const char **func1_names,
+                           double (**func2)(void *, double, double), const char **func2_names,
                            void *opaque, void *log_ctx);
 
 /**
@@ -60,25 +60,25 @@ int ff_parse_and_eval_expr(double *res, const char *s,
  * @param s expression as a zero terminated string for example "1+2^3+5*5+sin(2/3)"
  * @param func1 NULL terminated array of function pointers for functions which take 1 argument
  * @param func2 NULL terminated array of function pointers for functions which take 2 arguments
- * @param const_name NULL terminated array of zero terminated strings of constant identifers for example {"PI", "E", 0}
- * @param func1_name NULL terminated array of zero terminated strings of func1 identifers
- * @param func2_name NULL terminated array of zero terminated strings of func2 identifers
+ * @param var_names NULL terminated array of zero terminated strings of variable identifers for example {"PI", "E", 0}
+ * @param func1_names NULL terminated array of zero terminated strings of func1 identifers
+ * @param func2_names NULL terminated array of zero terminated strings of func2 identifers
  * @return 0 in case of success, a negative error corresponding to an
  * AVERROR code in case of failure
  */
-int ff_parse_expr(AVExpr **expr, 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,
+int ff_parse_expr(AVExpr **expr, const char *s, const char * const *var_names,
+                  double (**func1)(void *, double), const char **func1_names,
+                  double (**func2)(void *, double, double), const char **func2_names,
                   void *log_ctx);
 
 /**
  * Evaluates a previously parsed expression.
  *
- * @param const_value a zero terminated array of values for the identifers from ff_parse const_name
+ * @param var_values a zero terminated array of values for the identifers from ff_parse_expr() var_names
  * @param opaque a pointer which will be passed to all functions from func1 and func2
  * @return the value of the expression
  */
-double ff_eval_expr(AVExpr *e, const double *const_value, void *opaque);
+double ff_eval_expr(AVExpr *e, const double *var_values, void *opaque);
 
 /**
  * Frees a parsed expression previously created with ff_parse().
-- 
1.7.0




More information about the ffmpeg-devel mailing list