Zen API

- Home
- Topics
- Types
- Files

All Classes Files Functions Variables Typedefs Friends Macros Modules Pages
Public Member Functions | Protected Member Functions
kObject Class Reference
kApi

## Description

Root of all Zen classes.

The kObject class provides infrastructure to support object destruction, reference counting, and type introspection.

The kObject_Destroy method can be used to destroy an instance of any class. The kObject_Dispose method provides support for recursive destruction, often used in conjunction with Zen data collections. Refer to Object Destruction for more information.

The kObject_Clone method can be used to create a deep copy of an object. The implementation of this method requires additional support from derived types; refer to the documentation for a specific derived type to determine whether cloning is supported.

The kObject_Clone and kObject_Dispose methods are often used together to manage collections of data objects:

kList list = kNULL;
kList copy = kNULL;
kImage image = kNULL;
kSize imageCount = 10;
//create a list of image objects
kCheck(kList_Construct(&list, kTypeOf(kImage), imageCount, kNULL));
for (kSize i = 0; i < imageCount; ++i)
{
kCheck(kImage_Construct(&image, kTypeOf(kArgb), 640, 480, kNULL));
kList_Add(list, &image);
}
//make a deep copy of the list; copies both the list and the images contained in the list
kCheck(kObject_Clone(&copy, list, kNULL));
//...
//clean up; destroy the lists and the images contained in the lists
kObject_Dispose(list);
kObject_Dispose(copy);

All kObject-derived instances are reference counted. The kObject_Share method can optionally be used to increment an object's reference count, while the kObject_Destroy/kObject_Dispose methods are always used to decrement an object's reference count. Refer to Reference Counting for more information.

The kObject_Type method can be used to access type information for any kObject instance. The kType object returned by this method can be used to learn about the object's class, including its name, base classes, implemented interfaces, and methods. The kObject_Is method provides a convenient way to determine whether an object derives from a specific base class or implements an interface.

The kObject_Equals and kObject_HashCode methods can be helpful for object comparisons, but require support from derived types and are infrequently overridden. The kString class overrides both of these methods to support the use of kString objects as hash keys in kMap data collections.

Inherited by kAlloc, kArray1, kArray2, kArray3, kArrayList, kAssembly, kBackTrace, kBox, kCipher, kDirectory, kDynamicLib, kEvent, kHash, kHttpServer, kHttpServerChannel, kHttpServerRequest, kHttpServerResponse, kImage, kList, kLock, kMap, kMath, kMsgQueue, kNetwork, kParallel, kPath, kPeriodic, kPlugin, kProcess, kQueue, kSemaphore, kSerializer, kSocket, kStream, kString, kSymbolInfo, kTcpServer, kThread, kThreadPool, kTimer, kType, kUtils, and kXml.

## Public Member Functions
kAlloc | kObject_Alloc (kObject object)
| Gets the memory allocator associated with this object. More...
kStatus | kObject_Clone (kObject *object, kObject source, kAlloc allocator)
| Constructs a new object by copying an existing object, including any aggregated child elements. More...
kStatus | kObject_Destroy (kObject object)
| Destroys the object. More...
kStatus | kObject_Dispose (kObject object)
| Destroys the object and any aggregated child elements. More...
kBool | kObject_Equals (kObject object, kObject other)
| Determines whether the object is equal to another object. More...
kSize | kObject_HashCode (kObject object)
| Gets a hash code representing the state of this object. More...
kBool | kObject_Is (kObject object, kType type)
| Determines whether this object is an instance of the specified type. More...
kBool | kObject_IsShared (kObject object)
| Reports whether the object is currently shared (reference count greater than one). More...
kStatus | kObject_SetPool (kObject object, kObjectPool pool)
| Sets the object pool associated with this object. More...
kStatus | kObject_Share (kObject object)
| Increments the reference count associated with this object. More...
kSize | kObject_Size (kObject object)
| Estimates the memory consumed by this object, including any aggregated child elements. More...
kType | kObject_Type (kObject object)
| Returns the type of the object. More...

## Protected Member Functions
kStatus | kObject_FreeMem (kObject object, void *mem)
| Protected method called by derived classes to free memory using the object's allocator. More...
kStatus | kObject_FreeMemRef (kObject object, void *mem)
| Protected method called by derived classes to free memory (and reset the provided memory pointer to kNULL) using the object's allocator. More...
kStatus | kObject_GetMem (kObject object, kSize size, void *mem)
| Protected method called by derived classes to allocate memory using the object's allocator. More...
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. More...
kStatus | kObject_Init (kObject object, kType type, kAlloc alloc)
| Protected method called by derived classes to initialize the kObject base class. More...
kStatus | kObject_VDisposeItems (kObject object)
| Protected virtual method that destroys any aggregated child objects associated with a collection. More...
kBool | kObject_VEquals (kObject object, kObject other)
| Protected virtual method that compares two objects for equality. More...
kSize | kObject_VHashCode (kObject object)
| Protected virtual method that calculates a hash code representing the object instance. More...
kStatus | kObject_VInitClone (kObject object, kObject source, kAlloc allocator)
| Protected virtual method that clones (makes a deep copy of) the specified source object. More...
kStatus | kObject_VRelease (kObject object)
| Protected virtual method that deallocates any resources owned by the object. More...
kSize | kObject_VSize (kObject object)
| Protected virtual method that calculates the total size (in bytes) of the object instance. More...

The documentation for this class was generated from the following file:

- kObject.h