OpenClonk
C4ObjectListIterator Class Reference

#include <C4ObjectList.h>

Public Member Functions

 C4ObjectListIterator (C4ObjectList &rList)
 
C4ObjectGetNext (int32_t *piCount)
 

Detailed Description

Definition at line 189 of file C4ObjectList.h.

Constructor & Destructor Documentation

◆ C4ObjectListIterator()

C4ObjectListIterator::C4ObjectListIterator ( C4ObjectList rList)
inline

Definition at line 198 of file C4ObjectList.h.

198 : rList(rList), pCurr(rList.end()), pCurrID(rList.begin()) {} // ctor
iterator begin() const
const iterator end() const

Member Function Documentation

◆ GetNext()

C4Object * C4ObjectListIterator::GetNext ( int32_t *  piCount)

Definition at line 1008 of file C4ObjectList.cpp.

1009 {
1010  // End reached?
1011  if (pCurrID == rList.end())
1012  {
1013  return nullptr;
1014  }
1015  // Not yet started?
1016  if (pCurr == rList.end())
1017  {
1018  // Then start at first ID list head
1019  pCurr = pCurrID;
1020  }
1021  else if (++pCurr == rList.end()) // Next item
1022  {
1023  return nullptr;
1024  }
1025  // Next ID section reached?
1026  if ((*pCurr)->id != (*pCurrID)->id)
1027  {
1028  pCurrID = pCurr;
1029  }
1030  else
1031  {
1032  // Otherwise, it must be checked, whether this is a duplicate item already iterated
1033  // if so, advance the list
1034  for (C4ObjectList::iterator pCheck = pCurrID; pCheck != pCurr; ++pCheck)
1035  {
1036  if ((*pCheck)->CanConcatPictureWith(*pCurr))
1037  {
1038  // Next object of matching category
1039  if (++pCurr == rList.end())
1040  {
1041  return nullptr;
1042  }
1043  // Next ID chunk reached?
1044  if ((*pCurr)->id != (*pCurrID)->id)
1045  {
1046  // then break here
1047  pCurrID = pCurr;
1048  break;
1049  }
1050  // restart check for next object
1051  pCheck = pCurrID;
1052  }
1053  }
1054  }
1055  if (piCount)
1056  {
1057  // Default count
1058  *piCount = 1;
1059  // Add additional objects of same ID to the count
1060  C4ObjectList::iterator pCheck(pCurr);
1061  for (++pCheck; pCheck != rList.end() && (*pCheck)->id == (*pCurr)->id; ++pCheck)
1062  {
1063  if ((*pCheck)->CanConcatPictureWith(*pCurr))
1064  {
1065  ++*piCount;
1066  }
1067  }
1068  }
1069  // return found object
1070  return *pCurr;
1071 }

References C4ObjectList::end().

Referenced by C4ObjectMenu::DoRefillInternal().

Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following files: