repos
/
qt.core
/ annotate_shade
summary
|
shortlog
|
log
|
tree
|
commit
|
commitdiff
|
headdiff
|
annotate
|
headblob
|
headfilediff
|
filehistory
normal
|
plain
|
shade
|
zebra
Split up in qt.core.
Annotate for file /src/lib/lisp_object.cpp
2010-01-10 tobias
1
#include "lisp_object.h"
08:52:09 '
2
'
3
#include "cl_smoke_qt.h"
2009-04-05 tobias
4
17:56:16 '
5
#include <QtGlobal>
'
6
#include <QtDebug>
2010-01-10 tobias
7
#include <QVariant>
2009-04-05 tobias
8
17:56:16 '
9
namespace cl_smoke {
'
10
namespace qt {
'
11
'
12
/** @struct lisp_object::data
'
13
* @internal
'
14
* Holds a reference ID for a lisp object and calls
'
15
* the destructor callback when it is deleted.
'
16
*/
'
17
'
18
/** @typedef lisp_object::destructor
'
19
* Destructor.
'
20
* @param id The ID
'
21
*/
'
22
'
23
lisp_object::destructor lisp_object::destruct = NULL;
'
24
'
25
'
26
/** Constructor. */
'
27
lisp_object::data::data()
'
28
: id(id),
'
29
is_set(false)
'
30
{ }
'
31
'
32
/** Constructor.
'
33
* @param id The ID.
'
34
*/
2009-07-02 tobias
35
lisp_object::data::data(unsigned int id)
2009-04-05 tobias
36
: id(id),
17:56:16 '
37
is_set(true)
'
38
{ }
'
39
'
40
/** Destructor. */
'
41
lisp_object::data::~data()
'
42
{
'
43
Q_ASSERT_X(lisp_object::destruct, __func__,
'
44
"call setup_lisp_object() first.");
'
45
'
46
if (this->is_set)
'
47
(*lisp_object::destruct)(this->id);
'
48
}
'
49
'
50
/** @class lisp_object
'
51
* @brief Holds a reference ID to a lisp object.
'
52
*
'
53
* The registered destructor callback is called when
'
54
* the last instance for a specific lisp object is deleted.
'
55
*
'
56
* Used for lisp objects in QVariants and signal/slots.
'
57
*/
'
58
'
59
/** Constructor. */
'
60
lisp_object::lisp_object()
'
61
: d(new data())
'
62
{ }
'
63
'
64
/** Constructor.
'
65
* @param id the ID
'
66
*/
2009-07-02 tobias
67
lisp_object::lisp_object(unsigned int id)
2009-04-05 tobias
68
: d(new data(id))
17:56:16 '
69
{ }
'
70
'
71
/** Constructor.
'
72
* @param other the lisp_object to copy
'
73
*/
'
74
lisp_object::lisp_object(const lisp_object& other)
'
75
: d(other.d)
'
76
{ }
'
77
'
78
/** @fn lisp_object::id() const
'
79
* Gets the ID.
'
80
*
'
81
* @return the ID
'
82
*/
'
83
'
84
/** @fn lisp_object::set() const
'
85
* Determines werter the ID is set.
'
86
*
'
87
* @return @c true when the id is set and @c false otherwise.
'
88
*/
'
89
'
90
/** Sets a new ID.
'
91
* @param id the ID
'
92
*/
'
93
void
2009-07-02 tobias
94
lisp_object::set_id(unsigned int id)
2009-04-05 tobias
95
{
17:56:16 '
96
Q_ASSERT(this->set() ? id != this->id() : true);
'
97
'
98
d = new data(id);
'
99
}
'
100
'
101
} // namespace qt
'
102
} // namespace cl_smoke
'
103
'
104
using namespace cl_smoke::qt;
'
105
'
106
/** Initialize the lisp_object.
'
107
* @relates cl_smoke::qt::lisp_object
'
108
* @param destruct destructor callback
'
109
*
'
110
* @return the QMetaType ID of lisp_object
'
111
*/
2010-01-10 tobias
112
CL_SMOKE_QT_EXPORT int
08:52:09 '
113
cl_smoke_setup_lisp_object(void* destruct)
2009-04-05 tobias
114
{
17:56:16 '
115
Q_ASSERT(destruct != NULL);
'
116
lisp_object::destruct = reinterpret_cast<lisp_object::destructor>(destruct);
'
117
'
118
return qRegisterMetaType<lisp_object>();
'
119
}
'
120
'
121
/** Gets the ID of @a object.
'
122
* @relates cl_smoke::qt::lisp_object
'
123
* @param object the lisp_object.
'
124
*
'
125
* @return the ID
'
126
*/
2010-01-10 tobias
127
CL_SMOKE_QT_EXPORT unsigned int
08:52:09 '
128
cl_smoke_lisp_object_id(const void* object)
2009-04-05 tobias
129
{
17:56:16 '
130
return static_cast<const lisp_object*>(object)->id();
'
131
}
'
132
'
133
'
134
/** Determines werter the ID of @a object is set.
'
135
* @relates cl_smoke::qt::lisp_object
'
136
* @param object the object
'
137
*
'
138
* @return @c true when the ID is set and @c false otherwise.
'
139
*/
2010-01-10 tobias
140
CL_SMOKE_QT_EXPORT int
08:52:09 '
141
cl_smoke_lisp_object_is_set(const void* object)
2009-04-05 tobias
142
{
17:56:16 '
143
return static_cast<const lisp_object*>(object)->set();
'
144
}
'
145
'
146
/** Makes a new lisp_object.
'
147
* @relates cl_smoke::qt::lisp_object
'
148
* @param id the ID
'
149
*
'
150
* @return A new lisp_object instance.
'
151
*/
2010-01-10 tobias
152
CL_SMOKE_QT_EXPORT void*
08:52:09 '
153
cl_smoke_make_lisp_object(unsigned int id)
2009-04-05 tobias
154
{
17:56:16 '
155
return new lisp_object(id);
'
156
}
'
157
'
158
/** Deletes a lisp_object.
'
159
* @relates cl_smoke::qt::lisp_object
'
160
* @param object the lisp_object
'
161
*/
2010-01-10 tobias
162
CL_SMOKE_QT_EXPORT void*
08:52:09 '
163
cl_smoke_free_lisp_object(void* object)
2009-04-05 tobias
164
{
17:56:16 '
165
delete static_cast<lisp_object*>(object);
'
166
}
'
167
'
168
/** Gets the lisp_object of a QVariant.
'
169
* @relates cl_smoke::qt::lisp_object
'
170
* @param variant the QVariant
'
171
*
'
172
* @return a new lisp_object.
'
173
*/
2010-01-10 tobias
174
CL_SMOKE_QT_EXPORT void*
08:52:09 '
175
cl_smoke_lisp_object_value(const void* variant)
2009-04-05 tobias
176
{
17:56:16 '
177
const QVariant* qvariant = static_cast<const QVariant*>(variant);
'
178
Q_ASSERT(QVariant::UserType == qvariant->type());
'
179
'
180
new lisp_object(qvariant->value<lisp_object>());
'
181
}