/src/wrappers/common/library/iterator_on_c_array.e
Specman e | 77 lines | 57 code | 16 blank | 4 comment | 2 complexity | ec9dedb6ad77689ccb50118bafde6ba6 MD5 | raw file
1note 2 description: 3 "Iterator over a C_ARRAY." 4 copyright: 5 "[ 6 Copyright (C) 2007-2017: Paolo Redaelli 7 8 This library is free software; you can redistribute it and/or 9 modify it under the terms of the GNU Lesser General Public License 10 as published by the Free Software Foundation; either version 2.1 of 11 the License, or (at your option) any later version. 12 13 This library is distributed in the hope that it will be useful, but 14 WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 Lesser General Public License for more details. 17 18 You should have received a copy of the GNU Lesser General Public 19 License along with this library; if not, write to the Free Software 20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 21 02110-1301 USA 22 ]" 23class ITERATOR_ON_C_ARRAY[ITEM_ -> C_STRUCT] 24 -- TODO: this class is conceptually obsolete as it actually duplicates 25 -- ITERATOR_ON_COLLECTION, or more precisely ITERATOR_ON_TRAVERSABLE. It 26 -- could and should be easily removed 27 28inherit 29 ITERATOR[ITEM_] 30 31create {ANY} 32 from_array 33 34feature {} -- Creation and implementation 35 from_array (an_array: C_ARRAY[ITEM_]) 36 require 37 array_not_void: an_array /= Void 38 do 39 array := an_array 40 end 41 42 i: INTEGER -- Iterator index 43 44 array: C_ARRAY[ITEM_] 45 46feature {ANY} -- 47 start 48 do 49 i := array.lower 50 end 51 52 is_off: BOOLEAN 53 do 54 Result := i > array.upper 55 -- Result:=array.valid_index(i) 56 end 57 58 item: ITEM_ 59 do 60 Result := array.item(i) 61 end 62 63 next 64 do 65 i := i + 1 66 end 67 68feature {ANY} 69 iterable_generation: INTEGER 70 do 71 Result := array.generation 72 end 73 74 generation: INTEGER 75 76 77end -- class ITERATOR_ON_C_ARRAY