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
28
#ifndef __CSOBJECT_H__
29
#define __CSOBJECT_H__
35
// The RETAIN() macro is useful when passing object references to functions
36
// that you want to retain. For example istead of:
42
// After 20 years of programming I have finally found a use for the 'C' comma
43
// operator out side of a 'for' loop. :)
44
#define RETAIN(x) ((x)->retain(),(x))
46
// A back reference is a reference stored by an object pointing to it's owner.
47
// Since the owner will free all of it's object when it is released the object
48
// itself cannot hold a reference to its owner.
49
// Use this macro to make it clear that this is what you intended.
50
#define BACK_REFERENCE(x) (x)
55
virtual ~CSObject() { finalize(); }
58
virtual void retain(const char *func, const char *file, uint32_t line);
59
virtual void release(const char *func, const char *file, uint32_t line);
61
virtual void retain();
62
virtual void release();
66
* All objects are sortable, hashable and linkable,
67
* as long as these methods are implemented:
69
virtual void finalize() { }
70
virtual CSObject *getKey();
71
virtual int compareKey(CSObject *);
72
virtual uint32_t hashKey();
73
virtual CSObject *getHashLink();
74
virtual void setHashLink(CSObject *);
75
virtual CSObject *getNextLink();
76
virtual CSObject *getPrevLink();
77
virtual void setNextLink(CSObject *);
78
virtual void setPrevLink(CSObject *);
81
static void *operator new(size_t size, const char *func, const char *file, uint32_t line) {
82
return cs_mm_malloc(func, file, line, size);
85
static void operator delete(void *ptr, size_t size) {
93
class CSStaticObject : public CSObject {
95
virtual void retain(const char *func, const char *file, uint32_t line);
96
virtual void release(const char *func, const char *file, uint32_t line);
100
virtual void retain();
101
virtual void release();
105
class CSRefObject : public CSObject {
108
virtual ~CSRefObject();
111
virtual void startTracking();
112
virtual void retain(const char *func, const char *file, uint32_t line);
113
virtual void release(const char *func, const char *file, uint32_t line);
117
virtual void retain();
118
virtual void release();
121
uint32_t getRefCount() { return iRefCount;}
127
class CSSharedRefObject : public CSObject, public CSSync {
130
virtual ~CSSharedRefObject();
133
virtual void startTracking();
134
virtual void retain(const char *func, const char *file, uint32_t line);
135
virtual void release(const char *func, const char *file, uint32_t line);
139
virtual void retain();
140
virtual void release();
143
uint32_t getRefCount() { return iRefCount;}
150
#define new new(__FUNC__, __FILE__, __LINE__)
152
#define retain() retain(__FUNC__, __FILE__, __LINE__)
153
#define release() release(__FUNC__, __FILE__, __LINE__)
158
virtual ~CSPooled() {}
159
virtual void returnToPool() = 0;