Example #1
0
/**
 * This function deletes number of entries from list specified by range
 *
 * \param group image group from which we will remove records
 * \param range range specifying entries
 * \return OK on success
 */
RCode group_delete_range(ImageGroup* group, Range range) {
	guint	i = 0;

	ASSERT(NULL != group);
	ASSERT(NULL != group->list);

	TRACE_MESSAGE(IGRP, TL_INFO,
			"Removing range (group='%s',range=<%d,%d>)", group->name, range.start, range.end
		);

	// check if index is in range
	if ( FAIL == range_check_bounds(range, 0, group->list->len - 1) ) {
		ERROR_SET(ERROR.OUT_OF_RANGE);
		ERROR_NOTE("Supplied range is out of bounds (group='%s',range=<%d,%d>,min=0,max=%d)",
				group->name, range.start,range.end,group->list->len-1
			);
		return FAIL;
	}

	// unreference images that will be removed
	for (i = range.start; i <= range.end; i++) {
		ImageGroupRecord record = g_array_index(group->list, ImageGroupRecord, i);

		/** \todo Check what to do with the call return code */
		image_unref(record.image);
	}

	group->list = g_array_remove_range(group->list, range.start, range.end - range.start + 1);

	return OK;
}
Example #2
0
void
context_info_db_purge(ContextInfoDB *self)
{
  g_hash_table_remove_all(self->index);
  if (self->data->len > 0)
    self->data = g_array_remove_range(self->data, 0, self->data->len);
}
Example #3
0
/**
 * Sends logic sample data off to the session bus.
 *
 * @param data The raw sample data.
 * @ch_state Pointer to the state of the channel whose data we're processing.
 * @sdi The device instance.
 *
 * @return SR_ERR when data is trucated, SR_OK otherwise.
 */
static int dlm_digital_samples_send(GArray *data,
		struct sr_dev_inst *sdi)
{
	struct dev_context *devc;
	struct scope_state *model_state;
	uint32_t samples;
	struct sr_datafeed_logic logic;
	struct sr_datafeed_packet packet;

	devc = sdi->priv;
	model_state = devc->model_state;
	samples = model_state->samples_per_frame;

	if (data->len < samples * sizeof(uint8_t)) {
		sr_err("Truncated waveform data packet received.");
		return SR_ERR;
	}

	logic.length = samples;
	logic.unitsize = 1;
	logic.data = data->data;
	packet.type = SR_DF_LOGIC;
	packet.payload = &logic;
	sr_session_send(sdi, &packet);

	g_array_remove_range(data, 0, samples * sizeof(uint8_t));

	return SR_OK;
}
Example #4
0
void
npd_remove_all_control_points (NPDModel *model)
{
  g_array_remove_range (model->control_points,
                        0,
                        model->control_points->len);
}
static gint
refresh_active_playlist (xmmsv_t *val, void *udata)
{
	cli_cache_t *cache = (cli_cache_t *) udata;
	xmmsv_list_iter_t *it;
	gint32 id;

	if (!xmmsv_is_error (val)) {
		/* Reset array */
		if (cache->active_playlist->len > 0) {
			gint len = cache->active_playlist->len;
			cache->active_playlist = g_array_remove_range (cache->active_playlist,
			                                               0, len);
		}

		xmmsv_get_list_iter (val, &it);

		/* .. and refill it */
		while (xmmsv_list_iter_valid (it)) {
			xmmsv_t *entry;
			xmmsv_list_iter_entry (it, &entry);
			xmmsv_get_int (entry, &id);
			g_array_append_val (cache->active_playlist, id);

			xmmsv_list_iter_next (it);
		}
	}

	freshness_received (&cache->freshness_active_playlist);

	return TRUE;
}
Example #6
0
UString*
ustring_erase(UString* str, guint pos, guint len)
{
    if (len > 0)
	return g_array_remove_range(str, pos, len);
    else
	return str;
}
void nm_ip4_config_reset_nis_servers (NMIP4Config *config)
{
    NMIP4ConfigPrivate *priv;

    g_return_if_fail (NM_IS_IP4_CONFIG (config));

    priv = NM_IP4_CONFIG_GET_PRIVATE (config);
    if (priv->nis->len)
        g_array_remove_range (priv->nis, 0, priv->nis->len);
}
/**
 * nm_setting_ip4_config_clear_dns:
 * @setting: the #NMSettingIP4Config
 *
 * Removes all configured DNS servers.
 **/
