Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UnitCollection::UnitIterator Class Reference

#include <collection.h>

Inheritance diagram for UnitCollection::UnitIterator:
UniverseUtil::PythonUnitIter

Public Member Functions

 UnitIterator ()
 
 UnitIterator (const UnitIterator &)
 
 UnitIterator (UnitCollection *)
 
virtual ~UnitIterator ()
 
bool isDone ()
 
bool notDone ()
 
void remove ()
 
void moveBefore (UnitCollection &)
 
void preinsert (class Unit *)
 
void postinsert (class Unit *unit)
 
void advance ()
 
Unitnext ()
 
UnitIteratoroperator= (const UnitIterator &)
 
const UnitIterator operator++ (int)
 
const UnitIteratoroperator++ ()
 
Unitoperator* ()
 
 UnitIterator ()
 
 UnitIterator (UnitListNode *start)
 Creates this unit iterator. More...
 
 UnitIterator (const UnitIterator &orig)
 
UnitIteratoroperator= (const UnitIterator &orig)
 
 ~UnitIterator ()
 
bool isDone () const
 
bool notDone () const
 
void remove ()
 removes something after pos. eg the first valid unit. or current() More...
 
void moveBefore (UnitCollection &otherList)
 
void preinsert (Unit *unit)
 inserts in front of current More...
 
void postinsert (Unit *unit)
 inserts after current More...
 
Unitcurrent ()
 returns the unit pos is pointing at or NULL if all dead or end of list. More...
 
Unitnext ()
 advances the counter More...
 
void advance ()
 
Unitoperator++ (int)
 
Unitoperator++ ()
 
Unitoperator* ()
 

Protected Attributes

UnitCollectioncol
 
std::list< class Unit * >::iterator it
 

Friends

class UnitCollection
 

Detailed Description

Definition at line 39 of file collection.h.

Constructor & Destructor Documentation

UnitCollection::UnitIterator::UnitIterator ( )
inline

Definition at line 42 of file collection.h.

42 : col( NULL ) {}
UnitCollection::UnitIterator::UnitIterator ( const UnitIterator orig)

Definition at line 32 of file collection.cpp.

References col, and it.

33 {
34  col = orig.col;
35  it = orig.it;
36  if (col)
37  col->reg( this );
38 }
UnitCollection::UnitIterator::UnitIterator ( UnitCollection orig)

Definition at line 40 of file collection.cpp.

41 {
42  col = orig;
43  for (it = orig->u.begin(); it != col->u.end(); ++it)
44  if (*it)
45  break;
46  col->reg( this );
47 }
UnitCollection::UnitIterator::~UnitIterator ( )
virtual

Definition at line 49 of file collection.cpp.

50 {
51  if (col)
52  col->unreg( this );
53 }
UnitCollection::UnitIterator::UnitIterator ( )
inline

Definition at line 66 of file oldcollection.h.

66 : UnitIterator() : pos( NULL ) {}
UnitCollection::UnitIterator::UnitIterator ( UnitListNode *  start)
inline

Creates this unit iterator.

Definition at line 68 of file oldcollection.h.

68  : pos( start )
69  {
70  GetNextValidUnit();
71  }
UnitCollection::UnitIterator::UnitIterator ( const UnitIterator orig)
inline

Definition at line 72 of file oldcollection.h.

72 : pos( orig.pos ) {}
UnitCollection::UnitIterator::~UnitIterator ( )
inline

Definition at line 78 of file oldcollection.h.

79  {
80  pos = NULL;
81  }

Member Function Documentation

void UnitCollection::UnitIterator::advance ( )

Definition at line 84 of file collection.cpp.

Referenced by UnitCollection::append(), UnitCollection::cleanup(), GameStarSystem::Draw(), UniverseUtil::getNumUnits(), next(), operator++(), and UnitCollection::prepend().

85 {
86  if ( !col || it == col->u.end() ) return;
87  if ( (*it) != NULL && (*it)->Killed() )
88  col->erase( it );
89  else
90  ++it;
91  while ( it != col->u.end() ) {
92  if ( (*it) == NULL )
93  ++it;
94  else if ( (*it)->Killed() )
95  col->erase( it );
96  else
97  break;
98  }
99 }
void UnitCollection::UnitIterator::advance ( )
inline

Definition at line 112 of file oldcollection.h.

113  {
114  pos = pos->next;
115  GetNextValidUnit();
116  }
Unit* UnitCollection::UnitIterator::current ( )
inline

returns the unit pos is pointing at or NULL if all dead or end of list.

Definition at line 102 of file oldcollection.h.

Referenced by GameStarSystem::Draw(), UniverseUtil::getNumUnits(), next(), operator*(), and operator++().

103  {
104  return pos->next->unit;
105  }
bool UnitCollection::UnitIterator::isDone ( )
inline

Definition at line 47 of file collection.h.

References col, and it.

Referenced by notDone(), StarSystem::Update(), and Cockpit::updateAttackers().

