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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
* Original author: Paul McCullagh (H&G2JCtL)
20
* Continued development: Barry Leslie
27
#ifndef __CSOBJECT_H__
28
#define __CSOBJECT_H__
34
// The RETAIN() macro is useful when passing object references to functions
35
// that you want to retain. For example istead of:
41
// After 20 years of programming I have finally found a use for the 'C' comma
42
// operator out side of a 'for' loop. :)
43
#define RETAIN(x) ((x)->retain(),(x))
45
// A back reference is a reference stored by an object pointing to it's owner.
46
// Since the owner will free all of it's object when it is released the object
47
// itself cannot hold a reference to its owner.
48
// Use this macro to make it clear that this is what you intended.
49
#define BACK_REFERENCE(x) (x)
54
virtual ~CSObject() { finalize(); }
57
virtual void retain(const char *func, const char *file, uint32_t line);
58
virtual void release(const char *func, const char *file, uint32_t line);
60
virtual void retain();
61
virtual void release();
65
* All objects are sortable, hashable and linkable,
66
* as long as these methods are implemented:
68
virtual void finalize() { }
69
virtual CSObject *getKey();
70
virtual int compareKey(CSObject *);
71
virtual uint32_t hashKey();
72
virtual CSObject *getHashLink();
73
virtual void setHashLink(CSObject *);
74
virtual CSObject *getNextLink();
75
virtual CSObject *getPrevLink();
76
virtual void setNextLink(CSObject *);
77
virtual void setPrevLink(CSObject *);
80
static void *operator new(size_t size, const char *func, const char *file, uint32_t line) {
81
return cs_mm_malloc(func, file, line, size);
84
static void operator delete(void *ptr, size_t size) {
92
class CSStaticObject : public CSObject {
94
virtual void retain(const char *func, const char *file, uint32_t line);
95
virtual void release(const char *func, const char *file, uint32_t line);
99
virtual void retain();
100
virtual void release();
104
class CSRefObject : public CSObject {
107
virtual ~CSRefObject();
110
virtual void startTracking();
111
virtual void retain(const char *func, const char *file, uint32_t line);
112
virtual void release(const char *func, const char *file, uint32_t line);
116
virtual void retain();
117
virtual void release();
120
uint32_t getRefCount() { return iRefCount;}
126
class CSSharedRefObject : public CSObject, public CSSync {
129
virtual ~CSSharedRefObject();
132
virtual void startTracking();
133
virtual void retain(const char *func, const char *file, uint32_t line);
134
virtual void release(const char *func, const char *file, uint32_t line);
138
virtual void retain();
139
virtual void release();
142
uint32_t getRefCount() { return iRefCount;}
149
#define new new(__FUNC__, __FILE__, __LINE__)
151
#define retain() retain(__FUNC__, __FILE__, __LINE__)
152
#define release() release(__FUNC__, __FILE__, __LINE__)
157
virtual ~CSPooled() {}
158
virtual void returnToPool() = 0;