/src/wrappers/gobject/library/g_value_array.e
Specman e | 202 lines | 118 code | 37 blank | 47 comment | 1 complexity | 9d67acaa1a9b6b750478fb26f8608ae4 MD5 | raw file
1indexing 2 description: "Value array - A container structure to maintain an array of generic values." 3 copyright: "(C) 2006 Paolo Redaelli " 4 license: "LGPL v2 or later" 5 date: "$Date:$" 6 revision: "$Revision:$" 7 8class G_VALUE_ARRAY 9 -- A container to maintain an array of generic values. 10 11 -- The prime purpose of a GValueArray is for it to be used as an 12 -- object property that holds an array of values. A GValueArray 13 -- wraps an array of GValue elements in order for it to be used as 14 -- a boxed type through G_TYPE_VALUE_ARRAY. 15 16inherit 17 C_STRUCT 18 redefine copy 19 end 20 21creation make 22 23feature {} -- Creation 24 make (n_prealloced: INTEGER) is 25 -- Allocate and initialize a new GValueArray, optionally 26 -- preserve space for `n_prealloced' elements. New arrays 27 -- always contain 0 elements, regardless of the value of 28 -- n_prealloced. 29 require positive_prealloced: n_prealloced>0 30 do 31 handle := g_value_array_new (n_prealloced); 32 end 33 34feature 35 dispose is 36 do 37 g_value_array_free (handle) 38 handle:=default_pointer 39 end 40 41feature -- Duplication 42 copy (a_source: like Current) is 43 -- Construct an exact copy of a GValueArray by duplicating 44 -- all its contents. 45 require else valid_source: a_source /= Void 46 do 47 handle := g_value_array_copy (a_source.handle) 48 end 49 50feature -- Array-like features 51 to_external: POINTER is 52 -- Gives C access into the internal `storage' of the G_VALUE_ARRAY. 53 do 54 Result:=get_values (handle) 55 end 56 57 count: INTEGER is 58 -- Number of available indices. 59 do 60 Result := get_n_values(handle) 61 ensure positive: Result >= 0 62 end 63 64 item (an_index: INTEGER): G_VALUE is 65 -- the value at `an_index' contained in Current. 66 require 67 positive_integer: an_index >= 0 68 correct_index: an_index < count 69 do 70 create Result.from_external_pointer (g_value_array_get_nth (handle, an_index)) 71 end 72 73 append (a_value: G_VALUE) is 74 -- Insert a copy of `a_value' as last element of Current. 75 require valid_value: a_value/=Void 76 do 77 handle := g_value_array_append (handle, a_value.handle) 78 ensure number_increased: count = old count + 1 79 end 80 81 prepend (a_value: G_VALUE) is 82 -- Insert a copy of `a_value' as firsr element of Current. 83 require valid_value: a_value/=Void 84 do 85 handle := g_value_array_prepend (handle, a_value.handle) 86 ensure number_increased: count = old count + 1 87 end 88 89 insert (an_index: INTEGER; a_value: G_VALUE) is 90 -- Insert a copy of `a_value' at `an_index' position of 91 -- Current. 92 require 93 valid_index: an_index.in_range (0,count-1) 94 valid_value: a_value/=Void 95 do 96 handle:=g_value_array_insert(handle,an_index, a_value.handle) 97 ensure number_increased: count = old count + 1 98 end 99 100 remove (an_index: INTEGER) is 101 -- Remove the value at position `an_index'. 102 require valid_index: an_index.in_range (0,count-1) 103 do 104 handle := g_value_array_remove (handle, an_index) 105 ensure number_decreased: count = old count - 1 106 end 107 108 -- TODO: g_value_array_sort () 109 110 -- GValueArray* g_value_array_sort (GValueArray *value_array, 111 -- GCompareFunc compare_func); 112 113 -- Sort value_array using compare_func to compare the elements accoring to the semantics of GCompareFunc. 114 115 -- The current implementation uses Quick-Sort as sorting algorithm. 116 -- value_array : GValueArray to sort 117 -- compare_func : function to compare elements 118 -- Returns : the GValueArray passed in as value_array 119 120 121 -- TODO: g_value_array_sort_with_data () 122 123 -- GValueArray* g_value_array_sort_with_data (GValueArray *value_array, 124 -- GCompareDataFunc compare_func, 125 -- gpointer user_data); 126 127 -- Sort value_array using compare_func to compare the elements accoring to the semantics of GCompareDataFunc. 128 129 -- The current implementation uses Quick-Sort as sorting algorithm. 130 -- value_array : GValueArray to sort 131 -- compare_func : function to compare elements 132 -- user_data : extra data argument provided for compare_func 133 -- Returns : the GValueArray passed in as value_array 134 135feature {} -- External calls 136 g_value_array_get_nth (a_value_array: POINTER; an_index: INTEGER): POINTER is -- GValue 137 -- Note: an_index is a guint, a NATURAL 138 external "C use <glib-object.h>" 139 end 140 141 g_value_array_new (n_prealloced: INTEGER): POINTER is -- GValueArray 142 -- Note: n_prealloced is a guint, a NATURAL 143 external "C use <glib-object.h>" 144 end 145 146 g_value_array_copy (a_value_array: POINTER): POINTER is -- GValueArray 147 -- Note: a_value_array is a const POINTER 148 external "C use <glib-object.h>" 149 end 150 151 g_value_array_free (a_value_array: POINTER) is 152 -- Actually it is g_value_array_free 153 external "C use <glib-object.h>" 154 end 155 156 g_value_array_append (a_value_array, a_value: POINTER): POINTER is -- GValueArray 157 external "C use <glib-object.h>" 158 end 159 160 g_value_array_prepend (a_value_array, a_value: POINTER): POINTER is -- GValueArray 161 external "C use <glib-object.h>" 162 end 163 164 g_value_array_insert (a_value_array: POINTER; an_index: INTEGER; a_value: POINTER): POINTER is -- GValueArray 165 -- Note: an_index is a guint, a NATURAL 166 external "C use <glib-object.h>" 167 end 168 169 g_value_array_remove (a_value_array: POINTER; an_index: INTEGER): POINTER is -- GValueArray 170 -- Note: an_index is a guint 171 external "C use <glib-object.h>" 172 end 173 174 g_value_array_sort (a_value_array, a_compare_func: POINTER): POINTER is -- GValueArray 175 external "C use <glib-object.h>" 176 end 177 178 g_value_array_sort_with_data (a_value_array, a_compare_func, user_data: POINTER): POINTER is -- GValueArray 179 external "C use <glib-object.h>" 180 end 181 182feature {} -- GValueArray struct 183 184 get_n_values (a_gvalue_array: POINTER): INTEGER is 185 -- Get n_values from a GValueArray struct. It is a guint, the 186 -- number of values contained in the array 187 external "C struct get n_values use <glib-object.h>" 188 ensure positive: Result >= 0 189 end 190 191 get_values (a_gvalue_array: POINTER): POINTER is 192 -- Get values from a GValueArray struct. It is C pointer to 193 -- the array of values 194 external "C struct get values use <glib-object.h>" 195 end 196 197feature -- Size 198 struct_size: INTEGER is 199 external "C inline use <glib-object.h>" 200 alias "sizeof(GValueArray)" 201 end 202end