~ubuntu-branches/debian/squeeze/firebird2.0/squeeze

« back to all changes in this revision

Viewing changes to src/common/classes/array.h

  • Committer: Bazaar Package Importer
  • Author(s): Damyan Ivanov
  • Date: 2009-05-04 11:17:29 UTC
  • mfrom: (5.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090504111729-vrob1xe54hrvf8ij
Tags: 2.0.5.13206-0.ds2-3
change Section to database

Show diffs side-by-side

added added

removed removed

Lines of Context:
156
156
                data[count++] = item;
157
157
                return count;
158
158
        }
 
159
        void add(const T* items, size_t itemsSize)
 
160
        {
 
161
                ensureCapacity(count + itemsSize);
 
162
                memcpy(data + count, items, sizeof(T) * itemsSize);
 
163
                count += itemsSize;
 
164
        }
159
165
        void remove(size_t index) {
160
166
        // NOTE: remove method must be signal safe
161
167
        // This function may be called in AST. The function doesn't wait.
178
184
                fb_assert(index < count);
179
185
                memmove(data + index, data + index + 1, sizeof(T) * (--count - index));
180
186
        }
 
187
        void remove(T* itrFrom, T* itrTo)
 
188
        {
 
189
                removeRange(itrFrom - begin(), itrTo - begin());
 
190
        }
181
191
        void shrink(size_t newCount) {
182
192
                fb_assert(newCount <= count);
183
193
                count = newCount;
194
204
                memcpy(data + count, L.data, sizeof(T) * L.count);
195
205
                count += L.count;
196
206
        }
 
207
        void assign(const Array<T, Storage>& L)
 
208
        {
 
209
                ensureCapacity(L.count);
 
210
                memcpy(data, L.data, sizeof(T) * L.count);
 
211
                count = L.count;
 
212
        }
197
213
        // NOTE: getCount method must be signal safe
198
214
        // Used as such in GlobalRWLock::blockingAstHandler
199
215
        size_t getCount() const { return count; }
225
241
                capacity = this->getStorageSize();
226
242
                data = this->getStorage();
227
243
        }
 
244
        // This method only assigns "pos" if the element is found.
 
245
        // Maybe we should modify it to iterate directy with "pos".
 
246
        bool find(const T& item, size_t& pos) const
 
247
        {
 
248
                for (size_t i = 0; i < count; i++) {
 
249
                        if (data[i] == item) {
 
250
                                pos = i;
 
251
                                return true;
 
252
                        }
 
253
                }
 
254
                return false;
 
255
        }
 
256
        bool exist(const T& item) const
 
257
        {
 
258
                size_t pos;     // ignored
 
259
                return find(item, pos);
 
260
        }
228
261
 
229
262
protected:
230
263
        size_t count, capacity;