~ubuntu-branches/ubuntu/saucy/drizzle/saucy-proposed

« back to all changes in this revision

Viewing changes to plugin/pbms/src/cslib/CSStorage.h

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2008 PrimeBase Technologies GmbH, Germany
2
 
 *
3
 
 * PrimeBase Media Stream for MySQL
4
 
 *
5
 
 * This program is free software; you can redistribute it and/or modify
6
 
 * it under the terms of the GNU General Public License as published by
7
 
 * the Free Software Foundation; either version 2 of the License, or
8
 
 * (at your option) any later version.
9
 
 *
10
 
 * This program is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 * GNU General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU General Public License
16
 
 * along with this program; if not, write to the Free Software
17
 
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
 
 *
19
 
 * Original author: Paul McCullagh (H&G2JCtL)
20
 
 * Continued development: Barry Leslie
21
 
 *
22
 
 * 2007-06-15
23
 
 *
24
 
 * CORE SYSTEM STORAGE
25
 
 * Basic storage structures.
26
 
 *
27
 
 */
28
 
 
29
 
#pragma once
30
 
#ifndef __CSSTORAGE_H__
31
 
#define __CSSTORAGE_H__
32
 
 
33
 
#include <stdio.h>
34
 
 
35
 
#include "CSDefs.h"
36
 
#include "CSString.h"
37
 
 
38
 
class CSHashTable;
39
 
 
40
 
class CSHashTable : public CSObject {
41
 
public:
42
 
        CSHashTable(): iSize(0), iTable(NULL) { }
43
 
        virtual ~CSHashTable();
44
 
 
45
 
        void setSize(uint32_t size);
46
 
 
47
 
        void clear();
48
 
 
49
 
        /* Value must be given referenced. */
50
 
        void add(CSObject *item);
51
 
 
52
 
        /* Value is returned NOT referenced. */
53
 
        CSObject *find(CSObject *key);
54
 
        
55
 
        bool remove(CSObject *key);
56
 
 
57
 
private:
58
 
        uint32_t iSize;
59
 
 
60
 
        CSObject **iTable;
61
 
};
62
 
 
63
 
#define SC_SORT_LIST_INC_SIZE           20
64
 
 
65
 
class CSSortedList : public CSObject {
66
 
public:
67
 
        CSSortedList(): iListSize(0), iInUse(0), iList(NULL) { }
68
 
        virtual ~CSSortedList() { clear(); }
69
 
 
70
 
        void clear();
71
 
 
72
 
        /* Value must be given referenced. */
73
 
        void add(CSObject *item);
74
 
        
75
 
        /* Value is returned NOT referenced. */
76
 
        CSObject *find(CSObject *key);
77
 
 
78
 
        CSObject *itemAt(uint32_t idx);
79
 
        
80
 
        CSObject *takeItemAt(uint32_t idx); // Takes item off of list.
81
 
        
82
 
        void remove(CSObject *key);
83
 
        
84
 
        uint32_t getSize() { return iInUse; }
85
 
 
86
 
 
87
 
private:
88
 
        uint32_t iListSize;
89
 
 
90
 
        uint32_t iInUse;
91
 
 
92
 
        CSObject **iList;
93
 
 
94
 
        CSObject *search(CSObject *key, uint32_t& idx);
95
 
};
96
 
 
97
 
class CSSyncSortedList : public CSSortedList, public CSSync {
98
 
public:
99
 
        CSSyncSortedList(): CSSortedList(), CSSync() { }
100
 
};
101
 
 
102
 
class CSLinkedItem : public CSRefObject {
103
 
public:
104
 
        CSLinkedItem(): CSRefObject(), iNextLink(NULL), iPrevLink(NULL) { }
105
 
        virtual ~CSLinkedItem() { }
106
 
 
107
 
        virtual CSObject *getNextLink() { return iNextLink; }
108
 
        virtual CSObject *getPrevLink() { return iPrevLink; }
109
 
        virtual void setNextLink(CSObject *link) { iNextLink = link; }
110
 
        virtual void setPrevLink(CSObject *link) { iPrevLink = link; }
111
 
 
112
 
private:
113
 
        CSObject                *iNextLink;
114
 
        CSObject                *iPrevLink;
115
 
};
116
 
 
117
 
