kmediad 0.5.0a
A cross-platform Web-based audio player
Data Structures | Defines | Typedefs | Functions | Variables
klib_object.h File Reference

Interface of the klib_Object class. More...

#include <klib_defines.h>

Go to the source code of this file.

Data Structures

struct  _klib_Object
 The basic basic structure underling all klib objects. More...

Defines

#define KLIB_CLASSNAME_MAX_LEN   30
#define KLIB_OBJECT_TRACE_REFS   0x0001
#define KLIB_OBJECT_TRACE_CONSTRUCTION   0x0002

Typedefs

typedef struct _klib_Object klib_Object
typedef void(* klib_Object_DisposeFunc )(klib_Object *self)
typedef struct _klib_String *(* klib_Object_TostringFunc )(const klib_Object *self)

Functions

void klib_object_construct (klib_Object *self, const char *class_name)
 Initialize the object's memory and ref count.
void klib_object_dispose (klib_Object *self)
 Reclaim memory.
void klib_object_unref (klib_Object *self)
 Decrement the reference count of the object.
struct _klib_Stringklib_object_tostring (const klib_Object *self)
 Get a string representation of the object.
void klib_object_add_ref (klib_Object *self)
 Increment the reference count of the object.
BOOL klib_object_istype (klib_Object *o, const char *class_name)
 Returns true if the object has a particular type name.

Variables

int klib_object_trace_flags
 Can be set non-zero to enable very fine tracing.

Detailed Description

Interface of the klib_Object class.

klib_Object is the base, direct or indirect, of all objects in the klib library.


Define Documentation

#define KLIB_CLASSNAME_MAX_LEN   30
#define KLIB_OBJECT_TRACE_CONSTRUCTION   0x0002
#define KLIB_OBJECT_TRACE_REFS   0x0001

Typedef Documentation

typedef struct _klib_Object klib_Object
typedef void(* klib_Object_DisposeFunc)(klib_Object *self)
typedef struct _klib_String*(* klib_Object_TostringFunc)(const klib_Object *self)

Function Documentation

void klib_object_add_ref ( klib_Object self)

Increment the reference count of the object.

  {
  self->ref_count++;
  if (klib_object_trace_flags & KLIB_OBJECT_TRACE_REFS)
    {
    klib_log (KLIB_LOG_TRACE, "add_ref() called on object %X of class %s\n",
      (long)self, self->class_name);
    klib_log (KLIB_LOG_TRACE, "New ref count is %d\n", self->ref_count);
    }
  }
void klib_object_construct ( klib_Object self,
const char *  class_name 
)

Initialize the object's memory and ref count.

  {
  if (klib_object_trace_flags & KLIB_OBJECT_TRACE_CONSTRUCTION)
    klib_log (KLIB_LOG_TRACE, "Called constructor for Object\n");

  memset (self, 0, sizeof (klib_Object));
  self->ref_count = 0;
  self->dispose_func = klib_object_dispose;
  self->tostring_func = _klib_object_tostring;
  strncpy (self->class_name, class_name, sizeof (self->class_name) - 1);
  }
void klib_object_dispose ( klib_Object self)

Reclaim memory.

  {
  if (klib_object_trace_flags & KLIB_OBJECT_TRACE_CONSTRUCTION)
    klib_log (KLIB_LOG_TRACE, "Called destructor for Object\n");
  free (self);
  }
BOOL klib_object_istype ( klib_Object o,
const char *  class_name 
)

Returns true if the object has a particular type name.

  {
  if (!self) return FALSE;
  if (strcmp (class_name, self->class_name) == 0) return TRUE;
  return FALSE;
  }
struct _klib_String* klib_object_tostring ( const klib_Object self) [read]

Get a string representation of the object.

Caller must free this String

  {
  if (self == NULL) return klib_string_new ("(null)");
  return self->tostring_func (self);
  }
void klib_object_unref ( klib_Object self)

Decrement the reference count of the object.

  {
  if (klib_object_trace_flags & KLIB_OBJECT_TRACE_REFS)
    {
    klib_log (KLIB_LOG_TRACE, "unref() called on object %X of class %s\n",
      (long)self, self->class_name);
    }
  if (self->ref_count > 0)
    {
    if (klib_object_trace_flags & KLIB_OBJECT_TRACE_CONSTRUCTION)
      klib_log (KLIB_LOG_TRACE, "ref_count is %d -- will decrement\n",
    self->ref_count);
    self->ref_count--;
    }
  else
    {
    if (klib_object_trace_flags & KLIB_OBJECT_TRACE_CONSTRUCTION)
      klib_log (KLIB_LOG_TRACE, "ref_count is zero -- will dispose\n");
    self->dispose_func (self);
    }
  }

Variable Documentation

Can be set non-zero to enable very fine tracing.