48  {
49  if ( col && it != col->u.end() )
50  return false;
51  return true;
52  }
bool UnitCollection::UnitIterator::isDone ( ) const
inline

Definition at line 83 of file oldcollection.h.

84  {
85  return pos->next->unit == NULL;
86  }
void UnitCollection::UnitIterator::moveBefore ( UnitCollection otherlist)

Definition at line 61 of file collection.cpp.

References UnitCollection::prepend().

Referenced by StarSystem::RequestPhysics().

62 {
63  if ( col && it != col->u.end() ) {
64  otherlist.prepend( *it );
65  col->erase( it );
66  }
67 }
void UnitCollection::UnitIterator::moveBefore ( UnitCollection otherList)
Unit * UnitCollection::UnitIterator::next ( )

Definition at line 101 of file collection.cpp.

102 {
103  advance();
104  if ( !col || it == col->u.end() )
105  return NULL;
106  return *it;
107 }
Unit* UnitCollection::UnitIterator::next ( )
inline

advances the counter

Definition at line 107 of file oldcollection.h.

References advance(), and current().

108  {
109  advance();
110  return current();
111  }
bool UnitCollection::UnitIterator::notDone ( )
inline
bool UnitCollection::UnitIterator::notDone ( ) const
inline

Definition at line 87 of file oldcollection.h.

88  {
89  return pos->next->unit != NULL;
90  }
Unit* UnitCollection::UnitIterator::operator* ( )
inline

Definition at line 88 of file collection.h.

References col, and it.

89  {
90  if ( col && it != col->u.end() )
91  return *it;
92  return NULL;
93  }
Unit* UnitCollection::UnitIterator::operator* ( )
inline

Definition at line 128 of file oldcollection.h.

References current().

129  {
130  return current();
131  }
const UnitIterator UnitCollection::UnitIterator::operator++ ( int  )
inline

Definition at line 77 of file collection.h.

References advance().

78  {
79  UnitCollection::UnitIterator tmp( *this );
80  advance();
81  return tmp;
82  }
const UnitIterator& UnitCollection::UnitIterator::operator++ ( )
inline

Definition at line 83 of file collection.h.

References advance().

84  {
85  advance();
86  return *this;
87  }
Unit* UnitCollection::UnitIterator::operator++ ( int  )
inline

Definition at line 117 of file oldcollection.h.

References advance(), and current().

118  {
119  Unit *un = current();
120  advance();
121  return un;
122  }
Unit* UnitCollection::UnitIterator::operator++ ( )
inline

Definition at line 123 of file oldcollection.h.

References advance(), and current().

124  {
125  advance();
126  return current();
127  }
UnitIterator& UnitCollection::UnitIterator::operator= ( const UnitIterator orig)
inline

Definition at line 73 of file oldcollection.h.

74  {
75  pos = orig.pos;
76  return *this;
77  }
UnitCollection::UnitIterator & UnitCollection::UnitIterator::operator= ( const UnitIterator orig)

Definition at line 19 of file collection.cpp.

References col, and it.

20 {
21  if (col != orig.col) {
22  if (col)
23  col->unreg( this );
24  col = orig.col;
25  if (col)
26  col->reg( this );
27  }
28  it = orig.it;
29  return *this;
30 }
void UnitCollection::UnitIterator::postinsert ( class Unit unit)

Definition at line 75 of file collection.cpp.

76 {
77  list< Unit* >::iterator tmp = it;
78  if ( col && unit && it != col->u.end() ) {
79  ++tmp;
80  col->insert( tmp, unit );
81  }
82 }
void UnitCollection::UnitIterator::postinsert ( Unit unit)

inserts after current

void UnitCollection::UnitIterator::preinsert ( class Unit unit)

Definition at line 69 of file collection.cpp.

Referenced by Unit::UpgradeSubUnitsWithFactory().

70 {
71  if (col && unit)
72  col->insert( it, unit );
73 }
void UnitCollection::UnitIterator::preinsert ( Unit unit)
inline

inserts in front of current

Definition at line 95 of file oldcollection.h.

96  {
97  pos->next = new UnitListNode( unit, pos->next );
98  }
void UnitCollection::UnitIterator::remove ( )

Definition at line 55 of file collection.cpp.

Referenced by UnitHash3d< char[coltablesize], char[coltableacc], char[tablehuge] >::removeFromVector(), and Unit::UpgradeSubUnitsWithFactory().

56 {
57  if ( col && it != col->u.end() )
58  col->erase( it );
59 }
void UnitCollection::UnitIterator::remove ( )

removes something after pos. eg the first valid unit. or current()

Friends And Related Function Documentation

friend class UnitCollection
friend

Definition at line 96 of file collection.h.

Member Data Documentation

UnitCollection* UnitCollection::UnitIterator::col
protected

Definition at line 98 of file collection.h.

Referenced by isDone(), operator*(), operator=(), and UnitIterator().

std::list< class Unit* >::iterator UnitCollection::UnitIterator::it
protected

Definition at line 101 of file collection.h.

Referenced by isDone(), operator*(), operator=(), and UnitIterator().


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