/*
118
 
 * Items are linked so that following the previous pointers
119
 
 * you move from front to back.
120
 
 * Following the next pointers you move from back to front.
121
 
 */
122
 
class CSLinkedList : public CSObject {
123
 
public:
124
 
        CSLinkedList(): iSize(0), iListFront(NULL), iListBack(NULL) { }
125
 
        virtual ~CSLinkedList() { clear(); }
126
 
 
127
 
        void clear();
128
 
        
129
 
        uint32_t getSize() { return iSize; }
130
 
 
131
 
        /* Value must be given referenced. */
132
 
        void addFront(CSObject *item);
133
 
        void addBack(CSObject *item);
134
 
 
135
 
        bool remove(CSObject *item);
136
 
 
137
 
        /* Value is returned referenced. */
138
 
        CSObject *removeBack();
139
 
 
140
 
        /* Value is returned NOT referenced. */
141
 
        CSObject *getBack();
142
 
 
143
 
        /* Value is returned NOT referenced. */
144
 
        CSObject *getFront();
145
 
 
146
 
        /* Value is returned referenced. */
147
 
        CSObject *removeFront();
148
 
private:
149
 
        uint32_t iSize;
150
 
        CSObject *iListFront;
151
 
        CSObject *iListBack;
152
 
};
153
 
 
154
 
class CSSyncLinkedList : public CSLinkedList, public CSSync {
155
 
public:
156
 
        CSSyncLinkedList(): CSLinkedList(), CSSync() { }
157
 
};
158
 
 
159
 
class CSVector : public CSObject {
160
 
public:
161
 
        CSVector(uint32_t growSize): iGrowSize(growSize), iMaxSize(0), iUsage(0), iArray(NULL) { }
162
 
        virtual ~CSVector() { free(); }
163
 
 
164
 
        void free();
165
 
 
166
 
        void clear();
167
 
 
168
 
        /*
169
 
         * Remove and object from the vector, and
170
 
         * The object is rfemoved from the list.
171
 
         * return a reference.
172
 
         */
173
 
        CSObject *take(uint32_t idx);
174
 
 
175
 
        /*
176
 
         * Remove an object from the vector.
177
 
         */
178
 
        void remove(uint32_t idx);
179
 
 
180
 
        /*
181
 
         * Get a reference to an object in the vector.
182
 
         * A reference to the object remains on the list.
183
 
         * Value returned is NOT referenced!
184
 
         */
185
 
        CSObject *get(uint32_t idx);
186
 
 
187
 
        /* Set a specific index: */
188
 
        void set(uint32_t idx, CSObject *);
189
 
 
190
 
        /*
191
 
         * Add an object to the end of the vector.
192
 
         * Value must be referenced.
193
 
         */
194
 
        void add(CSObject *);
195
 
 
196
 
        uint32_t size() { return iUsage; }
197
 
 
198
 
private:
199
 
        uint32_t iGrowSize;
200
 
        uint32_t iMaxSize;
201
 
        uint32_t iUsage;
202
 
 
203
 
        CSObject **iArray;
204
 
};
205
 
 
206
 
class CSSyncVector : public CSVector, public CSSync {
207
 
public:
208
 
        CSSyncVector(uint32_t growSize): CSVector(growSize), CSSync() { }
209
 
};
210
 
 
211
 
typedef struct CSSpareArrayItem {
212
 
        uint32_t                sa_index;
213
 
        CSObject        *sa_object;
214
 
} CSSpareArrayItemRec, *CSSpareArrayItemPtr;
215
 
 
216
 
class CSSparseArray : public CSObject {
217
 
public:
218
 
        CSSparseArray(uint32_t growSize): iGrowSize(growSize), iMaxSize(0), iUsage(0), iArray(NULL) { }
219
 
        CSSparseArray(): iGrowSize(10), iMaxSize(0), iUsage(0), iArray(NULL) { }
220
 
        virtual ~CSSparseArray() { free(); }
221
 
 
222
 
        void free();
223
 
 
224
 
        void clear();
225
 
 
226
 
        CSObject *take(uint32_t sparse_idx);
227
 
 
228
 
        void remove(uint32_t sparse_idx);
229
 
 
230
 
        void removeFirst();
231
 
 
232
 
        CSObject *itemAt(uint32_t idx);
233
 
 
234
 
