1
/* Copyright (c) 2008 PrimeBase Technologies GmbH, Germany
3
* PrimeBase Media Stream for MySQL
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
* Original author: Paul McCullagh (H&G2JCtL)
20
* Continued development: Barry Leslie
25
* Basic storage structures.
29
#ifndef __CSSTORAGE_H__
30
#define __CSSTORAGE_H__
39
class CSHashTable : public CSObject {
41
CSHashTable(): iSize(0), iTable(NULL) { }
42
virtual ~CSHashTable();
44
void setSize(uint32_t size);
48
/* Value must be given referenced. */
49
void add(CSObject *item);
51
/* Value is returned NOT referenced. */
52
CSObject *find(CSObject *key);
54
void remove(CSObject *key);
62
#define SC_SORT_LIST_INC_SIZE 20
64
class CSSortedList : public CSObject {
66
CSSortedList(): iListSize(0), iInUse(0), iList(NULL) { }
67
virtual ~CSSortedList() { clear(); }
71
/* Value must be given referenced. */
72
void add(CSObject *item);
74
/* Value is returned NOT referenced. */
75
CSObject *find(CSObject *key);
77
CSObject *itemAt(uint32_t idx);
79
CSObject *takeItemAt(uint32_t idx); // Takes item off of list.
81
void remove(CSObject *key);
83
uint32_t getSize() { return iInUse; }
93
CSObject *search(CSObject *key, uint32_t& idx);
96
class CSSyncSortedList : public CSSortedList, public CSSync {
98
CSSyncSortedList(): CSSortedList(), CSSync() { }
101
class CSLinkedItem : public CSRefObject {
103
CSLinkedItem(): CSRefObject() { }
104
virtual ~CSLinkedItem() { }
106
virtual CSObject *getNextLink() { return iNextLink; }
107
virtual CSObject *getPrevLink() { return iPrevLink; }
108
virtual void setNextLink(CSObject *link) { iNextLink = link; }
109
virtual void setPrevLink(CSObject *link) { iPrevLink = link; }
117
* Items are linked so that following the previous pointers
118
* you move from front to back.
119
* Following the next pointers you move from back to front.
121
class CSLinkedList : public CSObject {
123
CSLinkedList(): iSize(0), iListFront(NULL), iListBack(NULL) { }
124
virtual ~CSLinkedList() { clear(); }
128
uint32_t getSize() { return iSize; }
130
/* Value must be given referenced. */
131
void addFront(CSObject *item);
133
bool remove(CSObject *item);
135
/* Value is returned referenced. */
136
CSObject *removeBack();
138
/* Value is returned NOT referenced. */
141
/* Value is returned NOT referenced. */
142
CSObject *getFront();
144
/* Value is returned referenced. */
145
CSObject *removeFront();
148
CSObject *iListFront;
152
class CSVector : public CSObject {
154
CSVector(uint32_t growSize): iGrowSize(growSize), iMaxSize(0), iUsage(0), iArray(NULL) { }
155
virtual ~CSVector() { free(); }
162
* Remove and object from the vector, and
163
* The object is rfemoved from the list.
164
* return a reference.
166
CSObject *take(uint32_t idx);
169
* Remove an object from the vector.
171
void remove(uint32_t idx);
174
* Get a reference to an object in the vector.
175
* A reference to the object remains on the list.
176
* Value returned is NOT referenced!
178
CSObject *get(uint32_t idx);
180
/* Set a specific index: */
181
void set(uint32_t idx, CSObject *);
184
* Add an object to the end of the vector.
185
* Value must be referenced.
187
void add(CSObject *);
189
uint32_t size() { return iUsage; }
199
class CSSyncVector : public CSVector, public CSSync {
201
CSSyncVector(uint32_t growSize): CSVector(growSize), CSSync() { }
204
typedef struct CSSpareArrayItem {
207
} CSSpareArrayItemRec, *CSSpareArrayItemPtr;
209
class CSSparseArray : public CSObject {
211
CSSparseArray(uint32_t growSize): iGrowSize(growSize), iMaxSize(0), iUsage(0), iArray(NULL) { }
212
CSSparseArray(): iGrowSize(10), iMaxSize(0), iUsage(0), iArray(NULL) { }
213
virtual ~CSSparseArray() { free(); }
219
CSObject *take(uint32_t idx);
221
void remove(uint32_t idx);
225
CSObject *itemAt(uint32_t idx);
227
CSObject *get(uint32_t idx);
229
uint32_t getIndex(uint32_t idx);
231
void set(uint32_t idx, CSObject *);
233
uint32_t size() { return iUsage; }
235
uint32_t minIndex() {
238
return iArray[0].sa_index;
241
uint32_t maxIndex() {
244
return iArray[iUsage-1].sa_index;
255
CSSpareArrayItemPtr iArray;
257
CSObject *search(uint32_t idx, uint32_t& pos);
260
class CSSyncSparseArray : public CSSparseArray, public CSSync {
262
CSSyncSparseArray(uint32_t growSize): CSSparseArray(growSize), CSSync() { }
265
class CSOrderKey : public CSObject {
267
virtual int compareKey(CSOrderKey *key) = 0;
268
int compareKey(CSObject *key) {return CSObject::compareKey(key);}
271
typedef struct CSOrderedListItem {
274
} CSOrderedListItemRec, *CSOrderedListItemPtr;
276
class CSOrderedList : public CSObject {
278
CSOrderedList(): iListSize(0), iInUse(0), iList(NULL) { }
279
virtual ~CSOrderedList() { clear(); }
283
/* Value must be given referenced. */
284
void add(CSOrderKey *key, CSObject *item);
286
/* Value is returned NOT referenced. */
287
CSObject *find(CSOrderKey *key);
289
/* Value is returned NOT referenced. */
290
CSObject *itemAt(uint32_t idx);
292
void remove(CSOrderKey *key);
299
CSOrderedListItemPtr iList;
301
CSOrderedListItemPtr search(CSOrderKey *key, uint32_t *idx);
304
class CSSyncOrderedList : public CSOrderedList, public CSSync {
306
CSSyncOrderedList(): CSOrderedList(), CSSync() { }
311
typedef struct CSQueueItem {
314
} CSQueueItemRec, *CSQueueItemPtr;
316
class CSQueue : public CSObject {
318
CSQueue(): iQueueSize(0), iHighWater(0), iFront(NULL), iBack(NULL), iFree(NULL) { }
319
virtual ~CSQueue() { clear(); }
323
/* Value must be given referenced. */
324
void add(CSObject *item);
326
/* Returns a referenced value, on a FIFO basis. */
333
CSQueueItemPtr iFront;
334
CSQueueItemPtr iBack;
335
CSQueueItemPtr iFree;