void
nm_setting_ip4_config_clear_dns (NMSettingIP4Config *setting)
{
	NMSettingIP4ConfigPrivate *priv;

	g_return_if_fail (NM_IS_SETTING_IP4_CONFIG (setting));

	priv = NM_SETTING_IP4_CONFIG_GET_PRIVATE (setting);
	g_array_remove_range (priv->dns, 0, priv->dns->len);
}
Example #9
0
PetscErrorCode IrregularNodeListUpdate_2D( int x, int y, LevelSet ls )
{
  int i, j, k, I, J, ni, nj, bc;
  const int nei[4][2] = {1,0,0,1,-1,0,0,-1};
  IrregularNode n;
  PetscReal **phi = ls->g->v2;
  PetscReal sten[3][3];
  GArray *g = ls->irregularNodes;
  PetscErrorCode ierr;
  
  PetscFunctionBegin;

  n.z = 0;
  n.oz = 0;

//  GLib errors are generated when index = 0 < len = 0
  if( g->len != 0 )
  {
    g_array_remove_range(g, 0, g->len);
  }
  
//  Index irregular grid points
  for( j = 2; j < ls->g->n.y-2; ++j)
  {
    for( i = 2; i < ls->g->n.x-2; ++i)
    {
//      printf("%d\t%d\n", i,j);
      for( J = -1; J < 2; ++J)
      {
        for( I = -1; I < 2; ++I)
        {
          sten[J+1][I+1] = (phi[j+J+y][i+I+x] + phi[j+J][i+I]) / 2.;
        }
      }
      for( k = 0; k < 4; ++k)
      {
        ni = 1 + nei[k][0];
        nj = 1 + nei[k][1];
        if( sten[1][1] * sten[ni][nj] <= 0. )
        {
          n.x = i;
          n.y = j;
          n.sign = PetscSign( sten[1][1] );
          OrthogonalProjection2D( sten, &n.ox, &n.oy);
          n.ox += x / 2.; //TODO: need to test OP shift direction
          n.oy += y / 2.;
          g_array_append_val(g, n );
          break;
        }
      }
    }
  }
  
  PetscFunctionReturn(0);
}
Example #10
0
File: mfp_comm.c Project: wrl/mfp
static void * 
mfp_comm_io_writer_thread(void * tdata) 
{
    int quitreq = 0;
    char msgbuf[MFP_MAX_MSGSIZE];
    GArray * rdata;
    struct timespec alarmtime;
    struct timeval nowtime;
    mfp_out_data r;
    char pbuff[32];

    rdata = g_array_new(TRUE, TRUE, sizeof(mfp_out_data));
    comm_io_writer_thread_ready = 1; 

    while(!quitreq) {
        /* wait for a signal that there's data to write */ 
        pthread_mutex_lock(&outgoing_lock);
        if (outgoing_queue_read == outgoing_queue_write) { 
            pthread_cond_wait(&outgoing_cond, &outgoing_lock);
        }

        gettimeofday(&nowtime, NULL);
        alarmtime.tv_sec = nowtime.tv_sec; 
        alarmtime.tv_nsec = nowtime.tv_usec*1000 + 10000000;

        if (outgoing_queue_read == outgoing_queue_write) { 
            pthread_cond_timedwait(&outgoing_cond, &outgoing_lock, &alarmtime);
        }

        /* copy/clear C response objects */
        if(outgoing_queue_read != outgoing_queue_write) {
            while(outgoing_queue_read != outgoing_queue_write) {
                r = outgoing_queue[outgoing_queue_read];
                g_array_append_val(rdata, r);
                outgoing_queue_read = (outgoing_queue_read+1) % REQ_BUFSIZE;
            }
        }
        pthread_mutex_unlock(&outgoing_lock);

        for(int reqno=0; reqno < rdata->len; reqno++) {
            r = g_array_index(rdata, mfp_out_data, reqno);
            mfp_comm_send_buffer(r.msgbuf, r.msglen);
        }
        if (rdata->len > 0) { 
            g_array_remove_range(rdata, 0, rdata->len);
        }

        pthread_mutex_lock(&comm_io_lock);
        quitreq = comm_io_quitreq;
        pthread_mutex_unlock(&comm_io_lock);
    }


}
Example #11
0
/**
 * Turns raw sample data into voltages and sends them off to the session bus.
 *
 * @param data The raw sample data.
 * @ch_state Pointer to the state of the channel whose data we're processing.
 * @sdi The device instance.
 *
 * @return SR_ERR when data is trucated, SR_OK otherwise.
 */
