Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/dave/src/list.cc @ 3715

Last change on this file since 3715 was 3213, checked in by patrick, 20 years ago

orxonox/trunk: enhanced the CommandNode - cleaning up garbage doing the wash etc

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::destroy()
80{
81  printf("List::clear() - clearing all world objects, releasing mem\n");
82  this->currentEl = this->first;
83  listElement* le = NULL;
84  while(this->currentEl != NULL)
85    {
86      le = this->currentEl->next;
87      delete this->currentEl->curr;
88      delete this->currentEl;
89      this->currentEl = le;
90    }
91  this->first = NULL;
92  this->last = NULL;
93  this->size = 0;
94}
95
96
97WorldEntity* List::firstElement()
98{
99  return this->first->curr;
100}
101
102
103bool List::isEmpty()
104{
105  return (this->size==0)?true:false;
106}
107
108
109int List::getSize()
110{
111  return this->size;
112}
113
114
115WorldEntity* List::enumerate()
116{
117  if(this->size == 0) return NULL;
118  this->currentEl = this->first;
119  return this->currentEl->curr;
120}
121
122
123WorldEntity* List::nextElement()
124{
125  if(this->size == 0) return NULL;
126  this->currentEl = this->currentEl->next;
127  if(this->currentEl == NULL) return NULL;
128  return this->currentEl->curr;
129}
130
131
132WorldEntity* List::toArray()
133{}
134
135
136void List::debug()
137{
138  int counter = 1;
139  this->currentEl = this->first;
140  printf("List:debug() =====================\n");
141  while(this->currentEl != NULL)
142    {
143      printf("element: nr %d/%d\n", counter, size);
144      this->currentEl = this->currentEl->next;
145      counter++;
146    }
147  printf("List:debug()END =====================\n");
148}
Note: See TracBrowser for help on using the repository browser.