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 private isDone: boolean = false 20 21 constructor(parent: <%= ctx.this_type %>) { 22 this.parent = parent 23 } 24 25 override next(): IteratorResult<<%= ctx.el_type %>> { 26 if (this.isDone || this.idx >= <%= ctx.array_len_int.('this.parent') %>) { 27 this.isDone = true 28 return new IteratorResult<<%= ctx.el_type %>>() 29 } 30 return new IteratorResult<<%= ctx.el_type %>>(<%= ctx.get_unsafe.('this.parent', 'this.idx++') %>) 31 } 32 33 override $_iterator(): IterableIterator<<%= ctx.el_type %>> { 34 return this; 35 } 36 37 public __Iterator_getLength(): int { 38 return this.parent.length as int 39 } 40} 41 42class ArrayEntriesIterator_<%= ctx.el_type %><%= ctx.this_iterator_generic || ctx.this_generic %> implements IterableIterator<[number, <%= ctx.el_type %>]> { 43 private parent: <%= ctx.this_type %> 44 private idx: int = 0 45 private isDone: boolean = false 46 47 constructor(parent: <%= ctx.this_type %>) { 48 this.parent = parent 49 } 50 51 override next(): IteratorResult<[number, <%= ctx.el_type %>]> { 52 if (this.isDone || this.idx >= <%= ctx.array_len_int.('this.parent') %>) { 53 this.isDone = true 54 return new IteratorResult<[number, <%= ctx.el_type %>]>() 55 } 56 const i = this.idx++; 57 const vl: [number, <%= ctx.el_type %>] = [i as number, <%= ctx.get_unsafe.('this.parent', 'i') %>] 58 return new IteratorResult<[number, <%= ctx.el_type %>]>(vl); 59 } 60 61 override $_iterator(): IterableIterator<[number, <%= ctx.el_type %>]> { 62 return this; 63 } 64 65 public __Iterator_getLength(): int { 66 return this.parent.length as int 67 } 68} 69