static int dlm_analog_samples_send(GArray *data,
		struct analog_channel_state *ch_state,
		struct sr_dev_inst *sdi)
{
	uint32_t i, samples;
	float voltage, range, offset;
	GArray *float_data;
	struct dev_context *devc;
	struct scope_state *model_state;
	struct sr_channel *ch;
	struct sr_datafeed_analog analog;
	struct sr_datafeed_packet packet;

	devc = sdi->priv;
	model_state = devc->model_state;
	samples = model_state->samples_per_frame;
	ch = devc->current_channel->data;

	if (data->len < samples * sizeof(uint8_t)) {
		sr_err("Truncated waveform data packet received.");
		return SR_ERR;
	}

	range = ch_state->waveform_range;
	offset = ch_state->waveform_offset;

	/*
	 * Convert byte sample to voltage according to
	 * page 269 of the Communication Interface User's Manual.
	 */
	float_data = g_array_new(FALSE, FALSE, sizeof(float));
	for (i = 0; i < samples; i++) {
		voltage = (float)g_array_index(data, int8_t, i);
		voltage = (range * voltage /
				DLM_DIVISION_FOR_BYTE_FORMAT) + offset;
		g_array_append_val(float_data, voltage);
	}

	analog.channels = g_slist_append(NULL, ch);
	analog.num_samples = float_data->len;
	analog.data = (float*)float_data->data;
	analog.mq = SR_MQ_VOLTAGE;
	analog.unit = SR_UNIT_VOLT;
	analog.mqflags = 0;
	packet.type = SR_DF_ANALOG;
	packet.payload = &analog;
	sr_session_send(sdi, &packet);
	g_slist_free(analog.channels);

	g_array_free(float_data, TRUE);
	g_array_remove_range(data, 0, samples * sizeof(uint8_t));

	return SR_OK;
}
Example #12
0
File: garray.c Project: Babelz/SaNi
/**
 * g_byte_array_remove_range:
 * @array: a @GByteArray
 * @index_: the index of the first byte to remove
 * @length: the number of bytes to remove
 *
 * Removes the given number of bytes starting at the given index from a
 * #GByteArray.  The following elements are moved to close the gap.
 *
 * Returns: the #GByteArray
 *
 * Since: 2.4
 */
GByteArray*
g_byte_array_remove_range (GByteArray *array,
                           guint       index_,
                           guint       length)
{
  g_return_val_if_fail (array, NULL);
  g_return_val_if_fail (index_ <= array->len, NULL);
  g_return_val_if_fail (index_ + length <= array->len, NULL);

  return (GByteArray *)g_array_remove_range ((GArray *)array, index_, length);
}
Example #13
0
int
cb_user_counter_save (CbUserCounter *counter,
                      sqlite3       *db)
{
  int count = 0;
  guint i;

  g_return_val_if_fail (CB_IS_USER_COUNTER (counter), 0);
  g_return_val_if_fail (db != NULL, 0);

  sqlite3_exec (db, "BEGIN TRANSACTION;", NULL, NULL, NULL);

  for (i = 0; i < counter->user_infos->len; i ++)
    {
      sqlite3_stmt *stmt;
      int ok;
      CbUserInfo *ui = &g_array_index (counter->user_infos, CbUserInfo, i);

      if (!ui->changed)
        continue;

      ui->changed = FALSE;

      /* Actually save entry in DB */
      ok = sqlite3_prepare_v2 (db,
                               "INSERT OR REPLACE INTO `user_cache` (id, screen_name, user_name, score) "
                               "VALUES(?, ?, ?, ?)", -1, &stmt, NULL);

      if (ok != SQLITE_OK)
        {
          g_warning ("SQL Error: %s", sqlite3_errmsg (db));
          continue;
        }

      sqlite3_bind_int64 (stmt,  1, ui->user_id);
      sqlite3_bind_text (stmt, 2, ui->screen_name, -1, NULL);
      sqlite3_bind_text (stmt, 3, ui->user_name, -1, NULL);
      sqlite3_bind_int (stmt,  4, ui->score);

      ok = sqlite3_step (stmt);
      if (ok != SQLITE_DONE)
        g_critical ("%s", sqlite3_errstr (ok));

      sqlite3_finalize (stmt);
      count ++;
    }

  sqlite3_exec (db, "END TRANSACTION;", NULL, NULL, NULL);
  counter->changed = FALSE;
  g_array_remove_range (counter->user_infos, 0, counter->user_infos->len);
  return count;
}
Example #14
0
void ibus_handwrite_recog_remove_stroke(IbusHandwriteRecog*obj,int number)
{
	int i;
	for( i =obj->strokes->len - number;i< obj->strokes->len ; i++)
	{
		g_free(g_array_index(obj->strokes,LineStroke,i).points);
	}

	obj->strokes = g_array_remove_range(obj->strokes,obj->strokes->len - number,number);

	if(IBUS_HANDWRITE_RECOG_GET_CLASS(obj)->change_stroke)
		IBUS_HANDWRITE_RECOG_GET_CLASS(obj)->change_stroke(obj);
}
Example #15
0
/**
 * mx_menu_remove_all:
 * @menu: A #MxMenu
 *
 * Remove all the actions from @menu.
 *
 */
