OpenTTD Source 20261123-master-g1c55c72fd0
CargoSpec::Iterator Struct Reference

Iterator to iterate all valid CargoSpec. More...

#include <cargotype.h>

Public Types

using value_type = CargoSpec
 The type pointed by iterator.
using pointer = CargoSpec *
 The pointer type to value_type.
using reference = CargoSpec &
 The reference type to value_type.
using difference_type = size_t
 Type used to store difference between two iterators.
using iterator_category = std::forward_iterator_tag
 The category of the iterator.

Public Member Functions

 Iterator (size_t index)
 Constructs new iterator from an index.
bool operator== (const Iterator &other) const
 Compare with other iterator.
CargoSpec * operator* () const
 Dereference operator.
Iterator & operator++ ()
 Increment the iterator and set it to the next position.

Private Member Functions

void ValidateIndex ()
 Validate index so it points to a valid cargo spec.

Private Attributes

size_t index
 Index of the CargoSpec that this iterator points to.

Detailed Description

Iterator to iterate all valid CargoSpec.

Definition at line 163 of file cargotype.h.

Member Typedef Documentation

◆ difference_type

Type used to store difference between two iterators.

Definition at line 167 of file cargotype.h.

◆ iterator_category

using CargoSpec::Iterator::iterator_category = std::forward_iterator_tag

The category of the iterator.

Definition at line 168 of file cargotype.h.

◆ pointer

The pointer type to value_type.

Definition at line 165 of file cargotype.h.

◆ reference

The reference type to value_type.

Definition at line 166 of file cargotype.h.

◆ value_type

The type pointed by iterator.

Definition at line 164 of file cargotype.h.

Constructor & Destructor Documentation

◆ Iterator()

CargoSpec::Iterator::Iterator ( size_t index)
inlineexplicit

Constructs new iterator from an index.

Parameters
indexIndex of the CargoSpec to iterate from.

Definition at line 174 of file cargotype.h.

References index, and ValidateIndex().

Referenced by operator++(), and operator==().

Member Function Documentation

◆ operator*()

CargoSpec * CargoSpec::Iterator::operator* ( ) const
inline

Dereference operator.

Gets the pointed CargoSpec.

Returns
A pointer to the CargoSpec this iterator points to.

Definition at line 190 of file cargotype.h.

References CargoSpec::Get(), and index.

◆ operator++()

Iterator & CargoSpec::Iterator::operator++ ( )
inline

Increment the iterator and set it to the next position.

Returns
This iterator after incrementing.

Definition at line 196 of file cargotype.h.

References index, Iterator(), and ValidateIndex().

◆ operator==()

bool CargoSpec::Iterator::operator== ( const Iterator & other) const
inline

Compare with other iterator.

Parameters
otherThe other iterator to compare with.
Returns
true iff the other iterator matches this value e.i. they are equal.

Definition at line 184 of file cargotype.h.

References index, and Iterator().

◆ ValidateIndex()

void CargoSpec::Iterator::ValidateIndex ( )
inlineprivate

Validate index so it points to a valid cargo spec.

Definition at line 202 of file cargotype.h.

References CargoSpec::Get(), CargoSpec::GetArraySize(), and CargoSpec::IsValid().

Referenced by Iterator(), and operator++().

Field Documentation

◆ index

size_t CargoSpec::Iterator::index
private

Index of the CargoSpec that this iterator points to.

Definition at line 199 of file cargotype.h.

Referenced by Iterator(), operator*(), operator++(), and operator==().


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