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

« back to all changes in this revision

Viewing changes to Puma/gen-release/step1/inc/Puma/Array.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:
25
25
 
26
26
template <class Item>
27
27
class Array {
28
 
   protected:
29
 
      static const long default_init_size = 5;
30
 
      static const long default_increment = 5;
31
 
 
32
 
   public:
33
 
      Array (long is = default_init_size, long incr = default_increment);
34
 
      Array (const Array<Item>& array);
35
 
      Array<Item>& operator =(const Array<Item>&);
36
 
      ~Array ();
37
 
      void append (const Item& item);
38
 
      void insert (long index, const Item& item);
39
 
      void prepend (const Item& item);
40
 
      void remove (long index);
41
 
      void reset ();
42
 
      Item& get (long index);
43
 
      Item& operator[] (long index);
44
 
      Item fetch (long index) const;
45
 
      Item& lookup (long index) const;
46
 
      long length () const;
47
 
 
48
 
   private:
49
 
      Item* data;
50
 
      long size;
51
 
      long count;
52
 
      long increment;
 
28
protected:
 
29
  static const long default_init_size = 5;
 
30
  static const long default_increment = 5;
 
31
 
 
32
public:
 
33
  Array (long is = default_init_size, long incr = default_increment);
 
34
  Array (const Array<Item>& array);
 
35
  Array<Item>& operator =(const Array<Item>&);
 
36
  ~Array ();
 
37
  void append (const Item& item);
 
38
  void insert (long index, const Item& item);
 
39
  void prepend (const Item& item);
 
40
  void remove (long index);
 
41
  void reset ();
 
42
  Item& get (long index);
 
43
  Item& operator[] (long index);
 
44
  Item fetch (long index) const;
 
45
  Item& lookup (long index) const;
 
46
  long length () const;
 
47
 
 
48
private:
 
49
  Item* data;
 
50
  long size;
 
51
  long count;
 
52
  long increment;
53
53
      
54
 
      void check (long wanted);
55
 
 };
56
 
 
57
 
template <class Item>
58
 
inline Array<Item>::Array (long is, long incr)
59
 
 {
60
 
   count     = 0; 
61
 
   size      = is;
62
 
   increment = incr;
63
 
   data      = new Item[size];
64
 
 }
65
 
 
66
 
template <class Item>
67
 
Array<Item>::Array (const Array<Item>& array)
68
 
 {
69
 
   count = 0;
70
 
   size  = array.size;
71
 
   data  = new Item[size];
72
 
   increment = array.increment;
73
 
 
74
 
   for (int pos = 0; pos < array.length (); pos++)
75
 
      append (array.lookup (pos));
76
 
 }
77
 
 
78
 
template <class Item>
79
 
Array<Item>& Array<Item>::operator =(const Array<Item>& array)
80
 
 {
81
 
   if (data)
82
 
      delete[] data;
83
 
   count = 0;
84
 
   size  = array.size;
85
 
   data  = new Item[size];
86
 
   increment = array.increment;
87
 
 
88
 
   for (int pos = 0; pos < array.length (); pos++)
89
 
      append (array.lookup (pos));
90
 
   return *this;
91
 
 }
92
 
 
93
 
template <class Item>
94
 
Array<Item>::~Array ()
95
 
 {
96
 
   if (data)
97
 
      delete[] data;
98
 
 }
99
 
 
100
 
template <class Item>
101
 
inline void Array<Item>::check (long wanted)
102
 
 {
103
 
   if (wanted >= size)
104
 
    {
105
 
      Item* new_data;
106
 
 
107
 
      while (wanted >= size)
108
 
      {
109
 
         size += increment;
110
 
         increment*=2;
111
 
      }
112
 
      new_data = new Item[size];
113
 
      for (int pos = 0; pos < count; pos++)
114
 
         new_data[pos] = data[pos];
115
 
      delete[] data;
116
 
      data = new_data;
117
 
    }
118
 
 }
 
54
  void grow (long wanted);
 
55
};
 