void
mx_menu_remove_all (MxMenu *menu)
{
    gint i;

    g_return_if_fail (MX_IS_MENU (menu));

    MxMenuPrivate *priv = menu->priv;

    if (!priv->children->len)
        return;

    for (i = 0; i < priv->children->len; i++)
        mx_menu_free_action_at (menu, i, FALSE);

    g_array_remove_range (priv->children, 0, priv->children->len);
}
Example #16
0
/**
 * @brief Reset the status.
 *
 **/
__EXPORT_API
void FcitxLibpinyinReset (void* arg)
{
    FcitxLibpinyin* libpinyin = (FcitxLibpinyin*) arg;
    libpinyin->buf[0] = '\0';
    libpinyin->cursor_pos = 0;

    if (libpinyin->candidate) {
        g_array_free(libpinyin->candidate, TRUE);
        libpinyin->candidate = NULL;
    }

    if (libpinyin->fixed_string->len > 0)
        g_array_remove_range(libpinyin->fixed_string, 0, libpinyin->fixed_string->len);
    if (libpinyin->inst)
        pinyin_reset(libpinyin->inst);
}
Example #17
0
int main(int argc, char** argv) {
 GArray* a = g_array_new(FALSE, FALSE, sizeof(int));
 int x[6] = {1,2,3,4,5,6};
 g_array_append_vals(a, &x, 6);
 prt(a);
 printf("Removing the first item\n");
 g_array_remove_index(a, 0);
 prt(a);
 printf("Removing the first two items\n");
 g_array_remove_range(a, 0, 2);
 prt(a);
 printf("Removing the first item very quickly\n");
 g_array_remove_index_fast(a, 0);
 prt(a);
 g_array_free(a, FALSE);
 return 0;
}
Example #18
0
static gboolean disk_show(void *hook_data, void *call_data){
  
  guint i;
  lttv_total_block element; 
  GtkTreeIter    iter;
  LttTime time_interval;
  guint64 time_interval_64;
  guint64 temp_variable; 
  guint64 bytes_read_per_sec, bytes_written_per_sec;
  g_info(" diskperformance: disk_show() \n");
  DiskPerformanceData *disk_performance = (DiskPerformanceData *)hook_data;
  GArray *disk_array = disk_performance->disk_array;
  time_interval =  ltt_time_sub(disk_performance->time_window.end_time, disk_performance->time_window.start_time); 
  
  time_interval_64  = time_interval.tv_sec;
  time_interval_64 *= NANOSECONDS_PER_SECOND;
  time_interval_64 += time_interval.tv_nsec;
  gtk_list_store_clear(disk_performance->store_m);
  for(i = 0; i < disk_array->len; i++){  
    
    element = g_array_index(disk_array,lttv_total_block,i);  
    temp_variable =  element.total_bytes_read * NANOSECONDS_PER_SECOND;
    bytes_read_per_sec = (guint64) temp_variable / time_interval_64;
    
    temp_variable =  element.total_bytes_written * NANOSECONDS_PER_SECOND;
    bytes_written_per_sec  = (guint64) temp_variable / time_interval_64;
    
    gtk_list_store_append (disk_performance->store_m, &iter);
    gtk_list_store_set (disk_performance->store_m, &iter,
      DISKNAME_COLUMN, element.diskname,
      BYTES_RD_COLUMN, element.total_bytes_read,
      BYTES_RD_SEC_COLUMN,bytes_read_per_sec,
      NUM_RD_COLUMN, element.num_read_operations,
      BYTES_WR_COLUMN, element.total_bytes_written,
      BYTES_WR_SEC_COLUMN, bytes_written_per_sec,
      NUM_WR_COLUMN, element.num_write_operations,
      -1); 
       
  }
  if(disk_performance->disk_array->len) 
    g_array_remove_range (disk_performance->disk_array,0,disk_performance->disk_array->len);
  return FALSE;
}
Example #19
0
/**
 * pkg_graph_clear_attributes:
 * @graph: A #PkgGraph.
 * @data_set: A #PkgDataSet.
 *
 * Clears all attributes mapped with a #GDataSet.
 *
 * Returns: None.
 * Side effects: None.
 */
