Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/list.cc @ 3009

Last change on this file since 3009 was 2818, checked in by patrick, 20 years ago

orxonox/src: fix bug with includes

File size: 2.7 KB
Line 
1
2
3/*
4   orxonox - the future of 3D-vertical-scrollers
5
6   Copyright (C) 2004 orx
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 2, or (at your option)
11   any later version.
12
13   ### File Specific:
14   main-programmer: Patrick Boenzli
15   co-programmer: ...
16*/
17
18
19#include "list.h"
20#include "world_entity.h"
21
22using namespace std;
23
24
25
26List::List () 
27{
28  this->first = NULL;
29  this->last = NULL;
30  this->size = 0;
31}
32
33List::~List () 
34{}
35
36
37void List::add(WorldEntity* entity)
38{
39  printf("List::add() \n");
40  listElement* el = new listElement;
41  el->prev = this->last;
42  el->curr = entity;
43  el->next = NULL;
44
45  this->last = el;
46
47  if(this->size == 0) this->first = el;
48  else el->prev->next = el;
49  this->size++;
50}
51
52
53void List::remove(WorldEntity* entity)
54{
55  this->currentEl = this->first;
56  listElement* te;
57  while( this->currentEl != NULL)
58    {
59      if( this->currentEl->curr == entity)
60        {
61          printf("List::remove() - object found\n");
62         
63          if( this->currentEl->prev  == NULL ) this->first = this->currentEl->next;
64          else this->currentEl->prev->next = this->currentEl->next;
65
66          if( this->currentEl->next == NULL) this->last = this->currentEl->prev;
67          else this->currentEl->next->prev = this->currentEl->prev;
68
69          te = this->currentEl->next;
70          delete this->currentEl;
71          this->currentEl = te;
72          return;
73        }
74      this->currentEl = this->currentEl->next;
75    }
76}
77
78
79void List::clear()
80{
81  printf("List::clear() - clearing all world objects, releasing mem\n");
82  this->currentEl = this->first;
83  while(this->currentEl != NULL)
84    {
85      listElement* le = this->currentEl->next;
86      delete this->currentEl->curr;
87      delete this->currentEl;
88      this->currentEl = le;
89    }
90  this->first = NULL;
91  this->last = NULL;
92  this->size = 0;
93}
94
95
96WorldEntity* List::firstElement()
97{
98  return this->first->curr;
99}
100
101
102bool List::isEmpty()
103{
104  return (this->size==0)?true:false;
105}
106
107
108int List::getSize()
109{
110  return this->size;
111}
112
113
114WorldEntity* List::enumerate()
115{
116  if(this->size == 0) return NULL;
117  this->currentEl = this->first;
118  return this->currentEl->curr;
119}
120
121
122WorldEntity* List::nextElement()
123{
124  if(this->size == 0) return NULL;
125  this->currentEl = this->currentEl->next;
126  if(this->currentEl == NULL) return NULL;
127  return this->currentEl->curr;
128}
129
130
131WorldEntity* List::toArray()
132{}
133
134
135void List::debug()
136{
137  int counter = 1;
138  this->currentEl = this->first;
139  printf("List:debug() =====================\n");
140  while(this->currentEl != NULL)
141    {
142      printf("element: nr %d/%d\n", counter, size);
143      this->currentEl = this->currentEl->next;
144      counter++;
145    }
146  printf("List:debug()END =====================\n");
147}
Note: See TracBrowser for help on using the repository browser.