CObject
CCListIterator Struct Reference

#include <CCListIterator.h>

+ Inheritance diagram for CCListIterator:

Public Member Functions

const struct CCListIterator_VTableCCListIterator_GetVTable ()
 
CError CCListIterator (struct CCListIterator *self, struct CIList *list)
 
CBool CIIterator_HasNext (struct CIIterator *self)
 
void CIIterator_Next (struct CIIterator *self, void *element)
 
CBool CIIterator_HasPrevious (struct CIIterator *self)
 
void CIIterator_Previous (struct CIIterator *self, void *element)
 
CBool CIIterator_Set (struct CIIterator *self, void *element)
 
CBool CIIterator_Remove (struct CIIterator *self)
 
size_t CIIterator_Index (struct CIIterator *self)
 

Data Fields

struct CObject cobject
 
struct CIIterator ciiterator
 
struct CIListlist
 
size_t index
 
size_t next_index
 
size_t previous_index
 
size_t last_index_used
 
CBool is_next_valid
 
CBool is_previous_valid
 
CBool is_last_index_used_valid
 
struct CInterface interface
 

Detailed Description

This is an implementations of the CIIterator interface for the CIList interface. Any data structure which implements the CIList interface can be iterated through using this structure. For example, the code below uses this iterator to print out every element in an array list.

struct CCArrayList list;
int i = 0;
CCArrayList(&list, sizeof(int), LIST_LENGTH);
CIList_Add(&list.cIList, &i);
++i;
CIList_Add(&list.cIList, &i);
++i;
CIList_Add(&list.cIList, &i);
++i;
struct CCListIterator iter;
CCListIterator(&iter, &list.cIList);
while( CIIterator_HasNext(&iter.cIIterator) ) {
int element;
CIIterator_Next(&iter.cIIterator, &element);
printf("Got the number %d\n", element);
}
CDestroy(&iter);
CDestroy(&list);
Attention
To call inherited methods from CIIterator, use as input to the first argument of all CIIterator_* methods:
  • CCListIterator::cIIterator

Constructor & Destructor Documentation

CError CCListIterator ( struct CCListIterator self,
struct CIList list 
)
Class Constructor

Constructs an interator capable of iterating over a list.

Parameters
selfThe iterator.
listThe list to iterate through.
Returns
Error code.

Member Function Documentation

CBool CIIterator_HasNext ( struct CIIterator self)
inherited

Evaluates if there is a next element in the collection. If this returns a logical true, then CIIterator_Next() will get the next element in the collection.

Parameters
selfThe iterator.
Returns
CBool CIIterator_HasPrevious ( struct CIIterator self)
inherited

Evaluates if there is a previous element in the collection. If this returns a logical true, then CIIterator_Previous() will get the previous element in the collection.

Parameters
selfThe iterator.
Returns
size_t CIIterator_Index ( struct CIIterator self)
inherited

Gets the index of the element in the collection last returned by a call to CIIterator_Next() or CIIterator_Previous(). If no call to those methods has been made yet, this does nothing and returns zero. Note, zero can be a valid index, so a returned value of zero is not an error code.

Parameters
selfThe iterator.
Returns
The index in the collection of the last element returned by a call to CIIterator_Next() or CIIterator_Previous().
void CIIterator_Next ( struct CIIterator self,
void *  element 
)
inherited

Gets the next element in the collection. If CIIterator_HasNext() returns a logical true, then this function will get a valid element. If CIIterator_HasNext() returned a logical false, then this function does nothing. This does not happen because of the call to CIIterator_HasNext(), CIIterator_HasNext() will only tell the application how this method is going to behave.

Parameters
selfThe iterator
elementThe next element in the collection will be copied to the the memory pointed to by this.
void CIIterator_Previous ( struct CIIterator self,
void *  element 
)
inherited

Gets the previous element in the collection. If CIIterator_HasPrevious() returns a logical true, then this function will get a valid element. If CIIterator_HasPrevious() returned a logical false, then this function does nothing.

Parameters
selfThe iterator
elementThe previous element in the collection will be copied to the the memory pointed to by this.
CBool CIIterator_Remove ( struct CIIterator self)
inherited

Removes the element in the collection last returned by a call to CIIterator_Next() or CIIterator_Previous(). If no call to those methods has been made yet, then this does nothing and returns a logical false.

Parameters
selfThe iterator.
Returns
CBool CIIterator_Set ( struct CIIterator self,
void *  element 
)
inherited

Sets the element in the collection last returned by a call to CIIterator_Next() or CIIterator_Previous(). If no call to those methods has been made yet, then this does nothing and returns a logical false.

Parameters
selfThe iterator.
elementMemory pointed to will be copied into the collection
Returns

The documentation for this struct was generated from the following file: