[xiph-commits] r13766 - trunk/sushivision

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Thu Sep 6 12:45:28 PDT 2007


Author: xiphmont
Date: 2007-09-06 12:45:28 -0700 (Thu, 06 Sep 2007)
New Revision: 13766

Modified:
   trunk/sushivision/dimension.c
   trunk/sushivision/example_fractal.c
   trunk/sushivision/sushivision.h
Log:
Ongoing API simplification: dimension naming/declarations



Modified: trunk/sushivision/dimension.c
===================================================================
--- trunk/sushivision/dimension.c	2007-09-06 16:51:20 UTC (rev 13765)
+++ trunk/sushivision/dimension.c	2007-09-06 19:45:28 UTC (rev 13766)
@@ -669,52 +669,81 @@
   return dw;
 };
 
-sv_dim_t *sv_dim_new(int number,
-		     char *name,
-		     unsigned flags){
+sv_dim_t *sv_dim_new(char *name){
+  int number;
+  sv_dim_t *d;
+  int i;
 
-  sv_dim_t *d;
   _sv_token *decl = _sv_tokenize_declparam(name);
   
   if(!decl){
     fprintf(stderr,"sushivision: Unable to parse dimension name \"%s\".\n",name);
     errno = -EINVAL;
-    //XXXX leak
     return NULL;
   }
 
-  if(number<0){
-    fprintf(stderr,"Dimension number must be >= 0\n");
-    errno = -EINVAL;
-    //XXXX leak
-    return NULL;
-  }
-
-  if(number<_sv_dimensions){
-    if(_sv_dimension_list[number]!=NULL){
-      fprintf(stderr,"Dimension number %d already exists\n",number);
-      errno = -EINVAL;
-      //XXXleak
-      return NULL;
-    }
+  if(_sv_dimensions == 0){
+    number=0;
+    _sv_dimension_list = calloc (number+1,sizeof(*_sv_dimension_list));
+    _sv_dimensions=1;
   }else{
-    if(_sv_dimensions == 0){
-      _sv_dimension_list = calloc (number+1,sizeof(*_sv_dimension_list));
-    }else{
-      _sv_dimension_list = realloc (_sv_dimension_list,(number+1) * sizeof(*_sv_dimension_list));
-      memset(_sv_dimension_list + _sv_dimensions, 0, sizeof(*_sv_dimension_list)*(number + 1 - _sv_dimensions));
+    for(number=0;number<_sv_dimensions;number++)
+      if(!_sv_dimension_list[number])break;
+    if(number==_sv_dimensions){
+      _sv_dimensions=number+1;
+      _sv_dimension_list = realloc (_sv_dimension_list,_sv_dimensions * sizeof(*_sv_dimension_list));
     }
-    _sv_dimensions=number+1;
   }
-
+  
   d = _sv_dimension_list[number] = calloc(1, sizeof(**_sv_dimension_list));
   d->number = number;
   d->name = strdup(decl->name);
   d->legend = strdup(decl->label);
-  d->flags = flags;
   d->type = SV_DIM_CONTINUOUS;
   d->private = calloc(1, sizeof(*d->private));
 
+  // parse decllist
+  for(i=0;i<decl->n;i++){
+    char *f=decl->values[i]->s;
+    double v=decl->values[i]->v;
+ 
+    if(!strcmp(f,"continuous")){
+      d->type = SV_DIM_CONTINUOUS;
+
+    }else if(!strcmp(f,"picklist")){
+      d->type = SV_DIM_PICKLIST;
+
+    }else if(!strcmp(f,"discrete")){
+      d->type = SV_DIM_DISCRETE;
+
+    }else if(!strcmp(f,"picklist")){
+      d->type = SV_DIM_PICKLIST;
+      d->flags |= SV_DIM_NO_X | SV_DIM_NO_Y;
+
+    }else if(!strcmp(f,"numerator")){
+      if(isnan(v)){
+	fprintf(stderr,"sushivision: Missing numerator value in \"%s\"\n.",name);
+      }else{
+	d->type = SV_DIM_PICKLIST;
+	d->private->discrete_numerator = v;
+      }
+
+    }else if(!strcmp(f,"denominator")){
+      if(isnan(v)){
+	fprintf(stderr,"sushivision: Missing denominator value in \"%s\"\n.",name);
+      }else if(v==0){
+	fprintf(stderr,"sushivision: denominator value may not be zero\n.",name);
+      }else{
+	d->type = SV_DIM_PICKLIST;
+	d->private->discrete_denominator = v;
+      }
+
+    }else{
+      fprintf(stderr,"sushivision: Unknown parameter \"%s\" for dimension \"%s\".\n",
+	      f,d->name);
+    }
+  }
+
   pthread_setspecific(_sv_dim_key, (void *)d);
 
   _sv_token_free(decl);
@@ -773,30 +802,6 @@
   return ret;
 }
 
-// XXXX need to recompute after
-int sv_dim_set_discrete(long quant_numerator,
-			long quant_denominator){
-  
-  sv_dim_t *d = sv_dim(0);
-  if(!d) return -EINVAL;
-
-  d->private->discrete_numerator = quant_numerator;
-  d->private->discrete_denominator = quant_denominator;
-  d->type = SV_DIM_DISCRETE;
-  
-  return 0;
-}
-
-int sv_dim_set_picklist(){
-  
-  sv_dim_t *d = sv_dim(0);
-  if(!d) return -EINVAL;
-
-  d->type = SV_DIM_PICKLIST;
-  d->flags |= SV_DIM_NO_X | SV_DIM_NO_Y;
-  return 0;
-}
-
 static _sv_propmap_t *typemap[]={
   &(_sv_propmap_t){"continuous",SV_DIM_CONTINUOUS, NULL,NULL,NULL},
   &(_sv_propmap_t){"discrete",SV_DIM_DISCRETE,     NULL,NULL,NULL},

Modified: trunk/sushivision/example_fractal.c
===================================================================
--- trunk/sushivision/example_fractal.c	2007-09-06 16:51:20 UTC (rev 13765)
+++ trunk/sushivision/example_fractal.c	2007-09-06 19:45:28 UTC (rev 13766)
@@ -59,22 +59,23 @@
 
   // "name:label(arg,arg,arg...)"
 
-  sv_dim_t *d0 = sv_dim_new(0, "rc:Re\\(c\\)", 0);
+  sv_dim_t *d0 = sv_dim_new("rc:Re\\(c\\)");
   sv_dim_make_scale("-2.25, -0.75, 0, 0.25, 0.75");
   
-  sv_dim_t *d1 = sv_dim_new(1, "ic:Im\\(c\\)", 0);
+  sv_dim_t *d1 = sv_dim_new("ic:Im\\(c\\)");
   sv_dim_make_scale("-2,-1,0,1,2");
 
-  sv_dim_t *d2 = sv_dim_new(2, "rz:Re\\(z0\\)", 0);
+  sv_dim_t *d2 = sv_dim_new("rz:Re\\(z0\\)");
   sv_dim_make_scale("-2.25, -1, 0, 1, 2.25");
 
-  sv_dim_t *d3 = sv_dim_new(3, "iz:Im\\(z0\\)", 0);
+  sv_dim_t *d3 = sv_dim_new("iz:Im\\(z0\\)");
   sv_dim_make_scale("-2.25, -1, 0, 1, 2.25");
 
-  sv_dim_t *d4 = sv_dim_new(4, "it:Max Iterations", 0);
-  sv_dim_make_scale("100:one hundred, 1000:one thousand, 10000:ten thousand, 100000:one hundred thousand");
-
-  sv_dim_set_picklist();
+  sv_dim_t *d4 = sv_dim_new("it:Max Iterations(picklist)");
+  sv_dim_make_scale("100:one hundred,"
+		    "1000:one thousand,"
+		    "10000:ten thousand,"
+		    "100000:one hundred thousand");
   sv_dim_set_value(100);
 
   sv_func_t *f = sv_func_new(0, 2, fractal_objective, 0);

Modified: trunk/sushivision/sushivision.h
===================================================================
--- trunk/sushivision/sushivision.h	2007-09-06 16:51:20 UTC (rev 13765)
+++ trunk/sushivision/sushivision.h	2007-09-06 19:45:28 UTC (rev 13766)
@@ -94,9 +94,7 @@
   sv_dim_internal_t *private;
 };
 
-sv_dim_t            *sv_dim_new (int number, 
-				 char *name,
-				 unsigned flags);
+sv_dim_t            *sv_dim_new (char *decl);
 
 sv_dim_t                *sv_dim (char *name);
 
@@ -104,11 +102,6 @@
 
 int           sv_dim_make_scale (char *format);
 
-int         sv_dim_set_discrete (long quant_numerator,
-				 long quant_denominator);
-
-int         sv_dim_set_picklist ();
-
 int            sv_dim_set_value (double val);
 
 int          sv_dim_set_bracket (double lo,



More information about the commits mailing list