void
pkg_graph_clear_attributes (PkgGraph   *graph,
                            PkgDataSet *data_set)
{
	PkgGraphPrivate *priv;
	GArray *array;

	g_return_if_fail(PKG_IS_GRAPH(graph));
	g_return_if_fail(PKG_IS_DATA_SET(data_set));

	priv = graph->priv;

	if (!(array = g_hash_table_lookup(priv->attrs, data_set))) {
		g_warning("PkgDataSet %p not added to PkgGraph %p",
		          data_set, graph);
		return;
	}

	g_array_remove_range(array, 0, array->len);
}
Example #20
0
/**
 * Reads and removes the block data header from a given data input.
 * Format is #ndddd... with n being the number of decimal digits d.
 * The string dddd... contains the decimal-encoded length of the data.
 * Example: #9000000013 would yield a length of 13 bytes.
 *
 * @param data The input data.
 * @param len The determined input data length.
 */
static int dlm_block_data_header_process(GArray *data, int *len)
{
	int i, n;
	gchar s[20];

	if (g_array_index(data, gchar, 0) != '#')
		return SR_ERR;

	n = (uint8_t)(g_array_index(data, gchar, 1) - '0');

	for (i = 0; i < n; i++)
		s[i] = g_array_index(data, gchar, 2 + i);
	s[i] = 0;

	if (sr_atoi(s, len) != SR_OK)
		return SR_ERR;

	g_array_remove_range(data, 0, 2 + n);

	return SR_OK;
}
Example #21
0
File: garray.c Project: Babelz/SaNi
/**
 * g_array_set_size:
 * @array: a #GArray
 * @length: the new size of the #GArray
 *
 * Sets the size of the array, expanding it if necessary. If the array
 * was created with @clear_ set to %TRUE, the new elements are set to 0.
 *
 * Returns: the #GArray
 */
GArray*
g_array_set_size (GArray *farray,
                  guint   length)
{
  GRealArray *array = (GRealArray*) farray;

  g_return_val_if_fail (array, NULL);

  if (length > array->len)
    {
      g_array_maybe_expand (array, length - array->len);
      
      if (array->clear)
        g_array_elt_zero (array, array->len, length - array->len);
    }
  else if (length < array->len)
    g_array_remove_range (farray, length, array->len - length);
  
  array->len = length;
  
  g_array_zero_terminate (array);
  
  return farray;
}
Example #22
0
/**
 * The function deletes one image from the image group array using supplied
 * index.
 *
 * \param group image group from which image will be removed
 * \param index index of the image to remove
 * \return OK on success
 */
