forked from decarbonization/PlayerKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RBObject.h
131 lines (111 loc) · 2.75 KB
/
RBObject.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//
// RBObject.h
// PlayerKit
//
// Created by Peter MacWhinnie on 6/23/09.
// Copyright 2009 Roundabout Software. All rights reserved.
//
#ifndef RBObject_h
#define RBObject_h 1
#include <CoreFoundation/CoreFoundation.h>
#include <libKern/OSAtomic.h>
#include <iostream>
#ifndef PK_FINAL
# define PK_FINAL
#endif /* PK_FINAL */
#ifndef PK_PURE_VIRTUAL
# define PK_PURE_VIRTUAL =0
#endif /* PK_PURE_VIRTUAL */
#if !defined(PK_VISIBILITY_PUBLIC) && !defined(PK_VISIBILITY_HIDDEN)
# if __GNUC__ >= 4
# define PK_VISIBILITY_PUBLIC __attribute__((visibility("default")))
# define PK_VISIBILITY_HIDDEN __attribute__((visibility("hidden")))
# else
# define PK_VISIBILITY_PUBLIC
# define PK_VISIBILITY_HIDDEN
# endif /* __GNUC__ >= 4 */
#endif /* !defined(PK_VISIBILITY_PUBLIC) && !defined(PK_VISIBILITY_HIDDEN) */
/*!
@class
@abstract The RBObject class provides a common base for objects in PlayerKit.
*/
class RBObject
{
protected:
const char *mClassName;
mutable int32_t mRetainCount;
public:
/*!
@ctor
@abstract The default constructor.
@param className The name of class this object belongs to.
@discussion This constructor should only be used by subclasses of RBObject,
which should pass in their name so RBObject can provide an
appropriate description..
*/
RBObject(const char *className = "RBObject") :
mRetainCount(1),
mClassName(strdup(className))
{
}
virtual ~RBObject()
{
if(mClassName)
{
free((void *)(mClassName));
mClassName = NULL;
}
}
#pragma mark Retain Counts
/*!
@method
@abstract The retain count of the object.
*/
int32_t GetRetainCount() const { return mRetainCount; }
/*!
@method
@abstract Retain the receiver. This method is thread safe.
*/
void Retain() const
{
OSAtomicIncrement32((volatile int32_t *)&mRetainCount);
}
/*!
@method
@abstract Release the receiver, deleting it its retain count is 0. This method is thread safe.
*/
void Release() const
{
OSAtomicDecrement32((volatile int32_t *)&mRetainCount);
if(mRetainCount == 0)
delete this;
}
#pragma mark Describing
/*!
@method
@abstract Copy the description of the receiver.
*/
virtual CFStringRef CopyDescription()
{
return CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("<%s:%p>"), mClassName, this);
}
/*!
@method
@abstract Get the class name of the receiver.
@discussion The receiver owns the value returned by this method.
*/
virtual const char *GetClassName() const { return mClassName; }
#pragma mark Equality
/*!
@method
@abstract Whether or not the receiver is equal to another RBObject.
*/
virtual bool IsEqualTo(RBObject *other)
{
return this == other;
}
private:
RBObject(RBObject &object);
RBObject &operator=(RBObject &object);
};
#endif /* RBObject_h */