[xiph-commits] r13774 - trunk/sushivision

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Fri Sep 7 15:07:09 PDT 2007


Author: xiphmont
Date: 2007-09-07 15:07:08 -0700 (Fri, 07 Sep 2007)
New Revision: 13774

Modified:
   trunk/sushivision/dimension.c
   trunk/sushivision/example_fractal.c
   trunk/sushivision/internal.h
   trunk/sushivision/main.c
   trunk/sushivision/objective.c
   trunk/sushivision/panel-1d.c
   trunk/sushivision/panel-2d.c
   trunk/sushivision/panel-xy.c
   trunk/sushivision/panel.c
   trunk/sushivision/sushivision.h
Log:
Beginning of objective API rework


Modified: trunk/sushivision/dimension.c
===================================================================
--- trunk/sushivision/dimension.c	2007-09-07 19:39:58 UTC (rev 13773)
+++ trunk/sushivision/dimension.c	2007-09-07 22:07:08 UTC (rev 13774)
@@ -677,7 +677,7 @@
   _sv_token *decl = _sv_tokenize_declparam(name);
   
   if(!decl){
-    fprintf(stderr,"sushivision: Unable to parse dimension name \"%s\".\n",name);
+    fprintf(stderr,"sushivision: Unable to parse dimension declaration \"%s\".\n",name);
     errno = -EINVAL;
     return NULL;
   }

Modified: trunk/sushivision/example_fractal.c
===================================================================
--- trunk/sushivision/example_fractal.c	2007-09-07 19:39:58 UTC (rev 13773)
+++ trunk/sushivision/example_fractal.c	2007-09-07 22:07:08 UTC (rev 13774)
@@ -80,20 +80,20 @@
 
   sv_func_t *f = sv_func_new(0, 2, fractal_objective, 0);
   
-  sv_obj_t *o0 = sv_obj_new(0,"outer",
-			    (sv_func_t *[]){f},
-			    (int []){0},
-			    "Y", 0);
-  sv_obj_make_scale(o0, "0, .001, .01, .1, 1.0");
+  sv_obj_new("outer",
+	     (sv_func_t *[]){f},
+	     (int []){0},
+	     "Y");
+  sv_obj_make_scale("0, .001, .01, .1, 1.0");
   
-  sv_obj_t *o1 = sv_obj_new(1,"inner",
-			    (sv_func_t *[]){f},
-			    (int []){1},
-			    "Y", 0);
-  sv_obj_make_scale(o1, "0, .001, .01, .1, 1.0");
+  sv_obj_new("inner",
+	     (sv_func_t *[]){f},
+	     (int []){1},
+	     "Y");
+  sv_obj_make_scale("0, .001, .01, .1, 1.0");
   
   sv_panel_new_2d(0,"Mandel/Julia Fractal",
-		  (sv_obj_t *[]){o0,o1,NULL},
+		  "inner, outer",
 		  "rc,ic,rz,iz,it",
 		  0);
   

Modified: trunk/sushivision/internal.h
===================================================================
--- trunk/sushivision/internal.h	2007-09-07 19:39:58 UTC (rev 13773)
+++ trunk/sushivision/internal.h	2007-09-07 22:07:08 UTC (rev 13774)
@@ -208,7 +208,7 @@
 
 extern sv_panel_t *_sv_panel_new(int number,
 				 char *name, 
-				 sv_obj_t **objectives,
+				 char *objectivelist,
 				 char *dimensionlist,	
 				 unsigned flags);
 extern void _sv_panel_realize(sv_panel_t *p);
@@ -259,4 +259,5 @@
 extern _sv_undo_t **_sv_undo_stack;
 
 extern pthread_key_t _sv_dim_key;
+extern pthread_key_t _sv_obj_key;
 

Modified: trunk/sushivision/main.c
===================================================================
--- trunk/sushivision/main.c	2007-09-07 19:39:58 UTC (rev 13773)
+++ trunk/sushivision/main.c	2007-09-07 22:07:08 UTC (rev 13774)
@@ -58,6 +58,7 @@
 _sv_undo_t **_sv_undo_stack=NULL;
 
 pthread_key_t   _sv_dim_key;