56
 
 
57
template <class Item>
 
58
inline Array<Item>::Array (long is, long incr) {
 
59
  count     = 0; 
 
60
  size      = is;
 
61
  increment = incr;
 
62
  data      = 0;
 
63
}
 
64
 
 
65
template <class Item>
 
66
Array<Item>::Array (const Array<Item>& array) {
 
67
  count     = 0;
 
68
  size      = array.size;
 
69
  increment = array.increment;
 
70
  
 
71
  if (size && array.data) {
 
72
    data = new Item[size];
 
73
    for (; count < array.count; count++) {
 
74
      data[count] = array.data[count];
 
75
    }
 
76
  } else
 
77
    data = 0;
 
78
}
 
79
 
 
80
template <class Item>
 
81
Array<Item>& Array<Item>::operator =(const Array<Item>& array) {
 
82
  if (data)
 
83
    delete[] data;
 
84
 
 
85
  count     = 0;
 
86
  size      = array.size;
 
87
  increment = array.increment;
 
88
 
 
89
  if (size && array.data) {
 
90
    data = new Item[size];
 
91
    for (; count < array.count; count++) {
 
92
      data[count] = array.data[count];
 
93
    }
 
94
  } else
 
95
    data = 0;
 
96
  
 
97
  return *this;
 
98
}
 
99
 
 
100
template <class Item>
 
101
Array<Item>::~Array () {
 
102
  if (data)
 
103
    delete[] data;
 
104
}
 
105
 
 
106
template <class Item>
 
107
inline void Array<Item>::grow (long wanted) {
 
108
  do {
 
109
    size += increment;
 
110
    increment *= 2;
 
111
  } while (wanted >= size);
 
112
 
 
113
  if (data) {
 
114
    Item* new_data = new Item[size];
 
115
    for (long i = 0; i < count; i++) {
 
116
      new_data[i] = data[i];
 
117
    }
 
118
    delete[] data;
 
119
    data = new_data;
 
120
  } else
 
121
    data = new Item[size];
 
122
}
119
123
   
120
124
template <class Item>
121
 
inline void Array<Item>::append (const Item& item)
122
 
 {
123
 
   check (count);
124
 
   data[count++] = item;
125
 
 }
126
 
 
127
 
template <class Item>
128
 
void Array<Item>::prepend (const Item& item)
129
 
 {
130
 
   insert (0, item);
131
 
 }
132
 
 
133
 
template <class Item>
134
 
void Array<Item>::insert (long index, const Item& item)
135
 
 {
136
 
   check (count);
137
 
   for (int pos = count; pos > index; pos--)
138
 
      data[pos] = data[pos - 1];
139
 
   data[index] = item;
140
 
   count++;
141
 
 }
142
 
 
143
 
template <class Item>
144
 
inline Item& Array<Item>::get (long index)
145
 
 {
146
 
   check (index);
147
 
   if (index >= count)
148
 
      count = index + 1;
149
 
   return data[index];
150
 
 }
151
 
 
152
 
template <class Item>
153
 
inline Item& Array<Item>::operator[] (long index)
154
 
 {
155
 
   return get (index);
156
 
 }
157
 
 
158
 
template <class Item>
159
 
inline Item Array<Item>::fetch (long index) const
160
 
 {
161
 
   assert(index < count);
162
 
   return data[index];
163
 
 }
164
 
 
165
 
template <class Item>
166
 
inline long Array<Item>::length () const
167
 
 {
168
 
   return count;
169
 
 }
170
 
 
171
 
template <class Item>
172
 
inline void Array<Item>::remove (long index)
173
 
 {
174
 
   if (index < count && count > 0)
175
 
    {
176
 
      for (int pos = index; pos < count - 1; pos++)
177
 
         data[pos] = data[pos + 1];
178
 
      count--;
179
 
    }
180
 
 }
 
125
inline void Array<Item>::append (const Item& item) {
 
126
  if (count >= size || ! data) {
 
127
    grow (count);
 
128
  }
 
129
  data[count++] = item;
 
130
}
 
