~ubuntu-branches/ubuntu/maverick/aspectc++/maverick

« back to all changes in this revision

Viewing changes to Puma/gen-release/step1/inc/Puma/VoidPtrArray.h

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2008-04-10 17:40:52 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080410174052-xdnsm7oi8hauyyf1
Tags: 1.0pre4~svn.20080409+dfsg-3
Fix another missing include, this time in Ag++/StdSystem.cc

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#ifndef __VoidPtrArray__
20
20
#define __VoidPtrArray__
21
21
 
 
22
#include <stdlib.h>
 
23
#include <string.h>
22
24
#include <assert.h>
23
25
 
24
26
namespace Puma {
51
53
  long count;
52
54
  long increment;
53
55
      
54
 
  void check (long wanted);
 
56
  void grow (long wanted);
55
57
};
56
58
 
57
59
 
58
60
inline VoidPtrArray::VoidPtrArray (long is, long incr) {
59
61
  count     = 0; 
60
 
  size      = 0; //is;
 
62
  size      = 0;
61
63
  increment = incr;
62
 
  data      = 0; //new void*[size];
 
64
  data      = 0;
63
65
}
64
66
 
65
67
 
66
68
inline VoidPtrArray::VoidPtrArray (const VoidPtrArray &array) {
67
 
  count = 0;
68
 
  size  = array.size;
 
69
  count     = array.count;
 
70
  size      = array.size;
 
71
  increment = array.increment;
 
72
  
69
73
  if (size) {
70
 
    data  = new void*[size];
71
 
    for (int pos = 0; pos < array.length (); pos++)
72
 
      append (array.lookup (pos));
73
 
  }
74
 
  else
 
74
    data = (void**) ::malloc(size * sizeof(void*));
 
75
    ::memcpy(data, array.data, count * sizeof(void*));
 
76
  } else
75
77
    data = 0;
76
 
  increment = array.increment;
77
78
}
78
79
 
79
80
 
80
81
inline VoidPtrArray &VoidPtrArray::operator =(const VoidPtrArray &array) {
81
82
  if (data)
82
 
    delete[] data;
83
 
  count = 0;
84
 
  size  = array.size;
 
83
    ::free (data);
 
84
 
 
85
  count     = array.count;
 
86
  size      = array.size;
 
87
  increment = array.increment;
 
88
 
85
89
  if (size) {
86
 
    data  = new void*[size];
87
 
    for (int pos = 0; pos < array.length (); pos++)
88
 
      append (array.lookup (pos));
89
 
  }
90
 
  else
 
90
    data = (void**) ::malloc(size * sizeof(void*));
 
91
    ::memcpy(data, array.data, count * sizeof(void*));
 
92
  } else
91
93
    data = 0;
92
 
  increment = array.increment;
 
94
  
93
95
  return *this;
94
96
}
95
97
 
96
98
 
97
99
inline VoidPtrArray::~VoidPtrArray () {
98
100
  if (data)
99
 
    delete[] data;
 
101
    ::free (data);
100
102
}
101
103
 
102
104
 
103
105
inline void VoidPtrArray::append (const void *item) {
104
 
  check (count);
 
106
  if (count >= size) {
 
107
    grow (count);
 
108
  }
105
109
  data[count++] = (void*)item;
106
110
}
107
111
 
112
116
 
113
117
 
114
118
inline void VoidPtrArray::insert (long index, const void *item) {
115
 
  check (count);
 
119
  if (count >= size) {
 
120
    grow (count);
 
121
  }
116
122
  for (int pos = count; pos > index; pos--)
117
123
    data[pos] = data[pos - 1];
118
124
  data[index] = (void*)item;
121
127
 
122
128
 
123
129
inline void *&VoidPtrArray::get (long index) {
124
 
  check (index);
 
130
  if (index >= size) {
 
131
    grow (index);
 
132
  }
125
133
  if (index >= count)
126
134
    count = index + 1;
127
135
  return data[index];
143
151
}
144
152
 
145
153
 
146
 
inline void VoidPtrArray::check (long wanted) {
147
 
  if (wanted >= size) {
148
 
    void** new_data;
149
 
 
150
 
    while (wanted >= size) {
151
 
      size += increment;
152
 
      increment*=2;
153
 
    }
154
 
 
155
 
    new_data = new void*[size];
156
 
    if (data) {
157
 
      for (int pos = 0; pos < count; pos++)
158
 
        new_data[pos] = data[pos];
159
 
      delete[] data;
160
 
    }
161
 
    data = new_data;
162
 
  }
 
154
inline void VoidPtrArray::grow (long wanted) {
 
155
  do {
 
156
    size += increment;
 
157
    increment *= 2;
 
158
  } while (wanted >= size);
 
159
 
 
160
  if (data)
 
161
    data = (void**) ::realloc(data, size * sizeof(void*));
 
162
  else
 
163
    data = (void**) ::malloc(size * sizeof(void*));
163
164
}
164
165
   
165
166
 
173
174
 
174
175
 
175
176
inline void VoidPtrArray::reset () {
176
 
//  if (data)
177
 
//    delete[] data;
178
 
  count     = 0; 
179
 
//  size      = default_init_size;
180
 
//  increment = default_increment;
181
 
//  data      = new void*[size];
 
177
  count = 0; 
 
178
  if (data)
 
179
    ::free (data);
 
180
  size = 0;
 
181
  data = 0;
 
182
  increment = default_increment;
182
183
}
183
184
 
184
185
 
185
186
inline void *&VoidPtrArray::lookup (long index) const {
186
 
   assert(index >= 0 && index < count);
187
 
//  if (index >= count) index = count - 1; 
188
 
//  if (index < 0)      index = 0;
189
 
   return data[index];
 
187
  assert(index >= 0 && index < count);
 
188
  return data[index];
190
189
}
191
190
 
192
191