g_array_remove_range is available only since 2.4

This commit is contained in:
Yevgen Muntyan 2005-07-25 13:56:47 +00:00
parent 4a56b48df2
commit e06d689c6a
3 changed files with 43 additions and 3 deletions

View File

@ -85,6 +85,27 @@ void moo_term_line_erase (MooTermLine *line)
}
#if GLIB_CHECK_VERSION(2,4,0)
#define array_remove_range(ar,pos,len) g_array_remove_range (CELLS_ARRAY (ar), pos, len)
#else
static void array_remove_range (MooTermCellArray *array,
guint index,
guint length)
{
g_return_if_fail (array);
g_return_if_fail (index < array->len);
g_return_if_fail (index + length <= array->len);
if (index + length != array->len)
g_memmove (&array->data[index],
&array->data[index + length],
(array->len - (index + length)) * sizeof (MooTermCell));
g_array_set_size (CELLS_ARRAY(array), array->len - length);
}
#endif
void moo_term_line_delete_range (MooTermLine *line,
guint pos,
guint len)
@ -94,7 +115,7 @@ void moo_term_line_delete_range (MooTermLine *line,
else if (pos + len >= line->cells->len)
return moo_term_line_set_len (line, pos);
else
g_array_remove_range (CELLS_ARRAY (line->cells), pos, len);
array_remove_range (line->cells, pos, len);
}

View File

@ -57,6 +57,22 @@ void g_ptr_array_foreach (GPtrArray *array,
(*func) (array->pdata[i], data);
}
void g_ptr_array_remove_range (GPtrArray *array,
guint index,
guint length)
{
g_return_if_fail (array);
g_return_if_fail (index < array->len);
g_return_if_fail (index + length <= array->len);
if (index + length != array->len)
g_memmove (&array->pdata[index],
&array->pdata[index + length],
(array->len - (index + length)) * sizeof (gpointer));
g_ptr_array_set_size (array, array->len - length);
}
#endif /* !GLIB_CHECK_VERSION(2,4,0) */

View File

@ -86,8 +86,11 @@ type_name##_get_type (void) \
#endif /* !G_DEFINE_TYPE */
void g_ptr_array_foreach (GPtrArray *array,
GFunc func,
gpointer user_data);
GFunc func,
gpointer user_data);
void g_ptr_array_remove_range (GPtrArray *array,
guint index_,
guint length);
#endif /* !GLIB_CHECK_VERSION(2,4,0) */