131
 
 
132
template <class Item>
 
133
void Array<Item>::prepend (const Item& item) {
 
134
  insert (0, item);
 
135
}
 
136
 
 
137
template <class Item>
 
138
void Array<Item>::insert (long index, const Item& item) {
 
139
  if (count >= size || ! data) {
 
140
    grow (count);
 
141
  }
 
142
  for (long i = count; i > index; i--)
 
143
    data[i] = data[i - 1];
 
144
  data[index] = item;
 
145
  count++;
 
146
}
 
147
 
 
148
template <class Item>
 
149
inline Item& Array<Item>::get (long index) {
 
150
  if (index >= size || ! data) {
 
151
    grow (index);
 
152
  }
 
153
  if (index >= count)
 
154
    count = index + 1;
 
155
  return data[index];
 
156
}
 
157
 
 
158
template <class Item>
 
159
inline Item& Array<Item>::operator[] (long index) {
 
160
  return get (index);
 
161
}
 
162
 
 
163
template <class Item>
 
164
inline Item Array<Item>::fetch (long index) const {
 
165
  assert(index < count && data);
 
166
  return data[index];
 
167
}
 
168
 
 
169
template <class Item>
 
170
inline long Array<Item>::length () const {
 
171
  return count;
 
172
}
 
173
 
 
174
template <class Item>
 
175
inline void Array<Item>::remove (long index) {
 
176
  if (index < count && count > 0) {
 
177
    for (long i = index; i < count - 1; i++)
 
178
      data[i] = data[i + 1];
 
179
    count--;
 
180
  }
 
181
}
181
182
 
182
183
#ifndef __puma
183
184
template <>
184
185
inline void Array<int>::reset () {
185
 
   count = 0; 
 
186
  count = 0; 
186
187
}
187
188
#endif
188
189
 
189
190
template <class Item>
190
 
void Array<Item>::reset ()
191
 
 {
192
 
   if (data)
193
 
      delete[] data;
194
 
   count     = 0; 
195
 
   size      = default_init_size;
196
 
   increment = default_increment;
197
 
   data      = new Item[size];
198
 
 }
 
191
void Array<Item>::reset () {
 
192
  if (data)
 
193
    delete[] data;
 
194
    
 
195
  count     = 0; 
 
196
  size      = default_init_size;
 
197
  increment = default_increment;
 
198
  data      = new Item[size];
 
199
}
199
200
 
200
201
template <class Item>
201
 
inline Item& Array<Item>::lookup (long index) const
202
 
 {
203
 
   assert(index >= 0 && index < count);
204
 
//   if (index >= count) index = count - 1; 
205
 
//   if (index < 0)      index = 0;
206
 
   return data[index];
207
 
 }
 
202
inline Item& Array<Item>::lookup (long index) const {
 
203
  assert(index >= 0 && index < count);
 
204
  return data[index];
 
205
}
208
206
 
209
207
 
210
208
} // namespace Puma
238
236
  void remove (long idx)                   { Base::remove (idx); }
239
237
  void reset ()                            { Base::reset (); }
240
238
 
241
 
  Item *&get (long idx)          { return (Item*&)Base::get (idx); }
242
 
  Item *&operator[] (long idx)   { return (Item*&)Base::operator[] (idx); }
243
 
  Item *fetch (long idx) const   { return (Item*)Base::fetch (idx); }
244
 
  Item *&lookup (long idx) const { return (Item*&)Base::lookup (idx); }
245
 
  long length () const           { return Base::length (); }
 
239
  Item *&get (long idx)                    { return (Item*&)Base::get (idx); }
 
240
  Item *&operator[] (long idx)             { return (Item*&)Base::operator[] (idx); }
 
241
  Item *fetch (long idx) const             { return (Item*)Base::fetch (idx); }
 
242
  Item *&lookup (long idx) const           { return (Item*&)Base::lookup (idx); }
 
243
  long length () const                     { return Base::length (); }
246
244
};
247
245
 
248
246