/src/wrappers/glib/partially-implemented/g_reference_array.e

http://github.com/tybor/Liberty · Specman e · 827 lines · 337 code · 122 blank · 368 comment · 27 complexity · bc434f905a2d119802cf9138c1ce2091 MD5 · raw file

  1. indexing
  2. description: "Arrays of non-expanded wrappers of C data structures; it grows automatically as new elements are added."
  3. copyright: "(C) 2005 Paolo Redaelli "
  4. license: "LGPL v2 or later"
  5. date: "$Date:$"
  6. revision: "$REvision:$"
  7. class G_REFERENCE_ARRAY [ITEM->C_STRUCT]
  8. -- Warning: this class will be soon called G_ARRAY and the "old"
  9. -- G_ARRAY will become G_EXPANDED_ARRAY or something like this.
  10. -- Paolo 2007-04-08
  11. -- Array of referenced C structures (i.e. non-expanded wrappers of
  12. -- C data structures); it grows automatically as new elements are
  13. -- added.
  14. -- Reference arrays wraps GPtrArray, similar to GArray but are used
  15. -- only for storing pointers, i.e. reference to other objects,
  16. -- speaking in Eiffel.
  17. -- Note: If you remove elements from the array, elements at the end
  18. -- of the array are moved into the space previously occupied by the
  19. -- removed element. This means that you should not rely on the
  20. -- index of particular elements remaining the same. You should also
  21. -- be careful when deleting elements while iterating over the
  22. -- array.
  23. -- To create an array, use `empty' or `with_capacity'.
  24. -- To add elements to a pointer array, use `add'.
  25. -- To remove elements from a pointer array, use
  26. -- g_ptr_array_remove(), g_ptr_array_remove_index() or
  27. -- g_ptr_array_remove_index_fast().
  28. -- To access an element of a pointer array, use
  29. -- g_ptr_array_index().
  30. -- To set the size of a pointer array, use g_ptr_array_set_size().
  31. -- To free a pointer array, use g_ptr_array_free().
  32. -- Example 5. Using a GPtrArray
  33. -- GPtrArray *gparray;
  34. -- gchar *string1 = "one", *string2 = "two", *string3 = "three";
  35. -- gparray = g_ptr_array_new ();
  36. -- g_ptr_array_add (gparray, (gpointer) string1);
  37. -- g_ptr_array_add (gparray, (gpointer) string2);
  38. -- g_ptr_array_add (gparray, (gpointer) string3);
  39. -- if (g_ptr_array_index (gparray, 0) != (gpointer) string1)
  40. -- g_print ("ERROR: got %p instead of %p\n",
  41. -- g_ptr_array_index (gparray, 0), string1);
  42. -- g_ptr_array_free (gparray, TRUE);
  43. inherit
  44. C_STRUCT
  45. rename exists as struct_exists
  46. undefine fill_tagged_out_memory
  47. redefine copy, is_equal
  48. end
  49. COLLECTION [ITEM]
  50. redefine -- features that can be implemented in a smarter way, knowing that there is an array of pointers to wrapped features.
  51. fast_first_index_of,
  52. --fast_index_of,
  53. fast_last_index_of,
  54. has,
  55. fast_has,
  56. swap
  57. end
  58. insert
  59. WRAPPER_FACTORY [ITEM] -- undefine fill_tagged_out_memory end
  60. G_PTR_ARRAY_EXTERNALS undefine fill_tagged_out_memory end
  61. creation empty, with_capacity, from_external_pointer
  62. feature
  63. empty is
  64. -- Creates a new empty array.
  65. do
  66. from_external_pointer(g_ptr_array_new)
  67. ensure is_empty
  68. end
  69. with_capacity (a_size: INTEGER) is
  70. -- Creates a new GPtrArray with a_size preallocated. This
  71. -- avoids frequent reallocation, if you are going to add many
  72. -- pointers to the array. Note however that the size of the
  73. -- array is still 0.
  74. -- Note: `a_size' should be NATURAL
  75. require natural: a_size>=0
  76. do
  77. from_external_pointer(g_ptr_array_sized_new(a_size))
  78. ensure is_empty
  79. end
  80. feature -- Indexing:
  81. lower: INTEGER_32 is 0
  82. -- Minimum index. See also `upper', `valid_index', `item'.
  83. upper: INTEGER_32 is
  84. -- Maximum index. See also `lower', `valid_index', `item'.
  85. do
  86. Result:=count-1
  87. end
  88. feature -- Counting:
  89. count: INTEGER_32 is
  90. -- Number of available indices See also `is_empty',
  91. -- `lower', `upper'.
  92. do
  93. Result:=get_len(handle)
  94. end
  95. is_empty: BOOLEAN is
  96. -- Is collection empty ? See also `count'.
  97. do
  98. Result := (count = 0)
  99. end
  100. feature -- Accessing:
  101. item (index: INTEGER_32): ITEM is
  102. -- Item at the corresponding `index'. See also `lower',
  103. -- `upper', `valid_index'.
  104. local
  105. p: POINTER;
  106. npa: NATIVE_ARRAY[POINTER]
  107. do
  108. npa := npa.from_pointer(get_pdata(handle))
  109. p := npa.item(index)
  110. if p.is_not_null then
  111. if wrappers.has(p) then Result::=wrappers.item(p)
  112. else print_wrapper_factory_notice
  113. end
  114. end
  115. end
  116. first: ITEM is
  117. -- The very `first' item.
  118. do
  119. Result:=item(lower)
  120. end
  121. last: ITEM is
  122. -- The `last' item.
  123. -- See also `first', `item'.
  124. do
  125. Result:=item(upper)
  126. end
  127. feature -- Other features:
  128. get_new_iterator: ITERATOR[ITEM] is
  129. obsolete "Currently unimplemented!"
  130. do
  131. -- create {G_ARRAY_ITERATOR[ITEM]} Result.from_array(Current)
  132. end
  133. feature -- Writing:
  134. put (element: ITEM; an_index: INTEGER_32) is
  135. -- Make `element' the item at `an_index'. See also `lower',
  136. -- `upper', `valid_index', `item', `swap', `force'.
  137. local npa: NATIVE_ARRAY[POINTER]
  138. do
  139. npa:=npa.from_pointer(get_pdata(handle))
  140. npa.put(null_or(element),i)
  141. end
  142. swap (i1, i2: INTEGER_32) is
  143. -- Swap item at index `i1' with item at index `i2'. See also
  144. -- `item', `put'.
  145. local npa: NATIVE_ARRAY[POINTER]; tmp: POINTER
  146. do
  147. -- Working at C level
  148. npa:=npa.from_pointer(get_pdata(handle))
  149. tmp := npa.item(i1)
  150. npa.put( npa.item(i2), i1)
  151. npa.put( tmp, i2)
  152. end
  153. set_all_with (v: ITEM) is
  154. -- Set all items with value `v'. See also `set_slice_with'.
  155. local i:INTEGER
  156. do
  157. from i:=lower until i>upper
  158. loop put(v,i); i:=i+1
  159. end
  160. end
  161. -- set_slice_with (v: ITEM_; lower_index, upper_index: INTEGER_32) is
  162. -- Set all items in range [`lower_index' .. `upper_index'] with `v'.
  163. -- See also `set_all_with'.
  164. -- local i:INTEGER
  165. -- do
  166. -- from i:=lower_index until i>upper_index
  167. -- loop put(v,i); i:=i+1
  168. -- end
  169. -- end
  170. clear_all is
  171. -- Set every item to its default value. The `count' is not
  172. -- affected. See also `clear', `all_default'.
  173. local i:INTEGER
  174. do
  175. from i:=lower until i>upper
  176. loop put(Void,i); i:=i+1
  177. end
  178. end
  179. feature -- Adding:
  180. add_first (element: ITEM) is
  181. -- Add a new item in first position : `count' is increased by
  182. -- one and all other items are shifted right. See also
  183. -- `add_last', `first', `last', `add'.
  184. -- Note: this is an O(n) feature, with n=count. This call in
  185. -- a loop makes a feature at least O(n^2)
  186. local i: INTEGER
  187. do
  188. from i:=upper until i<lower loop
  189. put (item(i), i+1)
  190. i := i-1
  191. end
  192. put(element,lower)
  193. end
  194. add_last (element: ITEM) is
  195. -- Add a new item at the end; `count' is increased by one.
  196. -- See also `add_first', `last', `first', `add'.
  197. do
  198. g_ptr_array_add (handle, null_or(element))
  199. end
  200. add (element: ITEM; index: INTEGER_32) is
  201. -- Add a new `element' at rank `index' : `count' is increased
  202. -- by one and range [`index' .. `upper'] is shifted right by
  203. -- one position.
  204. -- See also `add_first', `add_last', `append_collection'.
  205. local i,j: INTEGER
  206. do
  207. from i:=upper; j:=upper+1 until i=index loop
  208. put(item(i),j)
  209. j:=i; i:=i-1
  210. end
  211. end
  212. append_collection (other: COLLECTION[ITEM]) is
  213. -- Append `other' to Current. See also `add_last',
  214. -- `add_first', `add'.
  215. -- Complexity: O(other.count)
  216. local i: ITERATOR[ITEM]
  217. do
  218. i := other.get_new_iterator
  219. from i.start until i.is_off loop
  220. add_last(i.item) i.next
  221. end
  222. end
  223. feature -- Modification:
  224. force (element: E_; index: INTEGER_32) is
  225. -- Make `element' the item at `index', enlarging the
  226. -- collection if necessary (new bounds except `index' are
  227. -- initialized with default values).
  228. -- See also `put', `item', `swap'.
  229. obsolete "unimplemented!"
  230. do
  231. end
  232. copy (other: like Current) is
  233. -- Reinitialize by copying all the items of `other'.
  234. local i: INTEGER
  235. do
  236. -- Looping from upper to lower, so Current array is resized
  237. -- only one time.
  238. from i:=other.upper until i<other.lower loop
  239. force(other.item(i),i)
  240. i:=i-1
  241. end
  242. end
  243. from_collection (model: TRAVERSABLE[ITEM]) is
  244. -- Initialize the current object with the contents of `model'.
  245. local i: ITERATOR[ITEM]
  246. do
  247. from_external_pointer(g_ptr_array_sized_new(model.count))
  248. from i:=model.get_new_iterator; i.start until i.is_off
  249. loop
  250. add(i.iter)
  251. i.next
  252. end
  253. end
  254. feature -- Removing:
  255. remove_first is
  256. -- Remove the `first' element of the collection.
  257. local removed: POINTER
  258. do
  259. removed := g_ptr_array_remove_index (handle, lower)
  260. end
  261. remove_head (n: INTEGER_32) is
  262. -- Remove the `n' elements of the collection.
  263. -- See also `remove_tail', `remove', `remove_first'.
  264. do
  265. g_ptr_array_remove_range(handle, lower,n)
  266. end
  267. remove (index: INTEGER_32) is
  268. -- Remove the item at position `index'. Followings items are
  269. -- shifted left by one position.
  270. -- See also `remove_first', `remove_head', `remove_tail',
  271. -- `remove_last'.
  272. local removed: POINTER
  273. do
  274. removed := g_ptr_array_remove_index (handle, index)
  275. end
  276. remove_last is
  277. -- Remove the `last' item.
  278. -- See also `remove_first', `remove', `remove_tail'.
  279. local removed: POINTER
  280. do
  281. removed := g_ptr_array_remove_index (handle, upper)
  282. end
  283. remove_tail (n: INTEGER_32) is
  284. do
  285. g_ptr_array_remove_range(handle, upper-n, n)
  286. end
  287. clear_count is
  288. -- Discard all items (`is_empty' is True after that call). If
  289. -- possible, the actual implementation is supposed to keep
  290. -- its internal storage area in order to refill `Current' in
  291. -- an efficient way.
  292. -- See also `clear_count_and_capacity'.
  293. do
  294. set_size(0)
  295. end
  296. clear_count_and_capacity is
  297. -- Discard all items (`is_empty' is True after that call). If
  298. -- possible, the actual implementation is supposed to release
  299. -- its internal storage area for this memory to be used by
  300. -- other objects.
  301. -- See also `clear_count'.
  302. local p: POINTER
  303. do
  304. -- Implemented freeing the old one and recreating it.
  305. p := g_ptr_array_free (handle, 1)
  306. end
  307. feature -- Looking and Searching:
  308. has (x: ITEM): BOOLEAN is
  309. -- Look for `x' using `is_equal' for comparison.
  310. -- See also `fast_has', `index_of', `fast_index_of'.
  311. local i: INTEGER
  312. do
  313. from i:=upper until Result=True or else i<lower
  314. loop
  315. Result := x.is_equal(item(i))
  316. i:=i-1
  317. end
  318. end
  319. fast_has (x: ITEM): BOOLEAN is
  320. -- Look for `x' using basic `=' for comparison.
  321. -- See also `has', `fast_index_of', `index_of'.
  322. local i: INTEGER
  323. do
  324. from i:=upper until Result=True or else i<lower
  325. loop
  326. Result := (x.handle = g_ptr_array_index(handle,i))
  327. i:=i-1
  328. end
  329. end
  330. -- first_index_of (element: ITEM): INTEGER_32 is
  331. -- -- Give the index of the first occurrence of `element' using
  332. -- -- `is_equal' for comparison. Answer `upper + 1' when
  333. -- -- `element' is not inside.
  334. -- -- See also `fast_first_index_of', `index_of', `last_index_of',
  335. -- -- `reverse_index_of'.
  336. -- local i: INTEGER_32; found: BOOLEAN
  337. -- do
  338. -- from i:=lower until found or else i>upper
  339. -- loop
  340. -- if element.is_equal(item(i)) then
  341. -- Result:=i; found := True
  342. -- end
  343. -- i := i+1
  344. -- end
  345. -- end
  346. -- index_of (element: ITEM; start_index: INTEGER_32): INTEGER_32 is
  347. -- -- Using `is_equal' for comparison, gives the index of the
  348. -- -- first occurrence of `element' at or after
  349. -- -- `start_index'. Answer `upper + 1' when `element' when the
  350. -- -- search fail.
  351. -- -- See also `fast_index_of', `reverse_index_of',
  352. -- -- `first_index_of'.
  353. -- local i: INTEGER_32; found: BOOLEAN
  354. -- do
  355. -- from i:=start_index until found or else i>upper
  356. -- loop
  357. -- if element.is_equal(item(i)) then
  358. -- Result:=i; found := True
  359. -- end
  360. -- i := i+1
  361. -- end
  362. -- end
  363. -- reverse_index_of (element: ITEM; start_index: INTEGER_32): INTEGER_32 is
  364. -- -- Using `is_equal' for comparison, gives the index of the
  365. -- -- first occurrence of `element' at or before
  366. -- -- `start_index'. Search is done in reverse direction, which
  367. -- -- means from the `start_index' down to the `lower' index
  368. -- -- . Answer `lower -1' when the search fail.
  369. -- -- See also `fast_reverse_index_of', `last_index_of',
  370. -- -- `index_of'.
  371. -- local i: INTEGER_32; found: BOOLEAN
  372. -- do
  373. -- from i:=start_index until found or else i<lower
  374. -- loop
  375. -- if element.is_equal(item(i)) then
  376. -- Result:=i; found := True
  377. -- end
  378. -- i := i-1
  379. -- end
  380. -- end
  381. -- last_index_of (element: ITEM): INTEGER_32 is
  382. -- -- Using `is_equal' for comparison, gives the index of the
  383. -- -- last occurrence of `element' at or before `upper'. Search
  384. -- -- is done in reverse direction, which means from the `upper'
  385. -- -- down to the `lower' index . Answer `lower -1' when the
  386. -- -- search fail.
  387. -- -- See also `fast_last_index_of', `reverse_index_of', `index_of'.
  388. -- local i: INTEGER_32; found: BOOLEAN
  389. -- do
  390. -- from i:=upper until found or else i<lower
  391. -- loop
  392. -- if element.is_equal(item(i)) then
  393. -- Result:=i; found := True
  394. -- end
  395. -- i := i-1
  396. -- end
  397. -- end
  398. fast_first_index_of (element: ITEM): INTEGER_32 is
  399. -- Give the index of the first occurrence of `element' using
  400. -- basic `=' for comparison. Answer `upper + 1' when
  401. -- `element' is not inside.
  402. -- See also `first_index_of', `last_index_of', `fast_last_index_of'.
  403. local i: INTEGER_32; found: BOOLEAN
  404. do
  405. from i:=lower until found or else i>upper
  406. loop
  407. if element.handle = g_ptr_array_index(handle,i) then
  408. Result:=i; found:=True
  409. end
  410. i := i-1
  411. end
  412. end
  413. fast_index_of (element: ITEM; start_index: INTEGER_32): INTEGER_32 is
  414. -- Using basic `=' for comparison, gives the index of the
  415. -- first occurrence of `element' at or after
  416. -- `start_index'. Answer `upper + 1' when `element' when the
  417. -- search fail.
  418. -- See also `index_of', `fast_reverse_index_of',
  419. -- `fast_first_index_of'.
  420. local i: INTEGER_32; found: BOOLEAN
  421. do
  422. from i:=start_index until found or else i>upper
  423. loop
  424. if element.handle = g_ptr_array_index(handle,i) then
  425. Result:=i; found:=True
  426. end
  427. i := i+1
  428. end
  429. end
  430. fast_reverse_index_of (element: ITEM; start_index: INTEGER_32): INTEGER_32 is
  431. -- Using basic `=' comparison, gives the index of the first
  432. -- occurrence of `element' at or before `start_index'. Search
  433. -- is done in reverse direction, which means from the
  434. -- `start_index' down to the `lower' index . Answer `lower
  435. -- -1' when the search fail.
  436. -- See also `reverse_index_of', `fast_index_of', `fast_last_index_of'.
  437. local i: INTEGER_32; found: BOOLEAN
  438. do
  439. from i:=start_index until found or else i<lower
  440. loop
  441. if element.handle = g_ptr_array_index(handle,i) then
  442. Result:=i; found:=True
  443. end
  444. i := i-1
  445. end
  446. end
  447. fast_last_index_of (element: ITEM): INTEGER_32 is
  448. -- Using basic `=' for comparison, gives the index of the
  449. -- last occurrence of `element' at or before `upper'. Search
  450. -- is done in reverse direction, which means from the `upper'
  451. -- down to the `lower' index . Answer `lower -1' when the
  452. -- search fail.
  453. local i: INTEGER_32; found: BOOLEAN
  454. do
  455. from i:=upper until found or else i<lower
  456. loop
  457. if element.handle = g_ptr_array_index(handle,i) then
  458. Result:=i; found:=True
  459. end
  460. i := i-1
  461. end
  462. end
  463. feature -- Looking and comparison:
  464. is_equal (other: like Current): BOOLEAN is
  465. -- Do both collections have the same `lower', `upper', and items?
  466. -- The basic `=' is used for comparison of items.
  467. -- See also `is_equal_map', `same_items'.
  468. local i: INTEGER_32
  469. do
  470. if lower/=other.lower then Result:=False -- this shouldn't be strictly necessary
  471. elseif upper/=other.upper then Result:=False -- this shouldn't be strictly necessary
  472. else
  473. from Result:=True; i:=upper until Result=False or else i<lower
  474. loop
  475. if element.handle /= g_ptr_array_index(handle,i) then
  476. Result:=False
  477. end
  478. i := i-1
  479. end
  480. end
  481. end
  482. is_equal_map (other: like Current): BOOLEAN is
  483. -- Do both collections have the same `lower', `upper', and
  484. -- items? Feature `is_equal' is used for comparison of
  485. -- items.
  486. -- See also `is_equal', `same_items'.
  487. local i: INTEGER_32
  488. do
  489. if lower/=other.lower then Result:=False -- this shouldn't be strictly necessary
  490. elseif upper/=other.upper then Result:=False -- this shouldn't be strictly necessary
  491. else
  492. from Result:=True; i:=upper until Result=False or else i<lower
  493. loop
  494. if not element.is_equal(item(i)) then Result:=False end
  495. i := i-1
  496. end
  497. end
  498. end
  499. all_default: BOOLEAN is
  500. -- Are all items Void?
  501. local i: INTEGER_32
  502. do
  503. from Result:=True; i:=upper until Result=False or else i<lower
  504. loop
  505. if g_ptr_array_index(handle,i).is_not_null then Result:=False end
  506. i := i-1
  507. end
  508. end
  509. same_items (other: COLLECTION[ITEM]): BOOLEAN is
  510. -- Do both collections have the same items? The basic `=' is used
  511. -- for comparison of items and indices are not considered (for
  512. -- example this routine may yeld True with `Current' indexed in
  513. -- range [1..2] and `other' indexed in range [2..3]).
  514. -- See also `is_equal_map', `is_equal'.
  515. local i, oi: ITERATOR[ITEM]
  516. do
  517. if count = other.count then
  518. from
  519. i := get_new_iterator; i.start
  520. oi := get_new_iterator; oi.start
  521. until Result=False or else (i.is_off or oi.is_off)
  522. loop
  523. if i.item/=oi.item then Result:=False end
  524. i.next; oi.next
  525. end
  526. else Result:=False
  527. end
  528. end
  529. occurrences (element: ITEM): INTEGER_32 is
  530. -- Number of occurrences of `element' using `is_equal' for comparison.
  531. -- See also `fast_occurrences', `index_of'.
  532. local i: INTEGER_32
  533. do
  534. from i:=upper until i<lower
  535. loop
  536. if element.is_equal(item(i)) then Result:=Result+1 end
  537. i:=i-1
  538. end
  539. end
  540. fast_occurrences (element: ITEM): INTEGER_32 is
  541. -- Number of occurrences of `element' using basic `=' for comparison.
  542. -- See also `occurrences', `index_of'.
  543. local i: INTEGER_32
  544. do
  545. from i:=upper until i<lower
  546. loop
  547. if (element.handle=g_ptr_array_index(handle,i)) then Result:=Result+1 end
  548. i:=i-1
  549. end
  550. end
  551. feature -- Agents based features:
  552. -- do_all (action: ROUTINE[TUPLE[ANY]]) is
  553. -- -- Apply `action' to every item of `Current'.
  554. -- -- See also `for_all', `exists'.
  555. -- require
  556. -- action /= Void
  557. -- for_all (test: FUNCTION[TUPLE[ANY], BOOLEAN]): BOOLEAN
  558. -- -- Do all items satisfy `test'?
  559. -- --
  560. -- -- See also `do_all', `exists'.
  561. -- require
  562. -- test /= Void
  563. -- exists (test: FUNCTION[TUPLE[ANY], BOOLEAN]): BOOLEAN
  564. -- -- Does at least one item satisfy `test'?
  565. -- --
  566. -- -- See also `do_all', `for_all'.
  567. -- require
  568. -- test /= Void
  569. -- feature(s) from COLLECTION
  570. -- -- Other features:
  571. -- replace_all (old_value, new_value: ITEM)
  572. -- -- Replace all occurrences of the element `old_value' by `new_value' using `is_equal' for comparison.
  573. -- --
  574. -- -- See also `fast_replace_all', `move'.
  575. -- ensure
  576. -- count = old count;
  577. -- not (create {SAFE_EQUAL[ITEM]}default_create).test(old_value, new_value) implies occurrences(old_value) = 0
  578. -- fast_replace_all (old_value, new_value: ITEM)
  579. -- -- Replace all occurrences of the element `old_value' by `new_value' using basic `=' for comparison.
  580. -- --
  581. -- -- See also `replace_all', `move'.
  582. -- ensure
  583. -- count = old count;
  584. -- old_value /= new_value implies fast_occurrences(old_value) = 0
  585. -- move (lower_index, upper_index, distance: INTEGER_32)
  586. -- -- Move range `lower_index' .. `upper_index' by `distance' positions.
  587. -- -- Negative distance moves towards lower indices.
  588. -- -- Free places get default values.
  589. -- --
  590. -- -- See also `slice', `replace_all'.
  591. -- require
  592. -- lower_index <= upper_index;
  593. -- valid_index(lower_index);
  594. -- valid_index(lower_index + distance);
  595. -- valid_index(upper_index);
  596. -- valid_index(upper_index + distance)
  597. -- ensure
  598. -- count = old count
  599. -- slice (min, max: INTEGER_32): like Current
  600. -- -- New collection consisting of items at indexes in [`min'..`max'].
  601. -- -- Result has the same dynamic type as `Current'.
  602. -- -- The `lower' index of the `Result' is the same as `lower'.
  603. -- --
  604. -- -- See also `from_collection', `move', `replace_all'.
  605. -- require
  606. -- lower <= min;
  607. -- max <= upper;
  608. -- min <= max + 1
  609. -- ensure
  610. -- same_dynamic_type(Result);
  611. -- Result.count = max - min + 1;
  612. -- Result.lower = lower
  613. -- reverse
  614. -- -- Reverse the order of the elements.
  615. -- ensure
  616. -- count = old count
  617. set_count (a_length: INTEGER) is
  618. -- Sets the size of the array, expanding it if necessary. New
  619. -- elements are set to Void.
  620. require natural: a_length >= 0
  621. do
  622. g_ptr_array_set_size(handle, a_length)
  623. ensure set: count=a_length
  624. end
  625. feature -- Unwrapped code
  626. -- g_ptr_array_remove ()
  627. -- gboolean g_ptr_array_remove (GPtrArray *array,
  628. -- gpointer data);
  629. -- Removes the first occurrence of the given pointer from the pointer array. The following elements are moved down one place.
  630. -- It returns TRUE if the pointer was removed, or FALSE if the pointer was not found.
  631. -- array : a GPtrArray.
  632. -- data : the pointer to remove.
  633. -- Returns : TRUE if the pointer is removed. FALSE if the pointer is not found in the array.
  634. -- g_ptr_array_remove_index ()
  635. -- gpointer g_ptr_array_remove_index (GPtrArray *array,
  636. -- guint index_);
  637. -- Removes the pointer at the given index from the pointer array. The following elements are moved down one place.
  638. -- array : a GPtrArray.
  639. -- index_ : the index of the pointer to remove.
  640. -- Returns : the pointer which was removed.
  641. -- g_ptr_array_remove_fast ()
  642. -- gboolean g_ptr_array_remove_fast (GPtrArray *array,
  643. -- gpointer data);
  644. -- Removes the first occurrence of the given pointer from the pointer array. The last element in the array is used to fill in the space, so this function does not preserve the order of the array. But it is faster than g_ptr_array_remove().
  645. -- It returns TRUE if the pointer was removed, or FALSE if the pointer was not found.
  646. -- array : a GPtrArray.
  647. -- data : the pointer to remove.
  648. -- Returns : TRUE if the pointer was found in the array.
  649. -- g_ptr_array_remove_index_fast ()
  650. -- gpointer g_ptr_array_remove_index_fast (GPtrArray *array,
  651. -- guint index_);
  652. -- Removes the pointer at the given index from the pointer array. The last element in the array is used to fill in the space, so this function does not preserve the order of the array. But it is faster than g_ptr_array_remove_index().
  653. -- array : a GPtrArray.
  654. -- index_ : the index of the pointer to remove.
  655. -- Returns : the pointer which was removed.
  656. -- g_ptr_array_remove_range ()
  657. -- void g_ptr_array_remove_range (GPtrArray *array,
  658. -- guint index_,
  659. -- guint length);
  660. -- Removes the given number of pointers starting at the given index from a GPtrArray. The following elements are moved to close the gap.
  661. -- array : a GPtrArray.
  662. -- index_ : the index of the first pointer to remove.
  663. -- length : the number of pointers to remove.
  664. -- Since 2.4
  665. -- g_ptr_array_sort ()
  666. -- void g_ptr_array_sort (GPtrArray *array,
  667. -- GCompareFunc compare_func);
  668. -- Sorts the array, using compare_func which should be a qsort()-style comparison function (returns -1 for first arg is less than second arg, 0 for equal, 1 if first arg is greater than second arg).
  669. -- Note
  670. -- The comparison function for g_ptr_array_sort() doesn't take the pointers from the array as arguments, it takes pointers to the pointers in the array.
  671. -- array : a GPtrArray.
  672. -- compare_func : comparison function.
  673. -- g_ptr_array_sort_with_data ()
  674. -- void g_ptr_array_sort_with_data (GPtrArray *array,
  675. -- GCompareDataFunc compare_func,
  676. -- gpointer user_data);
  677. -- Like g_ptr_array_sort(), but the comparison function has a user data argument.
  678. -- Note
  679. -- The comparison function for g_ptr_array_sort_with_data() doesn't take the pointers from the array as arguments, it takes pointers to the pointers in the array.
  680. -- array : a GPtrArray.
  681. -- compare_func : comparison function.
  682. -- user_data : data to pass to compare_func.
  683. -- g_ptr_array_index()
  684. -- #define g_ptr_array_index(array,index_)
  685. -- Returns the pointer at the given index of the pointer array.
  686. -- array : a GPtrArray.
  687. -- index_ : the index of the pointer to return.
  688. -- Returns : the pointer at the given index.
  689. -- g_ptr_array_free ()
  690. -- gpointer* g_ptr_array_free (GPtrArray *array,
  691. -- gboolean free_seg);
  692. -- Frees all of the memory allocated for the pointer array.
  693. -- array : a GPtrArray.
  694. -- free_seg : if TRUE the array of pointers (pdata) is freed.
  695. -- Returns : NULL if free_seg is TRUE, otherwise the array of pointers (pdata) is returned.
  696. -- g_ptr_array_foreach ()
  697. -- void g_ptr_array_foreach (GPtrArray *array,
  698. -- GFunc func,
  699. -- gpointer user_data);
  700. -- Calls a function for each element of a GPtrArray.
  701. -- array : a GPtrArray
  702. -- func : the function to call for each array element
  703. -- user_data : user data to pass to the function
  704. -- Since 2.4
  705. end