Zen API
 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 objectAllocator)
98 {
99  if (!kIsNull(source))
100  {
101  return xkObject_CloneImpl(object, source, objectAllocator, objectAllocator, kNULL);
102  }
103 
104  *object = kNULL;
105 
106  return kOK;
107 }
108 
138 #if defined (K_CPP)
139 kInlineFx(kStatus) kObject_Clone(kObject* object, kObject source, kAlloc objectAllocator, kAlloc valueAllocator, kObject context = kNULL)
140 {
141  if (!kIsNull(source))
142  {
143  return xkObject_CloneImpl(object, source, objectAllocator, valueAllocator, context);
144  }
145 
146  *object = kNULL;
147 
148  return kOK;
149 }
150 #endif
151 
163 {
164  kObj(kObject, object);
165 
166  kAtomic32s_Increment(&obj->refCount);
167 
168  return kOK;
169 }
170 
184 {
185  kObj(kObject, object);
186 
187  obj->pool = pool;
188 
189  return kOK;
190 }
191 
209 {
210  if (!kIsNull(object))
211  {
212  return xkObject_DestroyImpl(object, kFALSE);
213  }
214 
215  return kOK;
216 }
217 
237 {
238  if (!kIsNull(object))
239  {
240  return xkObject_DestroyImpl(object, kTRUE);
241  }
242 
243  return kOK;
244 }
245 
258 {
259  kObj(kObject, object);
260 
261  return obj->type;
262 }
263 
278 {
279  kObjR(kObject, object);
280 
281  return !kIsNull(object) && !kIsNull(type) && !kIsNull(obj->type) &&
282  xkObject_RawVerifyTag(object) && kType_Is(obj->type, type);
283 }
284 
298 {
299  return xkObject_VTable(object)->VEquals(object, other);
300 }
301 
313 {
314  return xkObject_VTable(object)->VHashCode(object);
315 }
316 
330 {
331  kObj(kObject, object);
332 
333  return obj->alloc;
334 }
335 
344 {
345  return xkObject_VTable(object)->VAllocTraits(object);
346 }
347 
356 {
357  return (kObject_AllocTraits(object) & kALLOC_TRAIT_FOREIGN) != 0;
358 }
359 
372 {
373  return xkObject_VTable(object)->VSize(object);
374 }
375 
393 {
394  kObj(kObject, object);
395 
396  return kAtomic32s_Get(&obj->refCount) > 1;
397 }
398 
410 {
411  return xkObject_VTable(object)->VHasShared(object);
412 }
413 
414 /*
415 * Protected
416 */
417 
430 {
431  kObjR(kObject, object);
432 
433  obj->type = type;
434  obj->alloc = alloc;
435  obj->pool = kNULL;
436  obj->tag = xkOBJECT_TAG;
437 
438  kAtomic32s_Init(&obj->refCount, 1);
439 
440  return kOK;
441 }
442 
454 kInlineFx(kStatus) kObject_GetMem(kObject object, kSize size, void* mem)
455 {
456  return kAlloc_Get(kObject_Alloc(object), size, mem);
457 }
458 
471 {
472  return kAlloc_GetZero(kObject_Alloc(object), size, mem);
473 }
474 
486 {
487  return kAlloc_Free(kObject_Alloc(object), mem);
488 }
489 
501 {
502  return kAlloc_FreeRef(kObject_Alloc(object), mem);
503 }
504 
519 {
520  kObjR(kObject, object);
521 
522  obj->tag = 0;
523 
524  return kOK;
525 }
526 
545 kInlineFx(kStatus) kObject_VClone(kObject object, kObject source, kAlloc valueAllocator, kObject context)
546 {
547  return kERROR_UNIMPLEMENTED;
548 }
549 
562 {
563  return kOK;
564 }
565 
574 {
575  kObj(kObject, object);
576 
577  return kObject_IsShared(object);
578 }
579 
588 {
589  kObj(kObject, object);
590 
591  return kAlloc_Traits(obj->alloc);
592 }
593 
609 {
610  return kType_InnerSize(kObject_Type(object));
611 }
612 
626 {
627  return xkHashPointer(object);
628 }
629 
645 {
646  return (object == other);
647 }
648 
649 #endif
kStatus kObject_VRelease(kObject object)
Protected virtual method that deallocates any resources owned by the object.
Definition: kObject.h:518
kType kObject_Type(kObject object)
Returns the type of the object.
Definition: kObject.h:257
kAllocTrait kObject_VAllocTraits(kObject object)
Protected virtual method that gets the bitset of allocator traits for any allocators used within this...
Definition: kObject.h:587
kStatus kAlloc_Get(kAlloc alloc, kSize size, void *mem, kMemoryAlignment alignment)
Allocates a block of memory.
Definition: kAlloc.h:39
kAllocTrait kObject_AllocTraits(kObject object)
Gets the bitset of allocator traits for any allocators used within this object, including aggregated ...
Definition: kObject.h:343
kAlloc kObject_Alloc(kObject object)
Gets the memory allocator associated with this object.
Definition: kObject.h:329
kBool kObject_Equals(kObject object, kObject other)
Determines whether the object is equal to another object.
Definition: kObject.h:297
kSize kObject_HashCode(kObject object)
Gets a hash code representing the state of this object.
Definition: kObject.h:312
#define kIsNull(POINTER)
Tests for equality with null pointer.
Definition: kApiDef.h:341
kBool kObject_Is(kObject object, kType type)
Determines whether this object is an instance of the specified type.
Definition: kObject.h:277
k32s kAtomic32s_Increment(kAtomic32s *atomic)
Increments an atomic variable.
Definition: kAtomic.h:50
kStatus kObject_Init(kObject object, kType type, kAlloc alloc)
Protected method called by derived classes to initialize the kObject base class.
Definition: kObject.h:429
Represents an unsigned integer that can store a pointer address.
Abstract base class for memory allocator types.
kStatus kObject_Share(kObject object)
Increments the reference count associated with this object.
Definition: kObject.h:162
kSize kObject_VHashCode(kObject object)
Protected virtual method that calculates a hash code representing the object instance.
Definition: kObject.h:625
kStatus kAlloc_Free(kAlloc alloc, void *mem)
Frees a block of memory.
Definition: kAlloc.h:122
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:500
#define kInlineFx(TYPE)
Inline method declaration helper.
Definition: kApiDef.h:26
kBool kObject_HasShared(kObject object)
Reports whether an object or any of its aggregated child elements has a reference count greater than ...
Definition: kObject.h:409
kStatus kAlloc_GetZero(kAlloc alloc, kSize size, void *mem, kMemoryAlignment alignment)
Allocates a block of memory and zero-initializes the block.
Definition: kAlloc.h:70
#define kTRUE
Boolean true.
Definition: kApiDef.h:356
kBool kObject_IsShared(kObject object)
Reports whether the object is currently shared (reference count greater than one).
Definition: kObject.h:392
kStatus kObject_VClone(kObject object, kObject source, kAlloc valueAllocator, kObject context)
Protected virtual method that clones (makes a deep copy of) the specified source object.
Definition: kObject.h:545
kStatus kObject_Clone(kObject *object, kObject source, kAlloc objectAllocator)
Constructs a new object by copying an existing object, including any aggregated child elements...
Definition: kObject.h:97
#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:3383
#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:3395
Supports reclaiming objects upon destruction.
Core Zen type declarations.
kBool kObject_HasForeignData(kObject object)
Reports whether the object, including aggregated child elements, contains any foreign memory referenc...
Definition: kObject.h:355
kBool kObject_VHasShared(kObject object)
Protected virtual method that reports whether an object or any of its aggregated child elements has a...
Definition: kObject.h:573
kStatus kAlloc_FreeRef(kAlloc alloc, void *mem)
Frees a block of memory and sets the memory pointer to kNULL.
Definition: kAlloc.h:135
kStatus kObject_Destroy(kObject object)
Destroys the object.
Definition: kObject.h:208
#define kALLOC_TRAIT_FOREIGN
Allocates memory in a foreign memory domain (non-host address space).
Definition: kApiDef.h:2236
#define kERROR_UNIMPLEMENTED
Feature is not implemented.
Definition: kApiDef.h:494
Represents metadata about a type (class, interface, or value).
kBool kObject_VEquals(kObject object, kObject other)
Protected virtual method that compares two objects for equality.
Definition: kObject.h:644
kAllocTrait kAlloc_Traits(kAlloc alloc)
Gets the traits associated with this allocator.
Definition: kAlloc.h:179
kStatus kObject_Dispose(kObject object)
Destroys the object and any aggregated child elements.
Definition: kObject.h:236
kStatus kObject_SetPool(kObject object, kObjectPool pool)
Sets the object pool associated with this object.
Definition: kObject.h:183
kSize kType_InnerSize(kType type)
Gets the internal size of a type.
Definition: kType.h:321
Root of all Zen classes.
kSize kObject_Size(kObject object)
Estimates the memory consumed by this object, including any aggregated child elements.
Definition: kObject.h:371
#define kOK
Operation successful.
Definition: kApiDef.h:515
void kAtomic32s_Init(kAtomic32s *atomic, k32s value)
Initializes an atomic variable with a particular value.
Definition: kAtomic.h:36
Represents an error code.
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:454
#define kNULL
Null pointer.
Definition: kApiDef.h:269
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:470
kBool kType_Is(kType type, kType other)
Determines whether a type is equivalent to another type.
Definition: kType.h:89
kStatus kObject_VDisposeItems(kObject object)
Protected virtual method that destroys any aggregated child objects associated with a collection...
Definition: kObject.h:561
Represents a memory allocator trait.
Represents a boolean value.
#define kFALSE
Boolean false.
Definition: kApiDef.h:355
kStatus kObject_FreeMem(kObject object, void *mem)
Protected method called by derived classes to free memory using the object's allocator.
Definition: kObject.h:485
k32s kAtomic32s_Get(kAtomic32s *atomic)
Gets the current value of an atomic variable.
Definition: kAtomic.h:111
kSize kObject_VSize(kObject object)
Protected virtual method that calculates the total size (in bytes) of the object instance.
Definition: kObject.h:608