Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/importer/array.cc @ 3195

Last change on this file since 3195 was 3195, checked in by bensch, 19 years ago

orxonox/trunk/importer: this→pointers implemented in classes object, material, array, pathlist

File size: 3.0 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14*/
15
16#include "array.h"
17
18/**
19   \brief creates a new Array
20*/
21Array::Array ()
22{
23  this->initializeArray ();
24}
25
26/**
27   \brief deletes an Array.
28   It does this by first deleting all the array-entries, and then delete the array[] itself
29*/
30Array::~Array()
31{
32  if (verbose >= 2)
33    printf("deleting array\n");
34  Entry* walker = this->firstEntry;
35  Entry* previous;
36  while (walker)
37    {
38      previous = walker;
39      walker = walker->next;
40      delete previous;
41    }
42  if (finalized)
43    delete []this->array;
44}
45
46/**
47   \brief initializes an Array
48   the Function does this by setting up a fistEntry, and setting the entryCount.
49*/
50void Array::initializeArray ()
51{
52  if (verbose >= 2)
53    printf ("crating new Array\n");
54  this->firstEntry = new Entry;
55  this->firstEntry->next =NULL;
56  this->currentEntry=firstEntry;
57  this->finalized = false;
58  this->entryCount = 0; //0 means one entry
59  return;
60}
61
62/**
63   \brief finalizes an array.
64   This Function creates the array, and makes it ready to be sent to the application.
65*/
66void Array::finalizeArray (void)
67{
68  if (verbose >= 3)
69    printf ("Finalizing array. Length: %i\n", entryCount); 
70  //  if ((array = (GLfloat*)malloc( entryCount* sizeof(GLfloat))) == NULL)
71  if ((this->array = new GLfloat [this->entryCount]) == NULL)
72    printf ("could not allocate %i data Blocks\n", this->entryCount);
73  Entry* walker = this->firstEntry;
74  for (int i=0; i<this->entryCount; i++)
75    {
76      this->array[i] = walker->value;
77      walker = walker->next;
78    }
79  this->finalized = true;
80
81  return;
82}
83
84/**
85   \brief adds a new Entry to the Array
86   \param entry Entry to add.
87*/
88void Array::addEntry (GLfloat entry)
89{
90  if (!this->finalized)
91    {
92      if (verbose >= 3)
93        printf ("adding new Entry to Array: %f\n", entry);
94     
95      this->currentEntry->value = entry;
96      this->currentEntry->next = new Entry;
97      this->currentEntry = currentEntry->next;
98      this->currentEntry->next = NULL;
99      ++this->entryCount;
100    }
101  else 
102    if (verbose >= 1)
103      printf ("adding failed, because list has been finalized\n");
104}
105
106/**
107   \brief Adds 3 entries at once (convenience)
108*/
109void Array::addEntry (GLfloat entry0, GLfloat entry1, GLfloat entry2)
110{
111  this->addEntry (entry0);
112  this->addEntry (entry1);
113  this->addEntry (entry2);
114}
115 
116/**
117   \brief Gives back the array !! MUST be executed AFTER finalize.
118   \returns The created array.
119*/
120GLfloat* Array::getArray ()
121{
122  return this->array;
123}
124
125/**
126   \returns The Count of entries in the Array
127*/
128int Array::getCount()
129{
130  return this->entryCount;
131}
132
133/**
134   \brief Simple debug info about the Array
135*/
136void Array::debug ()
137{
138  printf ("entryCount=%i, address=%p\n", this->entryCount, this->array);
139}
Note: See TracBrowser for help on using the repository browser.