Zen API

- Home
- Topics
- Types
- Files

All Classes Files Functions Variables Typedefs Friends Macros Modules Pages
kObject.h
Go to the documentation of this file.
1
10 #include <kApi/kApiDef.h> //--inclusion order controlled by kApiDef
11
12 #ifndef K_API_OBJECT_H
13 #define K_API_OBJECT_H
14
15 #include <kApi/kObject.x.h>
16
73 //typedef kPointer kObject; --forward-declared in kApiDef.x.h
74
75 /*
76 * Public
77 */
78
97 kInlineFx(kStatus) kObject_Clone(kObject* object, kObject source, kAlloc allocator)
98 {
99 if (!kIsNull(source))
100 {
101 return xkObject_CloneImpl(object, source, allocator);
102 }
103
104 *object = kNULL;
105
106 return kOK;
107 }
108
119 kInlineFx(kStatus) kObject_Share(kObject object)
120 {
121 kObj(kObject, object);
122
123 kAtomic32s_Increment(&obj->refCount);
124
125 return kOK;
126 }
127
140 kInlineFx(kStatus) kObject_SetPool(kObject object, kObjectPool pool)
141 {
142 kObj(kObject, object);
143
144 obj->pool = pool;
145
146 return kOK;
147 }
148
165 kInlineFx(kStatus) kObject_Destroy(kObject object)
166 {
167 if (!kIsNull(object))
168 {
169 return xkObject_DestroyImpl(object, kFALSE);
170 }
171
172 return kOK;
173 }
174
193 kInlineFx(kStatus) kObject_Dispose(kObject object)
194 {
195 if (!kIsNull(object))
196 {
197 return xkObject_DestroyImpl(object, kTRUE);
198 }
199
200 return kOK;
201 }
202
214 kInlineFx(kType) kObject_Type(kObject object)
215 {
216 kObj(kObject, object);
217
218 return obj->type;
219 }
220
234 kInlineFx(kBool) kObject_Is(kObject object, kType type)
235 {
236 kObjR(kObject, object);
237
238 return !kIsNull(object) && !kIsNull(type) && !kIsNull(obj->type) &&
239 xkObject_RawVerifyTag(object) && kType_Is(obj->type, type);
240 }
241
254 kInlineFx(kBool) kObject_Equals(kObject object, kObject other)
255 {
256 return xkObject_VTable(object)->VEquals(object, other);
257 }
258
269 kInlineFx(kSize) kObject_HashCode(kObject object)
270 {
271 return xkObject_VTable(object)->VHashCode(object);
272 }
273
286 kInlineFx(kAlloc) kObject_Alloc(kObject object)
287 {
288 kObj(kObject, object);
289
290 return obj->alloc;
291 }
292
300 kInlineFx(kBool) kObject_HasForeignData(kObject object)
301 {
302 return xkObject_VTable(object)->VHasForeignData(object);
303 }
304
316 kInlineFx(kSize) kObject_Size(kObject object)
317 {
318 return xkObject_VTable(object)->VSize(object);
319 }
320
337 kInlineFx(kBool) kObject_IsShared(kObject object)
338 {
339 kObj(kObject, object);
340
341 return kAtomic32s_Get(&obj->refCount) > 1;
342 }
343
344 /*
345 * Protected
346 */
347
359 kInlineFx(kStatus) kObject_Init(kObject object, kType type, kAlloc alloc)
360 {
361 kObjR(kObject, object);
362
363 obj->type = type;
364 obj->alloc = alloc;
365 obj->pool = kNULL;
366 obj->tag = xkOBJECT_TAG;
367
368 kAtomic32s_Init(&obj->refCount, 1);
369
370 return kOK;
371 }
372
384 kInlineFx(kStatus) kObject_GetMem(kObject object, kSize size, void* mem)
385 {
386 return kAlloc_Get(kObject_Alloc(object), size, mem);
387 }
388
400 kInlineFx(kStatus) kObject_GetMemZero(kObject object, kSize size, void* mem)
401 {
402 return kAlloc_GetZero(kObject_Alloc(object), size, mem);
403 }
404
415 kInlineFx(kStatus) kObject_FreeMem(kObject object, void* mem)
416 {
417 return kAlloc_Free(kObject_Alloc(object), mem);
418 }
419
430 kInlineFx(kStatus) kObject_FreeMemRef(kObject object, void* mem)
431 {
432 return kAlloc_FreeRef(kObject_Alloc(object), mem);
433 }
434
448 kInlineFx(kStatus) kObject_VRelease(kObject object)
449 {
450 kObjR(kObject, object);
451
452 obj->tag = 0;
453
454 return kOK;
455 }
456
470 kInlineFx(kStatus) kObject_VInitClone(kObject object, kObject source, kAlloc allocator)
471 {
472 return kERROR_UNIMPLEMENTED;
473 }
474
486 kInlineFx(kStatus) kObject_VDisposeItems(kObject object)
487 {
488 return kOK;
489 }
490
498 kInlineFx(kBool) kObject_VHasForeignData(kObject object)
499 {
500 return kFALSE;
501 }
502
517 kInlineFx(kSize) kObject_VSize(kObject object)
518 {
519 return kType_InnerSize(kObject_Type(object));
520 }
521
534 kInlineFx(kSize) kObject_VHashCode(kObject object)
535 {
536 return xkHashPointer(object);
537 }
538
553 kInlineFx(kBool) kObject_VEquals(kObject object, kObject other)
554 {
555 return (object == other);
556 }
557
558 #endif
kObject::kObject_VRelease
kStatus kObject_VRelease(kObject object)
Protected virtual method that deallocates any resources owned by the object.
Definition: kObject.h:448
kObject::kObject_Type
kType kObject_Type(kObject object)
Returns the type of the object.
Definition: kObject.h:214
kObject::kObject_Alloc
kAlloc kObject_Alloc(kObject object)
Gets the memory allocator associated with this object.
Definition: kObject.h:286
kObject::kObject_Equals
kBool kObject_Equals(kObject object, kObject other)
Determines whether the object is equal to another object.
Definition: kObject.h:254
kObject::kObject_HashCode
kSize kObject_HashCode(kObject object)
Gets a hash code representing the state of this object.
Definition: kObject.h:269
kPointer::kIsNull
#define kIsNull(POINTER)
Tests for equality with null pointer.
Definition: kApiDef.h:341
kObject::kObject_Is
kBool kObject_Is(kObject object, kType type)
Determines whether this object is an instance of the specified type.
Definition: kObject.h:234
kAtomic32s::kAtomic32s_Increment
k32s kAtomic32s_Increment(kAtomic32s *atomic)
Increments an atomic variable.
Definition: kAtomic.h:50
kObject::kObject_Init
kStatus kObject_Init(kObject object, kType type, kAlloc alloc)
Protected method called by derived classes to initialize the kObject base class.
Definition: kObject.h:359
kObject::kObject_VHasForeignData
kBool kObject_VHasForeignData(kObject object)
Protected virtual method that reports whether the object, including aggregated child elements...
Definition: kObject.h:498
kSize
Represents an unsigned integer that can store a pointer address.
kAlloc
Abstract base class for memory allocator types.
kObject::kObject_Share
kStatus kObject_Share(kObject object)
Increments the reference count associated with this object.
Definition: kObject.h:119
kObject::kObject_VHashCode
kSize kObject_VHashCode(kObject object)
Protected virtual method that calculates a hash code representing the object instance.
Definition: kObject.h:534
kAlloc::kAlloc_Free
kStatus kAlloc_Free(kAlloc alloc, void *mem)
Frees a block of memory.
Definition: kAlloc.h:84
kObject::kObject_FreeMemRef
kStatus kObject_FreeMemRef(kObject object, void *mem)
Protected method called by derived classes to free memory (and reset the provided memory pointer to k...
Definition: kObject.h:430
kInlineFx
#define kInlineFx(TYPE)
Inline method declaration helper.
Definition: kApiDef.h:26
kObject::kObject_Clone
kStatus kObject_Clone(kObject *object, kObject source, kAlloc allocator)
Constructs a new object by copying an existing object, including any aggregated child elements...
Definition: kObject.h:97
kBool::kTRUE
#define kTRUE
Boolean true.
Definition: kApiDef.h:356
kObject::kObject_IsShared
kBool kObject_IsShared(kObject object)
Reports whether the object is currently shared (reference count greater than one).
Definition: kObject.h:337
kObject::kObject_VInitClone
kStatus kObject_VInitClone(kObject object, kObject source, kAlloc allocator)
Protected virtual method that clones (makes a deep copy of) the specified source object.
Definition: kObject.h:470
kObj
#define kObj(TypeName_T, T_object)
Declares a local "obj" (this-pointer) variable and initializes it from a type-checked object handle...
Definition: kApiDef.h:2923
kObjR
#define kObjR(TypeName_T, T_object)
Declares a local "obj" (this-pointer) variable and initializes it from an object handle, without type-checking.
Definition: kApiDef.h:2935
kObjectPool
Supports reclaiming objects upon destruction.
kApiDef.h
Core Zen type declarations.
kObject::kObject_HasForeignData
kBool kObject_HasForeignData(kObject object)
Reports whether the object, including aggregated child elements, contains any foreign memory referenc...
Definition: kObject.h:300
kAlloc::kAlloc_FreeRef
kStatus kAlloc_FreeRef(kAlloc alloc, void *mem)
Frees a block of memory and sets the memory pointer to kNULL.
Definition: kAlloc.h:97
kObject::kObject_Destroy
kStatus kObject_Destroy(kObject object)
Destroys the object.
Definition: kObject.h:165
kStatus::kERROR_UNIMPLEMENTED
#define kERROR_UNIMPLEMENTED
Feature not implemented.
Definition: kApiDef.h:494
kType
Represents metadata about a type (class, interface, or value).
kObject::kObject_VEquals
kBool kObject_VEquals(kObject object, kObject other)
Protected virtual method that compares two objects for equality.
Definition: kObject.h:553
kObject::kObject_Dispose
kStatus kObject_Dispose(kObject object)
Destroys the object and any aggregated child elements.
Definition: kObject.h:193
kObject::kObject_SetPool
kStatus kObject_SetPool(kObject object, kObjectPool pool)
Sets the object pool associated with this object.
Definition: kObject.h:140
kType::kType_InnerSize
kSize kType_InnerSize(kType type)
Gets the internal size of a type.
Definition: kType.h:321
kObject
Root of all Zen classes.
kObject::kObject_Size
kSize kObject_Size(kObject object)
Estimates the memory consumed by this object, including any aggregated child elements.
Definition: kObject.h:316
kStatus::kOK
#define kOK
Operation successful.
Definition: kApiDef.h:515
kAtomic32s::kAtomic32s_Init
void kAtomic32s_Init(kAtomic32s *atomic, k32s value)
Initializes an atomic variable with a particular value.
Definition: kAtomic.h:36
kStatus
Represents an error code.
kObject::kObject_GetMem
kStatus kObject_GetMem(kObject object, kSize size, void *mem)
Protected method called by derived classes to allocate memory using the object's allocator.
Definition: kObject.h:384
kNULL
#define kNULL
Null pointer.
Definition: kApiDef.h:269
kAlloc::kAlloc_Get
kStatus kAlloc_Get(kAlloc alloc, kSize size, void *mem)
Allocates a block of memory.
Definition: kAlloc.h:37
kObject::kObject_GetMemZero
kStatus kObject_GetMemZero(kObject object, kSize size, void *mem)
Protected method called by derived classes to allocate and zero memory using the object's allocator...
Definition: kObject.h:400
kType::kType_Is
kBool kType_Is(kType type, kType other)
Determines whether a type is equivalent to another type.
Definition: kType.h:89
kObject::kObject_VDisposeItems
kStatus kObject_VDisposeItems(kObject object)
Protected virtual method that destroys any aggregated child objects associated with a collection...
Definition: kObject.h:486
kBool
Represents a boolean value.
kBool::kFALSE
#define kFALSE
Boolean false.
Definition: kApiDef.h:355
kAlloc::kAlloc_GetZero
kStatus kAlloc_GetZero(kAlloc alloc, kSize size, void *mem)
Allocates a block of memory and zero-initializes the block.
Definition: kAlloc.h:51
kObject::kObject_FreeMem
kStatus kObject_FreeMem(kObject object, void *mem)
Protected method called by derived classes to free memory using the object's allocator.
Definition: kObject.h:415
kAtomic32s::kAtomic32s_Get
k32s kAtomic32s_Get(kAtomic32s *atomic)
Gets the current value of an atomic variable.
Definition: kAtomic.h:111
kObject::kObject_VSize
kSize kObject_VSize(kObject object)
Protected virtual method that calculates the total size (in bytes) of the object instance.
Definition: kObject.h:517