        CSObject *get(uint32_t sparse_idx);
235
 
        
236
 
        uint32_t getIndex(uint32_t sparse_idx);
237
 
        
238
 
        void set(uint32_t sparse_idx, CSObject *);
239
 
 
240
 
        uint32_t size() { return iUsage; }
241
 
 
242
 
        uint32_t minIndex() {
243
 
                if (iUsage == 0)
244
 
                        return 0;
245
 
                return iArray[0].sa_index;
246
 
        }
247
 
 
248
 
        uint32_t maxIndex() {
249
 
                if (iUsage == 0)
250
 
                        return 0;
251
 
                return iArray[iUsage-1].sa_index;
252
 
        }
253
 
 
254
 
        CSObject *first();
255
 
 
256
 
        CSObject *last();
257
 
 
258
 
private:
259
 
        uint32_t                                iGrowSize;
260
 
        uint32_t                                iMaxSize;
261
 
        uint32_t                                iUsage;
262
 
        CSSpareArrayItemPtr     iArray;
263
 
 
264
 
        CSObject *search(uint32_t idx, uint32_t& pos);
265
 
};
266
 
 
267
 
class CSSyncSparseArray : public CSSparseArray, public CSSync {
268
 
public:
269
 
        CSSyncSparseArray(uint32_t growSize): CSSparseArray(growSize), CSSync() { }
270
 
};
271
 
 
272
 
class CSOrderKey : public CSObject {
273
 
public:
274
 
        virtual int compareKey(CSOrderKey *key) = 0;
275
 
        int compareKey(CSObject *key) {return CSObject::compareKey(key);}
276
 
};
277
 
 
278
 
typedef struct CSOrderedListItem {
279
 
        CSOrderKey      *li_key;
280
 
        CSObject        *li_item;
281
 
} CSOrderedListItemRec, *CSOrderedListItemPtr;
282
 
 
283
 
class CSOrderedList : public CSObject {
284
 
public:
285
 
        CSOrderedList(): iListSize(0), iInUse(0), iList(NULL) { }
286
 
        virtual ~CSOrderedList() { clear(); }
287
 
 
288
 
        void clear();
289
 
 
290
 
        /* Value must be given referenced. */
291
 
        void add(CSOrderKey *key, CSObject *item);
292
 
        
293
 
        /* Value is returned NOT referenced. */
294
 
        CSObject *find(CSOrderKey *key);
295
 
        
296
 
        /* Value is returned NOT referenced. */
297
 
        CSObject *itemAt(uint32_t idx);
298
 
        
299
 
        void remove(CSOrderKey *key);
300
 
 
301
 
private:
302
 
        uint32_t iListSize;
303
 
 
304
 
        uint32_t iInUse;
305
 
 
306
 
        CSOrderedListItemPtr iList;
307
 
 
308
 
        CSOrderedListItemPtr search(CSOrderKey *key, uint32_t *idx);
309
 
};
310
 
 
311
 
class CSSyncOrderedList : public CSOrderedList, public CSSync {
312
 
public:
313
 
        CSSyncOrderedList(): CSOrderedList(), CSSync() { }
314
 
};
315
 
 
316
 
class CSQueue;
317
 
 
318
 
typedef struct CSQueueItem {
319
 
        CSObject                        *qi_object;
320
 
        CSQueue                         *qi_next;
321
 
} CSQueueItemRec, *CSQueueItemPtr;
322
 
 
323
 
class CSQueue : public CSObject {
324
 
public:
325
 
        CSQueue(): iQueueSize(0), iHighWater(0), iFront(NULL), iBack(NULL), iFree(NULL) { }
326
 
        virtual ~CSQueue() { clear(); }
327
 
 
328
 
        void clear();
329
 
 
330
 
        /* Value must be given referenced. */
331
 
        void add(CSObject *item);
332
 
 
333
 
        /* Returns a referenced value, on a FIFO basis. */
334
 
        CSObject *remove();
335
 
 
336
 
private:
337
 
        uint32_t iQueueSize;
338
 
        uint32_t iHighWater;
339
 
 
340
 
        CSQueueItemPtr  iFront;
341
 
        CSQueueItemPtr  iBack;
342
 
        CSQueueItemPtr  iFree;
343
 
};
344
 
 
345
 
#endif