+pthread_key_t   _sv_obj_key;
 
 void _sv_wake_workers(){
   pthread_mutex_lock(&m);

Modified: trunk/sushivision/objective.c
===================================================================
--- trunk/sushivision/objective.c	2007-09-07 19:39:58 UTC (rev 13773)
+++ trunk/sushivision/objective.c	2007-09-07 22:07:08 UTC (rev 13774)
@@ -25,38 +25,35 @@
 #include <errno.h>
 #include "internal.h"
 
-sv_obj_t *sv_obj_new(int number,
-		     char *name,
+sv_obj_t *sv_obj_new(char *name,
 		     sv_func_t **function_map,
 		     int *function_output_map,
-		     char *output_type_map,
-		     unsigned flags){
+		     char *output_type_map){
   
   sv_obj_t *o;
   sv_obj_internal_t *p;
   int i;
   int outputs = strlen(output_type_map);
-
-  if(number<0){
-    fprintf(stderr,"Objective number must be >= 0\n");
+  int number;
+  _sv_token *decl = _sv_tokenize_declparam(name);
+  
+  if(!decl){
+    fprintf(stderr,"sushivision: Unable to parse objective declaration \"%s\".\n",name);
     errno = -EINVAL;
     return NULL;
   }
-  
-  if(number<_sv_objectives){
-    if(_sv_objective_list[number]!=NULL){
-      fprintf(stderr,"Objective number %d already exists\n",number);
-    errno = -EINVAL;
-    return NULL;
-    }
+
+  if(_sv_objectives == 0){
+    number=0;
+    _sv_objective_list = calloc (number+1,sizeof(*_sv_objective_list));
+    _sv_objectives=1;
   }else{
-    if(_sv_objectives == 0){
-      _sv_objective_list = calloc (number+1,sizeof(*_sv_objective_list));
-    }else{
-      _sv_objective_list = realloc (_sv_objective_list,(number+1) * sizeof(*_sv_objective_list));
-      memset(_sv_objective_list + _sv_objectives, 0, sizeof(*_sv_objective_list)*(number +1 - _sv_objectives));
+    for(number=0;number<_sv_objectives;number++)
+      if(!_sv_objective_list[number])break;
+    if(number==_sv_objectives){
+      _sv_objectives=number+1;
+      _sv_objective_list = realloc (_sv_objective_list,_sv_objectives * sizeof(*_sv_objective_list));
     }
-    _sv_objectives=number+1;
   }
   
   o = _sv_objective_list[number] = calloc(1, sizeof(**_sv_objective_list));
@@ -163,12 +160,12 @@
   }
 
   o->number = number;
-  o->name = strdup(name);
+  o->name = strdup(decl->name);
+  o->legend = strdup(decl->label);
   o->output_types = strdup(output_type_map);
   o->type = SV_OBJ_BASIC;
   o->outputs = outputs;
-  o->flags = flags;
-
+  
   /* copy in the maps */
   o->function_map = malloc(outputs * sizeof(*o->function_map));
   o->output_map = malloc(outputs * sizeof(*o->output_map));
@@ -177,14 +174,16 @@
   for(i=0;i<outputs;i++)
     o->function_map[i] = function_map[i]->number;
   
+  pthread_setspecific(_sv_obj_key, (void *)o);
+  _sv_token_free(decl);
+
   return o;
 }
 
 // XXXX need to recompute after
 // XXXX need to add scale cloning to compute to make this safe in callbacks
-int sv_obj_set_scale(sv_obj_t *in,
-		     sv_scale_t *scale){
-  sv_obj_t *o = (sv_obj_t *)in; // unwrap
+int sv_obj_set_scale(sv_scale_t *scale){
+  sv_obj_t *o = sv_obj(0);
 
   if(o->scale)
     sv_scale_free(o->scale); // always a deep copy we own
@@ -198,17 +197,46 @@
 
 // XXXX need to recompute after
 // XXXX need to add scale cloning to compute to make this safe in callbacks
-int sv_obj_make_scale(sv_obj_t *in,
-		      char *format){
-
-  sv_obj_t *o = (sv_obj_t *)in; //unwrap
+int sv_obj_make_scale(char *format){
+  sv_obj_t *o = sv_obj(0);
   sv_scale_t *scale;
   int ret;
 
-  if(!o) return -EINVAL;
-  scale = sv_scale_new(o->name,format);
+  char *name=_sv_tokenize_escape(o->name);
+  char *label=_sv_tokenize_escape(o->legend);
+  char *arg=calloc(strlen(name)+strlen(label)+2,sizeof(*arg));
+
+  strcat(arg,name);
+  strcat(arg,":");
+  strcat(arg,label);
+  free(name);
+  free(label);
+
+  if(!o){
+    free(arg);
+    return -EINVAL;
+  }
+  scale = sv_scale_new(arg,format);
+  free(arg);
   if(!scale)return errno;
 
   o->scale = scale;
   return ret;
 }
+
+sv_obj_t *sv_obj(char *name){
+  int i;
+  
+  if(name == NULL || name == 0 || !strcmp(name,"")){
+    return (sv_obj_t *)pthread_getspecific(_sv_obj_key);
+    
+  }
+  for(i=0;i<_sv_objectives;i++){
+    sv_obj_t *o=_sv_objective_list[i];
+    if(o && o->name && !strcmp(name,o->name)){
+      pthread_setspecific(_sv_obj_key, (void *)o);
+      return o;
+    }
+  }
+  return NULL;
+}

Modified: trunk/sushivision/panel-1d.c
===================================================================
--- trunk/sushivision/panel-1d.c	2007-09-07 19:39:58 UTC (rev 13773)
+++ trunk/sushivision/panel-1d.c	2007-09-07 22:07:08 UTC (rev 13774)
@@ -1421,11 +1421,11 @@
 sv_panel_t *sv_panel_new_1d(int number,
 			    char *name,
 			    sv_scale_t *scale,
-			    sv_obj_t **objectives,
+			    char *objectivelist,
 			    char *dimensionlist,	
 			    unsigned flags){
   
-  sv_panel_t *p = _sv_panel_new(number,name,objectives,dimensionlist,flags);
+  sv_panel_t *p = _sv_panel_new(number,name,objectivelist,dimensionlist,flags);
   _sv_panel1d_t *p1;
 
   if(!p)return p;

Modified: trunk/sushivision/panel-2d.c
===================================================================
--- trunk/sushivision/panel-2d.c	2007-09-07 19:39:58 UTC (rev 13773)
+++ trunk/sushivision/panel-2d.c	2007-09-07 22:07:08 UTC (rev 13774)
@@ -1927,12 +1927,12 @@
 
 sv_panel_t *sv_panel_new_2d(int number,
 			    char *name, 
-			    sv_obj_t **objectives,
+			    char *objectivelist,
 			    char *dimensionlist,
 			    unsigned flags){
   
   int i,j;
-  sv_panel_t *p = _sv_panel_new(number,name,objectives,dimensionlist,flags);
+  sv_panel_t *p = _sv_panel_new(number,name,objectivelist,dimensionlist,flags);
   if(!p)return NULL;
 
   _sv_panel2d_t *p2 = calloc(1, sizeof(*p2));

Modified: trunk/sushivision/panel-xy.c
===================================================================
--- trunk/sushivision/panel-xy.c	2007-09-07 19:39:58 UTC (rev 13773)
+++ trunk/sushivision/panel-xy.c	2007-09-07 22:07:08 UTC (rev 13774)
@@ -1608,11 +1608,11 @@
 			    char *name,
 			    sv_scale_t *xscale,
 			    sv_scale_t *yscale,
-			    sv_obj_t **objectives,
+			    char *objectivelist,
 			    char *dimensionlist,	
 			    unsigned flags){
 
-  sv_panel_t *p = _sv_panel_new(number,name,objectives,dimensionlist,flags);
+  sv_panel_t *p = _sv_panel_new(number,name,objectivelist,dimensionlist,flags);
   _sv_panelxy_t *xy;
 
   if(!p)return NULL;

Modified: trunk/sushivision/panel.c
===================================================================
--- trunk/sushivision/panel.c	2007-09-07 19:39:58 UTC (rev 13773)
+++ trunk/sushivision/panel.c	2007-09-07 22:07:08 UTC (rev 13774)
@@ -802,12 +802,13 @@
 
 sv_panel_t * _sv_panel_new(int number,
 			   char *name, 
-			   sv_obj_t **objectives,
+			   char *objectivelist,
 			   char *dimensionlist,
 			   unsigned flags){
 
   sv_panel_t *p;
   _sv_tokenlist *dim_tokens;
+  _sv_tokenlist *obj_tokens;
   int i;
 
   if(number<0){
@@ -843,11 +844,12 @@
   p->private->def_oversample_d = p->private->oversample_d = 1;
 
   i=0;
-  while(objectives && objectives[i])i++;
-  p->objectives = i;
-  p->objective_list = malloc(i*sizeof(*p->objective_list));
+  obj_tokens = _sv_tokenize_namelist(objectivelist);
+  p->objectives = obj_tokens->n;
+  p->objective_list = malloc(p->objectives*sizeof(*p->objective_list));
   for(i=0;i<p->objectives;i++){
-    p->objective_list[i].o = (sv_obj_t *)objectives[i];
+    char *name = obj_tokens->list[i]->name;
+    p->objective_list[i].o = sv_obj(name);
     p->objective_list[i].p = p;
   }
 
@@ -879,6 +881,8 @@
     p->dimension_list[i].p = p;
   }
 
+  _sv_tokenlist_free(obj_tokens);
+  _sv_tokenlist_free(dim_tokens);
   return p;
 }
 

Modified: trunk/sushivision/sushivision.h
===================================================================
--- trunk/sushivision/sushivision.h	2007-09-07 19:39:58 UTC (rev 13773)
+++ trunk/sushivision/sushivision.h	2007-09-07 22:07:08 UTC (rev 13774)
@@ -139,6 +139,7 @@
 struct sv_obj { 
   int number;
   char *name;
+  char *legend;
   enum sv_obj_type type;
 
   sv_scale_t *scale;
@@ -152,23 +153,16 @@
   sv_obj_internal_t *private;
 };
 
-sv_obj_t            *sv_obj_new (int number,
-				 char *name,
+sv_obj_t            *sv_obj_new (char *decl,
 				 sv_func_t **function_map,
 				 int *function_output_map,
-				 char *output_type_map,
-				 unsigned flags);
+				 char *output_type_map);
 
-sv_obj_t   *sv_obj_new_defaults (int number,
-				 char *name,
-				 sv_func_t *function,
-				 unsigned flags);
+sv_obj_t                *sv_obj (char *name);
 
-int            sv_obj_set_scale (sv_obj_t *o,
-				 sv_scale_t *scale);
+int            sv_obj_set_scale (sv_scale_t *scale);
 
-int           sv_obj_make_scale (sv_obj_t *o,
-				 char *format);
+int           sv_obj_make_scale (char *format);
 
 /* panels ********************************************************/
 
@@ -210,7 +204,7 @@
 sv_panel_t     *sv_panel_new_1d (int number,
 				 char *name,
 				 sv_scale_t *y_scale,
-				 sv_obj_t **objectives,
+				 char *objectives,
 				 char *dimensions,	
 				 unsigned flags);
 
@@ -218,13 +212,13 @@
 				 char *name,
 				 sv_scale_t *x_scale,
 				 sv_scale_t *y_scale,
-				 sv_obj_t **objectives,
+				 char *objectives,
 				 char *dimensions,	
 				 unsigned flags);
 
 sv_panel_t     *sv_panel_new_2d (int number,
 				 char *name, 
-				 sv_obj_t **objectives,
+				 char *objectives,
 				 char *dimensions,
 				 unsigned flags);
 



More information about the commits mailing list