wxAutoExcel 2.5.1
Loading...
Searching...
No Matches
wxAutoExcel::wxExcelCollectionIterator< Collection, Item > Class Template Reference

An iterator over the items of a Microsoft Excel collection. More...

#include <wxAutoExcel_iterator.h>

Public Member Functions

 wxExcelCollectionIterator ()
 Creates an iterator which does not refer to any collection.
 wxExcelCollectionIterator (Collection *collection, long index)
 Creates an iterator referring to the item of collection at index, starting from 1.
Item operator* () const
 Returns the item the iterator refers to.
wxExcelCollectionIterator & operator++ ()
 Advances the iterator to the next item.
bool operator== (const wxExcelCollectionIterator &other) const
 Compares the iterators.
long GetIndex () const
 Returns the index of the item the iterator refers to, starting from 1.

Detailed Description

template<class Collection, class Item>
class wxAutoExcel::wxExcelCollectionIterator< Collection, Item >

An iterator over the items of a Microsoft Excel collection.

The collection classes, such as wxExcelWorksheets, wxExcelShapes, or wxExcelNames, as well as wxExcelRange, have begin() and end() methods returning this iterator, so that their items can be iterated over with a range-based for loop:

for ( wxExcelWorksheet worksheet : workbook.GetWorksheets() )
wxLogMessage("Worksheet '%s'", worksheet.GetName());
Represents Microsoft Excel Worksheet.
Definition wxAutoExcelWorksheet.h:23

Dereferencing the iterator obtains the item from Excel and returns it by value. As wxAutoExcel objects are just references to Excel objects, the loop variable should be a value (or auto), not a reference.

The number of items is obtained by end(), the items are obtained one by one, by their index starting from 1. Therefore, the items must not be added to or removed from the collection while iterating over it. If an item cannot be obtained, it is invalid and the error is reported according to the error mode, see wxExcelObject::SetErrorMode_(). When the number of items cannot be obtained, there is nothing to iterate over.

Constructor & Destructor Documentation

◆ wxExcelCollectionIterator() [1/2]

template<class Collection, class Item>
wxAutoExcel::wxExcelCollectionIterator< Collection, Item >::wxExcelCollectionIterator ( )
inline

Creates an iterator which does not refer to any collection.

◆ wxExcelCollectionIterator() [2/2]

template<class Collection, class Item>
wxAutoExcel::wxExcelCollectionIterator< Collection, Item >::wxExcelCollectionIterator ( Collection * collection,
long index )
inline

Creates an iterator referring to the item of collection at index, starting from 1.

Member Function Documentation

◆ operator*()

template<class Collection, class Item>
Item wxAutoExcel::wxExcelCollectionIterator< Collection, Item >::operator* ( ) const
inline

Returns the item the iterator refers to.

◆ operator++()

template<class Collection, class Item>
wxExcelCollectionIterator & wxAutoExcel::wxExcelCollectionIterator< Collection, Item >::operator++ ( )
inline

Advances the iterator to the next item.

◆ operator==()

template<class Collection, class Item>
bool wxAutoExcel::wxExcelCollectionIterator< Collection, Item >::operator== ( const wxExcelCollectionIterator< Collection, Item > & other) const
inline

Compares the iterators.

◆ GetIndex()

template<class Collection, class Item>
long wxAutoExcel::wxExcelCollectionIterator< Collection, Item >::GetIndex ( ) const
inline

Returns the index of the item the iterator refers to, starting from 1.