1%# 2%# Copyright (c) 2021-2024 Huawei Device Co., Ltd. 3%# Licensed under the Apache License, Version 2.0 (the "License"); 4%# you may not use this file except in compliance with the License. 5%# You may obtain a copy of the License at 6%# 7%# http://www.apache.org/licenses/LICENSE-2.0 8%# 9%# Unless required by applicable law or agreed to in writing, software 10%# distributed under the License is distributed on an "AS IS" BASIS, 11%# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12%# See the License for the specific language governing permissions and 13%# limitations under the License. 14%# 15 16class ArrayValuesIterator_<%= ctx.el_type %><%= ctx.this_iterator_generic || ctx.this_generic %> implements IterableIterator<<%= ctx.el_type %>> { 17 private parent: <%= ctx.this_type %> 18 private idx: int = 0 19 20 constructor(parent: <%= ctx.this_type %>) { 21 this.parent = parent 22 } 23 24 override next(): IteratorResult<<%= ctx.el_type %>> { 25 if (this.idx >= <%= ctx.array_len_int.('this.parent') %>) { 26 return new IteratorResult<<%= ctx.el_type %>>() 27 } 28 return new IteratorResult<<%= ctx.el_type %>>(<%= ctx.get_unsafe.('this.parent', 'this.idx++') %>) 29 } 30 31 override $_iterator(): IterableIterator<<%= ctx.el_type %>> { 32 return this; 33 } 34 35 public __Iterator_getLength(): int { 36 return this.parent.length as int 37 } 38} 39 40class ArrayEntriesIterator_<%= ctx.el_type %><%= ctx.this_iterator_generic || ctx.this_generic %> implements IterableIterator<[number, <%= ctx.el_type %>]> { 41 private parent: <%= ctx.this_type %> 42 private idx: int = 0 43 44 constructor(parent: <%= ctx.this_type %>) { 45 this.parent = parent 46 } 47 48 override next(): IteratorResult<[number, <%= ctx.el_type %>]> { 49 if (this.idx >= <%= ctx.array_len_int.('this.parent') %>) { 50 return new IteratorResult<[number, <%= ctx.el_type %>]>() 51 } 52 const i = this.idx++; 53 const vl: [number, <%= ctx.el_type %>] = [i as number, <%= ctx.get_unsafe.('this.parent', 'i') %>] 54 return new IteratorResult<[number, <%= ctx.el_type %>]>(vl); 55 } 56 57 override $_iterator(): IterableIterator<[number, <%= ctx.el_type %>]> { 58 return this; 59 } 60 61 public __Iterator_getLength(): int { 62 return this.parent.length as int 63 } 64} 65