RCode group_delete_index(ImageGroup* group, guint index) {
	ImageGroupRecord record;

	ASSERT(NULL != group);
	ASSERT(NULL != group->list);

	TRACE_MESSAGE(IGRP, TL_INFO, "Removing index (group='%s',index=%d)", group->name, index);

	if ( 0 > index || group->list->len - 1 < index ) {
		ERROR_SET(ERROR.OUT_OF_RANGE);
		ERROR_NOTE("Supplied index is out of bounds (group='%s',index=%d,min=0,max=%d)",
				group->name, index, group->list->len - 1
			);
		return FAIL;
	}

	// unreference images that will be removed
	record = g_array_index(group->list, ImageGroupRecord, index);
	/** \todo Check what to do with the call return code */
	image_unref(record.image);

	group->list = g_array_remove_range(group->list, index, 1);
	return OK;
}
Example #23
0
void
ustring_clear(UString* str)
{
    if (str->len > 0)
	g_array_remove_range(str, 0, str->len);
}
Example #24
0
static gboolean
editor_notify_cb(GObject *object, GeanyEditor *editor, SCNotification *nt, gpointer data)
{
	gint i = 0, val;
	gint old_position = 0;
	gint old_lposition = 0;
	gint old_line = 0;
	gint pos;
	if(NULL == editor || NULL == editor->sci)
		return FALSE;
	if(nt->nmhdr.code == SCN_CHARADDED)
	{
		if('\n' == nt->ch)
			define_format_newline(editor->sci);
	}
	if(nt->nmhdr.code == SCN_UPDATEUI)
	{
		if(g_array_index(lines_stack, gint, 0))
		{
			/* save current position */
			old_line = sci_get_current_line(editor->sci);
			old_lposition = sci_get_line_end_position(editor->sci, old_line) - sci_get_line_length(editor->sci, old_line);
			old_position = sci_get_current_position(editor->sci);
			sci_start_undo_action(editor->sci);
		}
		while((val = g_array_index(lines_stack, gint, i)))
		{
			i++;
			define_format_line(editor->sci, val - 1);
			dprintf("Removed from stack: %d\n", val);
		}
		if(i > 0)
		{
			sci_end_undo_action(editor->sci);
			g_array_remove_range(lines_stack, 0, i);
			/* restore current position */
			pos = sci_get_line_end_position(editor->sci, old_line) - sci_get_line_length(editor->sci, old_line);
			sci_set_current_position(editor->sci, old_position + pos - old_lposition, FALSE);
		}
	}
	if(nt->nmhdr.code == SCN_MODIFIED)
	{
		if(nt->modificationType & (SC_MOD_INSERTTEXT | SC_MOD_DELETETEXT))
		{
			if(nt->modificationType & (SC_PERFORMED_UNDO | SC_PERFORMED_REDO))
				return FALSE;
			gint line = sci_get_line_from_position(editor->sci, nt->position) + 1;
			if(sci_get_char_at(editor->sci, get_line_end(editor->sci, line - 1) - 1) == '\\')
			{
				gboolean found = FALSE;
				while((val = g_array_index(lines_stack, gint, i)))
				{
					if(val == line)
					{
						found = TRUE;
						break;
					}
					i++;
				}
				if(!found)
				{
					dprintf("Added line: %d\n", line);
					g_array_append_val(lines_stack, line);
				}
			}
		}
	}
	return FALSE;
}
Example #25
0
void
cb_user_counter_query_by_prefix (CbUserCounter *counter,
                                 sqlite3       *db,
                                 const char    *prefix,
                                 guint          max_results,
                                 CbUserInfo  **results,
                                 int           *n_results)
{
  char *sql;
  char *err;
  guint i;
  struct {
    GArray *infos;
    guint lowest_score;
  } query_data;

  g_return_if_fail (CB_IS_USER_COUNTER (counter));
  g_return_if_fail (prefix != NULL);
  g_return_if_fail (results != NULL);
  g_return_if_fail (max_results > 0);
  g_return_if_fail (n_results != NULL);

  query_data.infos = g_array_new (FALSE, TRUE, sizeof (CbUserInfo));
  query_data.lowest_score = G_MAXINT;
  g_array_set_clear_func (query_data.infos, (GDestroyNotify)cb_user_info_destroy);

  for (i = 0; i < counter->user_infos->len; i ++)
    {
      const CbUserInfo *ui = &g_array_index (counter->user_infos, CbUserInfo, i);
      char *user_name;
      char *screen_name;
      gboolean full = query_data.infos->len >= max_results;

      /* Will already be in the results from the sql query */
      if (!ui->changed)
        continue;

      if (full && ui->score < query_data.lowest_score)
        continue;

      screen_name = g_utf8_strdown (ui->screen_name, -1);
      user_name   = g_utf8_strdown (ui->user_name, -1);

      if (g_str_has_prefix (screen_name, prefix) ||
          g_str_has_prefix (user_name, prefix))
        {
          CbUserInfo *new_ui;
          /* Copy user info into result array */
          g_array_set_size (query_data.infos, query_data.infos->len + 1);
          new_ui = &g_array_index (query_data.infos, CbUserInfo, query_data.infos->len - 1);

          new_ui->user_id = ui->user_id;
          new_ui->screen_name = g_strdup (ui->screen_name);
          new_ui->user_name = g_strdup (ui->user_name);
          new_ui->score = ui->score;

          query_data.lowest_score = MIN (query_data.lowest_score, ui->score);
        }

      g_free (user_name);
      g_free (screen_name);
    }

  if (query_data.infos->len == 0)
    query_data.lowest_score = -1;

  sql = g_strdup_printf ("SELECT `id`, `screen_name`, `user_name`, `score` "
                         "FROM `user_cache` WHERE `screen_name` LIKE '%s%%' "
                         "OR `user_name` LIKE '%s%%' ORDER BY `score` DESC LIMIT %d "
                         "COLLATE NOCASE;", prefix, prefix, max_results);

  sqlite3_exec (db, sql, query_sqlite_cb, &query_data, &err);

  if (err != NULL)
    {
      g_critical ("%s SQL Error: %s", __FUNCTION__, err);
      sqlite3_free (err);
    }



  /* Now sort after score */
  g_array_sort (query_data.infos, score_sort);

  /* Remove everything after max_results */
  if (query_data.infos->len > max_results)
    g_array_remove_range (query_data.infos, max_results, query_data.infos->len - max_results);

  g_assert (query_data.infos->len <= max_results);

  /* Just use the GArray's data */
  *n_results = query_data.infos->len;
  *results = (CbUserInfo*) g_array_free (query_data.infos, FALSE);

  g_free (sql);
}
void my_atk_text_clear_selections(MyAtkText *text)
{
    if(text->selections->len != 0)
        g_array_remove_range(text->selections, 0, text->selections->len);
}
Example #27
0
bool_t GLibArrayImpl::RemoveRange(LArrayInst * inst, int i, int len)
{
	g_return_val_if_fail(inst != NULL, FALSE);
	g_array_remove_range(dynamic_cast<GLibArrayInst *>(inst)->m_array, i, len);
	return TRUE;
}
Example #28
0
PetscErrorCode IrregularNodeListUpdate_3D( LevelSet ls )
{
  PetscErrorCode ierr;
  PetscReal ***phi = ls->g->v3;
  iCoor s = ls->g->n;
  IrregularNode *n;
  int i,j,k, l, count = 0, len = ls->irregularNodes->len;
  int ni,nj,nk;
  const int nei[3][6] = {{1,0,0,-1, 0, 0},
                         {0,1,0, 0,-1, 0},
                         {0,0,1, 0, 0,-1}};
  
  PetscFunctionBegin;
  PetscLogEventBegin(EVENT_IrregularNodeListUpdate_3D,0,0,0,0);
//  PetscLogEventRegister(&EVENT_IrregularNodeListUpdate_3D,"IrregularNodeListUpdate_3D", 0);
  
  for (k = 1; k < s.z-1; ++k)
  {
    for (j = 1; j < s.y-1; ++j)
    {
      for (i = 1; i < s.x-1; ++i)
      {
        for (l = 0; l < 6; ++l)
        {
          ni = i + nei[0][l];
          nj = j + nei[1][l];
          nk = k + nei[2][l];
          
          if( phi[i][j][k] * phi[ni][nj][nk] < 0 )
          {
            if( count < len ) // Reuse IrregularNode allocations 
            {
              n = &g_array_index(ls->irregularNodes,IrregularNode,count);
              ierr = PetscMemzero(n,sizeof(IrregularNode)); 
              n->x = i;
              n->y = j;
              n->z = k;
              n->sign = PetscSign(phi[i][j][k]);
              OrthogonalProjection3D(phi, i, j, k, &n->ox, &n->oy, &n->oz);
              count++;
            } else { // If not enough, append more nodes to end of list
              IrregularNode n;
              n.x = i;
              n.y = j;
              n.z = k;
              n.sign = PetscSign(phi[i][j][k]);
              OrthogonalProjection3D(phi, i, j, k, &n.ox, &n.oy, &n.oz);
              g_array_append_val(ls->irregularNodes, n);
            }
            break;
          }
        }
      }
    }
  }

  //TODO: test if the node numbering is correct when removing excess length
  if( ls->irregularNodes->len != 0 && count < len )
  {
    g_array_remove_range(ls->irregularNodes, count, len);
  }
  PetscLogEventEnd(EVENT_IrregularNodeListUpdate_3D,0,0,0,0);
  PetscFunctionReturn(0);
}