:orphan: .. **************************************************************************** .. CUI .. .. The Advanced Framework for Simulation, Integration, and Modeling (AFSIM) .. .. The use, dissemination or disclosure of data in this file is subject to .. limitation or restriction. See accompanying README and LICENSE for details. .. **************************************************************************** ArrayIterator ------------- .. class:: ArrayIterator inherits Iterator ArrayIterator is a type that allows the user to iterate over a range of elements in an :class:`Array>` container. Use the :method:`GetIterator.GetIterator>` method to obtain an iterator to the beginning of the array. Usage:: Array array = Array(); ArrayIterator iter = array.GetIterator(); while (iter.HasNext()) { iter.Next(); int index = (int)iter.Key(); double data = (double)iter.Data(); } When iterating over the entire range of the Array, the :ref:`foreach>` loop is a more convenient method:: Array array = Array(); foreach (double data in array) // Only data is needed { ... } foreach (int index : double data in array) // Both index and data are needed { ... } Methods ======= .. note:: Return values from methods that return :class:`Object` should be cast to the correct key and data types. .. method:: bool HasPrev() Returns true if another element exists before the current element. .. method:: Object Prev() Decrements the iterator to the previous element and returns its associated data, which should be cast to the data type of the Array before usage. If at the beginning of the array and no previous element exists, invalid data is returned, so :method:`HasPrev()` should be queried before using this method. .. method:: Object Key() Returns the index associated with the current element, in the range [0, :method:`Size().Size>` - 1]. Should be cast to int before usage. .. method:: Object Data() Returns the data associated with the current element, which should be cast to the data type of the Array before usage. See :class:`Iterator` for a list of methods inherited by all iterator types.