Changeset bc1d648 for variable.c


Ignore:
Timestamp:
Jul 3, 2011, 8:08:06 PM (10 years ago)
Author:
Jason Gross <jgross@mit.edu>
Branches:
master, release-1.8, release-1.9
Children:
ca54fd6
Parents:
82e93c9
git-author:
Jason Gross <jgross@mit.edu> (06/27/11 01:53:42)
git-committer:
Jason Gross <jgross@mit.edu> (07/03/11 20:08:06)
Message:
Drop require_type

It's not doing much for us (and would do even less after the next
commit).

I'm not sure whether or not we should type-check owl_variable_get_*
File:
1 edited

Legend:

Unmodified
Added
Removed
  • variable.c

    rce68f23 rbc1d648  
    662662}
    663663
    664 void owl_variable_dict_newvar_string(owl_vardict * vd, const char *name, const char *summ, const char * desc, const char * initval) {
    665   owl_variable *old = owl_variable_get_var(vd, name, OWL_VARIABLE_STRING);
    666   if(old) {
     664void owl_variable_dict_newvar_string(owl_vardict *vd, const char *name, const char *summ, const char *desc, const char *initval)
     665{
     666  owl_variable *old = owl_variable_get_var(vd, name);
     667  if (old && old->type == OWL_VARIABLE_STRING) {
    667668    owl_variable_update(old, summ, desc);
    668669    g_free(old->pval_default);
     
    682683}
    683684
    684 void owl_variable_dict_newvar_int(owl_vardict * vd, const char *name, const char *summ, const char * desc, int initval) {
    685   owl_variable *old = owl_variable_get_var(vd, name, OWL_VARIABLE_INT);
    686   if(old) {
     685void owl_variable_dict_newvar_int(owl_vardict *vd, const char *name, const char *summ, const char *desc, int initval)
     686{
     687  owl_variable *old = owl_variable_get_var(vd, name);
     688  if (old && old->type == OWL_VARIABLE_INT) {
    687689    owl_variable_update(old, summ, desc);
    688690    old->ival_default = initval;
     
    703705}
    704706
    705 void owl_variable_dict_newvar_bool(owl_vardict * vd, const char *name, const char *summ, const char * desc, int initval) {
    706   owl_variable *old = owl_variable_get_var(vd, name, OWL_VARIABLE_BOOL);
    707   if(old) {
     707void owl_variable_dict_newvar_bool(owl_vardict *vd, const char *name, const char *summ, const char *desc, bool initval)
     708{
     709  owl_variable *old = owl_variable_get_var(vd, name);
     710  if (old && old->type == OWL_VARIABLE_BOOL) {
    708711    owl_variable_update(old, summ, desc);
    709712    old->ival_default = initval;
     
    847850}
    848851
    849 owl_variable *owl_variable_get_var(const owl_vardict *d, const char *name, int require_type) {
     852owl_variable *owl_variable_get_var(const owl_vardict *d, const char *name)
     853{
    850854  owl_variable *v;
    851855  if (!name) return(NULL);
    852856  v = owl_dict_find_element(d, name);
    853   if (v == NULL || !v->get_fn || v->type != require_type) return(NULL);
     857  if (v == NULL || !v->get_fn) return NULL;
    854858  return v;
    855859}
    856860
    857861/* returns a reference */
    858 const void *owl_variable_get(const owl_vardict *d, const char *name, int require_type) {
    859   owl_variable *v = owl_variable_get_var(d, name, require_type);
     862const void *owl_variable_get(const owl_vardict *d, const char *name)
     863{
     864  const owl_variable *v = owl_variable_get_var(d, name);
    860865  if(v == NULL) return NULL;
    861866  return v->get_fn(v);
     
    864869/* returns a reference */
    865870const char *owl_variable_get_string(const owl_vardict *d, const char *name) {
    866   return owl_variable_get(d,name, OWL_VARIABLE_STRING);
     871  /* TODO: (Decide whether or not to) type check? */
     872  return owl_variable_get(d, name);
    867873}
    868874
    869875/* returns a reference */
    870876const void *owl_variable_get_other(const owl_vardict *d, const char *name) {
    871   return owl_variable_get(d,name, OWL_VARIABLE_OTHER);
     877  /* TODO: (Decide whether or not to) type check? */
     878  return owl_variable_get(d, name);
    872879}
    873880
    874881int owl_variable_get_int(const owl_vardict *d, const char *name) {
    875   const int *pi;
    876   pi = owl_variable_get(d,name,OWL_VARIABLE_INT);
    877   if (!pi) return(-1);
    878   return(*pi);
     882  /* TODO: (Decide whether or not to) type check? */
     883  const int *pi = owl_variable_get(d, name);
     884  if (!pi) return -1;
     885  return *pi;
    879886}
    880887
    881888int owl_variable_get_bool(const owl_vardict *d, const char *name) {
    882   const int *pi;
    883   pi = owl_variable_get(d,name,OWL_VARIABLE_BOOL);
    884   if (!pi) return(-1);
    885   return(*pi);
     889  /* TODO: (Decide whether or not to) type check? */
     890  const int *pi = owl_variable_get(d, name);
     891  if (!pi) return -1;
     892  return *pi;
    886893}
    887894
Note: See TracChangeset for help on using the changeset viewer.