示例#1
0
int users_search(mongo* conn, User* users, int limit) {
  int pos = 0;
  mongo_cursor cursor[1];
  bson_iterator iterator[1];
  mongo_cursor_init(cursor, conn, "ruby-mongo-console.users");
  // mongo_cursor_set_query
  mongo_cursor_set_limit(cursor, limit);

  while(mongo_cursor_next(cursor) == MONGO_OK) {
    const char* s;

    s = get_field_value(iterator, cursor, "name");
    if (s) {
      users[pos].name_len = strlen(s);
      users[pos].name = new_str(s, users[pos].name_len);
    } else {
      users[pos].name_len = 0;
      users[pos].name = NULL;
    }

    s = get_field_value(iterator, cursor, "bio");
    if (s) {
      users[pos].bio_len = strlen(s);
      users[pos].bio = new_str(s, users[pos].bio_len);
    } else {
      users[pos].bio_len = 0;
      users[pos].bio = NULL;
    }

    pos++;
  }

  mongo_cursor_destroy(cursor);
  return pos;
}
示例#2
0
bool formatter_data_to_keyval(const struct formatter *f,
                              const uint8_t *data, struct keyval_list *kv_list)

{
    unsigned int i;
    char buf[80];
    bool success = true;
    struct keyval kv;

    timestamp(f, kv_list);

    for (i = 0; i < f->num_fields && success; i++) {
        const spt value = get_field_value(&f->fields[i], data);

        memset(buf, 0, sizeof(buf));
        field_data_to_str(buf, sizeof(buf), value, &f->fields[i]);

        kv.key   = f->fields[i].name;
        kv.value = buf;

        success = keyval_list_append(kv_list, &kv);
    }

    return success;
}
示例#3
0
void
add_field (GtkListStore *store, const char *key, const char *title, int is_prop, DB_playItem_t **tracks, int numtracks) {
    // get value to edit
    const char *mult = is_prop ? "" : _("[Multiple values] ");
    char val[MAX_GUI_FIELD_LEN];
    size_t ml = strlen (mult);
    memcpy (val, mult, ml+1);
    int n = get_field_value (val + ml, sizeof (val) - ml, key, deadbeef->pl_find_meta_raw, equals_ptr, tracks, numtracks);

    GtkTreeIter iter;
    gtk_list_store_append (store, &iter);
    if (!is_prop) {
        if (n) {
            gtk_list_store_set (store, &iter, 0, title, 1, val, 2, key, 3, n ? 1 : 0, -1);
        }
        else {
            deadbeef->pl_lock ();
            const char *val = deadbeef->pl_find_meta_raw (tracks[0], key);
            if (!val) {
                val = "";
            }
            gtk_list_store_set (store, &iter, 0, title, 1, val, 2, key, 3, n ? 1 : 0, -1);
            deadbeef->pl_unlock ();
        }
    }
    else {
        gtk_list_store_set (store, &iter, 0, title, 1, n ? val : val + ml, -1);
    }
}
示例#4
0
文件: dataset.cpp 项目: gellis12/xbmc
const field_value Dataset::get_field_value(const char *f_name) {
  if (ds_state != dsInactive)
  {
    if (ds_state == dsEdit || ds_state == dsInsert){
      for (unsigned int i=0; i < edit_object->size(); i++)
        if (str_compare((*edit_object)[i].props.name.c_str(), f_name)==0) {
          return (*edit_object)[i].val;
        }
      throw DbErrors("Field not found: %s",f_name);
    }
    else
    {
      //Lets try to reuse a string ->index conversation
      if (get_index_map_entry(f_name))
        return get_field_value(static_cast<int>(fieldIndexMap_Entries[fieldIndexMapID].fieldIndex));

      const char* name=strstr(f_name, ".");
      if (name)
        name++;

      for (unsigned int i=0; i < fields_object->size(); i++) 
        if (str_compare((*fields_object)[i].props.name.c_str(), f_name) == 0 || (name && str_compare((*fields_object)[i].props.name.c_str(), name) == 0)) {
          fieldIndexMap_Entries[fieldIndexMapID].fieldIndex = i;
          return (*fields_object)[i].val;
        }
    }
    throw DbErrors("Field not found: %s",f_name);
  }
  throw DbErrors("Dataset state is Inactive");
  //field_value fv;
  //return fv;
}
示例#5
0
int CMySQLConnection::get_field_value(std::string* value, const char* format, ...)
{
    va_list args;
    va_start(args, format);
    utils::VaListHelper vlh(args);

    return get_field_value(value, format, args);
}
示例#6
0
static VALUE rb_thrift_struct_write(VALUE self, VALUE protocol) {
  // call validate
  rb_funcall(self, validate_method_id, 0);

  // check_native_proto_method_table(protocol);

  // write struct begin
  mt->write_struct_begin(protocol, rb_class_name(CLASS_OF(self)));

  // iterate through all the fields here
  VALUE struct_fields = STRUCT_FIELDS(self);

  VALUE struct_field_ids_unordered = rb_funcall(struct_fields, keys_method_id, 0);
  VALUE struct_field_ids_ordered = rb_funcall(struct_field_ids_unordered, sort_method_id, 0);

  int i = 0;
  for (i=0; i < RARRAY_LEN(struct_field_ids_ordered); i++) {
    VALUE field_id = rb_ary_entry(struct_field_ids_ordered, i);

    VALUE field_info = rb_hash_aref(struct_fields, field_id);

    VALUE ttype_value = rb_hash_aref(field_info, type_sym);
    int ttype = FIX2INT(ttype_value);
    VALUE field_name = rb_hash_aref(field_info, name_sym);

    VALUE field_value = get_field_value(self, field_name);

    if (!NIL_P(field_value)) {
      mt->write_field_begin(protocol, field_name, ttype_value, field_id);

      write_anything(ttype, field_value, protocol, field_info);

      mt->write_field_end(protocol);
    }
  }

  mt->write_field_stop(protocol);

  // write struct end
  mt->write_struct_end(protocol);

  return Qnil;
}
示例#7
0
double BGMBase::size(double u, double v, double w)
{
  return get_field_value(u, v, w, sizeField);
}
示例#8
0
/*
**  mexFunction is the interface function to MATLAB.
**
** plhs - pointer to left-hand OUTPUT mxArrays
** nlhs - number of left-hand OUTPUT arrays
** prhs - pointer to right-hand INPUT mxArrays
** nrhs - number of right-hand INPUT arrays
**
*/
void mexFunction(int nlhs, mxArray *plhs[],
		 int nrhs, const mxArray *prhs[])
{
int msize[]={0,0,0};
int arg_ndims;
int out_dims[]={0,0,0};
buffer *bf_image,*bf_pvec,*bf_pvec2;
ebuffer *bf_elist,*bf_thres=NULL;
buffer *bf_mvec,*bf_mvec2,*bf_arate,*bf_arate2;
buffer *bf_ecdf;
int validcnt,nofedges,rows,cols,ndim;
edgeval d_max;
double d_mean;
mxArray *mx_pvec,*mx_arate,*mx_elist;
int tslist_flag=1;
int min_size=60;           /* Default */
double ainc=1.05;          /* Default */
double min_marginf=0.0015; /* Default */
edgeval min_margin;        /* Value after conversion */
fpnum res=1e-4;            /* Default */
int Ns=10;                 /* Default */
int timesteps=200;         /* Default */
int filter_size=3;         /* Default */
int n8flag=0;              /* Default */
int normfl=1;              /* Default */
int blurfl=0;              /* Default */
int verbosefl=1;           /* Default */


  /* Argument count check */
  if((nrhs ==0)||(nrhs > 2)) {
    mexPrintf("Usage: [<mvec>,<pvec>,<arate>,<elist2>]=detect_mscr(<image>[,<pars>])\n");
    
    if((nrhs > 2))
      mexErrMsgTxt("Error: 1 or 2 input arguments required.\n");
    return;
  }

  /* Parse arg 1 (RGB or greyscale image) */
  msize[0]=-1;msize[1]=-1;msize[2]=-1;
  arg_ndims = mxGetNumberOfDimensions(prhs[0]);
  if((arg_ndims!=2)&&(arg_ndims!=3)) {
    mexPrintf("Error: <image> should be 2D or 3D.\n");
    return;
  }
  if(!type_check("image",prhs[0],mxDOUBLE_CLASS,arg_ndims,msize))
    return;
  
  bf_image=buffer_encapsulate(prhs[0]);
  rows = bf_image->rows;
  cols = bf_image->cols;
  ndim = bf_image->ndim;
  if((ndim!=1)&&(ndim!=3)) {
    mexPrintf("Size mismatch: <Im> should be MxNxD where D=1 or 3.\n");
    free(bf_image);
    return;
  }

  /* Parse arg 2 (pars struct) */
  if(nrhs>1) {
    msize[0]=1;msize[1]=1;
    if(!type_check("pars",prhs[1],mxSTRUCT_CLASS,2,msize)) {
      free(bf_image);
      return;
    }

    min_marginf = get_field_value(prhs[1],"min_margin",min_marginf);
    min_margin  = min_marginf*EDGE_SCALE+EDGE_OFFSET;
    timesteps   = get_field_value(prhs[1],"timesteps",timesteps);
    min_size    = get_field_value(prhs[1],"min_size",min_size);
    ainc        = get_field_value(prhs[1],"ainc",ainc);
    filter_size = get_field_value(prhs[1],"filter_size",filter_size);
    n8flag      = get_field_value(prhs[1],"n8flag",n8flag);
    normfl      = get_field_value(prhs[1],"normfl",normfl);
    blurfl      = get_field_value(prhs[1],"blurfl",blurfl);
    verbosefl   = get_field_value(prhs[1],"verbosefl",verbosefl);
  }

  if(verbosefl) {
    /* Display parameter settings */
    mexPrintf("\nDescriptor parameter settings:\n");
    mexPrintf(" min_margin: %g\n",min_marginf);
    mexPrintf("  timesteps: %d\n",timesteps);
    mexPrintf("   min_size: %d\n",min_size);
    mexPrintf("       ainc: %g\n",ainc);
    mexPrintf("filter_size: %d\n",filter_size);
    mexPrintf("     n8flag: %d\n",n8flag);
    mexPrintf("     normfl: %d\n",normfl);
    mexPrintf("     blurfl: %d\n",blurfl);
    mexPrintf("  verbosefl: %d\n",verbosefl);
  }

 /* Set edge list size */
 if(n8flag) 
   nofedges=4*rows*cols-3*rows-3*cols+2;
 else
   nofedges=2*rows*cols-rows-cols;

 if(nlhs>0) {
   /* Allocate out elist */
   out_dims[0]=4;
   out_dims[1]=nofedges;
#ifdef INTEGER_EDGES
   mx_elist = mxCreateNumericArray(2,out_dims,mxINT32_CLASS,mxREAL);
#else
   mx_elist = mxCreateNumericArray(2,out_dims,mxDOUBLE_CLASS,mxREAL);
#endif
   bf_elist = ebuffer_encapsulate(mx_elist);   

   /* Call computation function */

   if(blurfl) {
     /* Blur input image instead */
     blur_buffer(bf_image,filter_size);
     filter_size=1;
   }
   if(filter_size%2) {
     if(n8flag) {
       if(normfl)
	 d_max=image_to_edgelist_blur_n8_norm(bf_image,bf_elist,filter_size,verbosefl);
       else
	 d_max=image_to_edgelist_blur_n8(bf_image,bf_elist,filter_size,verbosefl);
     } else {
       if(normfl)
	 d_max=image_to_edgelist_blur_norm(bf_image,bf_elist,filter_size,verbosefl);
       else
	 d_max=image_to_edgelist_blur(bf_image,bf_elist,filter_size,verbosefl);
     }
   } else {
     mexErrMsgTxt("bfz should be odd.\n");
/*      d_max=image_to_edgelist_grad(bf_image,bf_elist,filter_size); */
   }
   if(tslist_flag) {
     /* Call cdf sampling */
/*      bf_ecdf=buffer_new(2,Ns,1); */
/*      edgelist_to_cdf(bf_elist,bf_ecdf,d_max); */

     /* Call thresholds interpolation */
     bf_thres=ebuffer_new(1,timesteps,1);
     if(verbosefl) mexPrintf("order=%d\n",ndim);
     d_mean=evolution_thresholds2(bf_elist,bf_thres,ndim);
     if(verbosefl) mexPrintf("d_mean=%g\n",d_mean);
     /* Try linear dependence on mean edge strength */
/*      min_margin=d_mean*min_margin_sc; */
   }

   /* Call computation function */
   edgelist_to_bloblist(&bf_mvec,&bf_pvec,&bf_arate,bf_image,bf_elist,bf_thres,min_size,ainc,res,verbosefl);
   center_moments(bf_mvec,bf_pvec);
   validcnt=bloblist_mark_invalid(bf_mvec,min_size,bf_arate,(fpnum)min_margin);
   validcnt=bloblist_shape_invalid(bf_mvec);
   if(verbosefl) mexPrintf("validcnt=%d\n",validcnt);

   if(tslist_flag) {
     ebuffer_free(bf_thres);
/*      buffer_free(bf_ecdf); */
   }

   /* Allocate out mvec */
   out_dims[0]=6;
   out_dims[1]=validcnt;
   plhs[0] = mxCreateNumericArray(2,out_dims,mxDOUBLE_CLASS,mxREAL);
   bf_mvec2 = buffer_encapsulate(plhs[0]);

   /* Allocate out pvec */
   out_dims[0]=3;
   out_dims[1]=validcnt;
   mx_pvec = mxCreateNumericArray(2,out_dims,mxDOUBLE_CLASS,mxREAL);
   bf_pvec2 = buffer_encapsulate(mx_pvec);

   /* Allocate out arates */
   out_dims[0]=bf_arate->rows;
   out_dims[1]=validcnt;
   mx_arate = mxCreateNumericArray(2,out_dims,mxDOUBLE_CLASS,mxREAL);
   bf_arate2 = buffer_encapsulate(mx_arate);

   bloblist_compact(bf_mvec,bf_mvec2,bf_pvec,bf_pvec2,bf_arate,bf_arate2);
   free(bf_mvec2);    /* Only release struct */
   free(bf_pvec2);    /* Only release struct */
   free(bf_arate2);   /* Only release struct */
   free(bf_elist);    /* Only release struct */

   buffer_free(bf_mvec);   /* Release non-compacted mvec */
   buffer_free(bf_pvec);   /* Release non-compacted pvec */
   buffer_free(bf_arate);  /* Release non-compacted arate */
 }

 if(nlhs>1) plhs[1]=mx_pvec; 

 if(nlhs>2) plhs[2]=mx_arate; 

 if(nlhs>3) plhs[3]=mx_elist; 

 /* Free memory */
 free(bf_image);  /* Only release struct */
}
static int accesslog_parse_format(char * pformat, int len) 
{
	int i, j;
	char ch;

	format = pformat;

	while(1) {
		ch=get_next_char();
		if(ch==0) break;

		// It is string.
		if(ch != '%') {
			ff_ptr[ff_used].field = FORMAT_STRING;
			ff_ptr[ff_used].string[0] = ch;

			i=1;
			while(1) {
				ch=get_next_char();
				if((ch=='%')||(ch==0)) break;
				ff_ptr[ff_used].string[i]=ch;
				i++;
			}
			ff_ptr[ff_used].string[i]=0;

			ff_used++;
			if(ch==0) break; // break the whole while(1) loop
		}
	
		ff_ptr[ff_used].string[0] = 0;

		/* search for the terminating command */
		ch=get_next_char();
		if (ch == '{') {
			i=0;
			while(1) {
				ch=get_next_char();
				if (ch == 0) {
					al_log_basic("\nERROR: failed to parse configuration file.\n");
					exit(1);
				}
				else if (ch == '}') break;
				ff_ptr[ff_used].string[i]=ch;
				i++;
			}
			ff_ptr[ff_used].string[i]=0;

			// Get next char after '}'
			get_field_value(get_next_char());
			if (ff_ptr[ff_used].field == FORMAT_COOKIE) {
				/* 
				 * we need to adjust the string as .c*k<cookiname> 
				 * BUG: 64 bytes should be enough.
				 */
				char tmp[64];
				strcpy(tmp, ff_ptr[ff_used].string);
				snprintf(ff_ptr[ff_used].string, 64, ".c*k%s", tmp);
			}
		}
		else {
			get_field_value(ch);
			//printf("%d : %d\n", ff_>used, ff_>ptr[ff_>used]->field);
		}

		ff_used++;

	}

	// Special case for URI/Query_string
	// We want to do in this way.
	for(j=0; j<ff_used; j++) {
		switch (ff_ptr[j].field) {
		case FORMAT_URL:
		case FORMAT_QUERY_STRING:
		case FORMAT_REQUEST_LINE:
			strcpy(&ff_ptr[j].string[0], "uri");
			break;
		case FORMAT_HTTP_HOST:
			strcpy(&ff_ptr[j].string[0], "host");
			break;
		case FORMAT_REMOTE_USER:
			strcpy(&ff_ptr[j].string[0], "user"); // HTTP user field.
			break;
		default:
			break;
		}
	}

	return 0;
}
示例#10
0
double frameFieldBackgroundMesh2D::get_smoothness(double u, double v)
{
    return get_field_value(u,v,0.,smoothness);
}