Repository navigation
Expand file tree
/
Copy pathObject.cpp
More file actions
99 lines (72 loc) · 1.37 KB
/
Copy pathObject.cpp
File metadata and controls
99 lines (72 loc) · 1.37 KB
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
/**
* \file Object.cpp
* \author Jan Milík <milikjan@fit.cvut.cz>
* \date 2011-03-27
*
* \brief Implementation of the Object class.
*/
#include <cassert>
#include <exception>
#include <iostream>
#include "Object.h"
#include "Debug.h"
namespace cppapp {
Object::Object()
{
refCount_ = 0;
sentinel_ = SENTINEL;
}
Object::~Object()
{
checkHealth();
refCount_ = 0;
sentinel_ = DEAD_SENTINEL;
}
void Object::claim()
{
checkHealth();
refCount_++;
}
/**
* This method checks reference count (for live objects, ref count should
* be greater or equal to 0) and the sentinel (\c int value in the object
* that set to a defined value in live objects and different value in
* dead objects).
*/
void Object::checkHealth() const
{
CPPAPP_ASSERT(refCount_ >= 0);
CPPAPP_ASSERT(sentinel_ == SENTINEL);
}
Object* Object::release(Object* obj)
{
if (obj != NULL) obj->checkHealth();
CPPAPP_ASSERT(obj->refCount_ > 0);
if (--(obj->refCount_) <= 0) {
delete obj;
return NULL;
}
return obj;
}
std::string Object::getClassName()
{
const char *mangled = typeid(*this).name();
int status = 0;
size_t length = 0;
char *result = abi::__cxa_demangle(
mangled,
NULL,
&length,
&status
);
std::string str;
if (status == 0)
str = std::string(result);
else
str = std::string(mangled);
return str;
}
void Object::deleteAll()
{
}
} // namespace cppapp