|
kmediad 0.5.0a
A cross-platform Web-based audio player
|
Implementation of the klib_NVPair class. More...
#include <malloc.h>#include <string.h>#include <stdarg.h>#include <ctype.h>#include "klib_log.h"#include "klib_object.h"#include "klib_string.h"#include "klib_nvpair.h"Functions | |
| klib_String * | klib_nvpair_tostring (klib_NVPair *self) |
| void | klib_nvpair_construct (klib_NVPair *self, const char *class_name, const char *name, klib_Object *value) |
| klib_NVPair * | klib_nvpair_new (const char *name, klib_Object *value) |
| Create a new nvpair object with the specified name and value. | |
| void | klib_nvpair_dispose (klib_NVPair *self) |
| void | klib_nvpair_set_value (klib_NVPair *pair, klib_Object *value) |
| Sets the value of of the NV pair. | |
| const char * | klib_nvpair_get_key (const klib_NVPair *pair) |
| Returns the key part of the NV pair. | |
| klib_Object * | klib_nvpair_get_value (const klib_NVPair *pair) |
| Returns the value part of the NV pair. | |
Implementation of the klib_NVPair class.
| void klib_nvpair_construct | ( | klib_NVPair * | self, |
| const char * | class_name, | ||
| const char * | name, | ||
| klib_Object * | value | ||
| ) |
{
if (klib_object_trace_flags & KLIB_OBJECT_TRACE_CONSTRUCTION)
klib_log (KLIB_LOG_TRACE, "Called constructor for NVPair\n");
klib_object_construct ((klib_Object *)self, class_name);
((klib_Object *)self)->dispose_func = (klib_Object_DisposeFunc)
klib_nvpair_dispose;
((klib_Object *)self)->tostring_func = (klib_Object_TostringFunc)
klib_nvpair_tostring;
self->priv = (klib_NVPair_priv *) malloc (sizeof (klib_NVPair_priv));
memset (self->priv, 0, sizeof (klib_NVPair_priv));
self->priv->name = strdup (name);
self->priv->value = value;
klib_object_add_ref ((klib_Object *) self->priv->value);
}
| void klib_nvpair_dispose | ( | klib_NVPair * | self | ) |
{
if (klib_object_trace_flags & KLIB_OBJECT_TRACE_CONSTRUCTION)
klib_log (KLIB_LOG_TRACE, "Called destructor for NVPair\n");
if (self->priv)
{
if (self->priv->name)
{
free (self->priv->name);
self->priv->name = NULL;
}
if (self->priv->value)
{
klib_object_unref (self->priv->value);
self->priv->value = NULL;
}
free (self->priv);
self->priv = NULL;
}
klib_object_dispose ((klib_Object *)self);
}
| const char* klib_nvpair_get_key | ( | const klib_NVPair * | pair | ) |
Returns the key part of the NV pair.
{
return pair->priv->name;
}
| klib_Object* klib_nvpair_get_value | ( | const klib_NVPair * | pair | ) |
Returns the value part of the NV pair.
Callers may modify this value, and should add a reference to it if the NV pair is likely to be free'd
{
return pair->priv->value;
}
| klib_NVPair* klib_nvpair_new | ( | const char * | name, |
| klib_Object * | object | ||
| ) |
Create a new nvpair object with the specified name and value.
The class will add its own reference to the object
{
if (klib_object_trace_flags & KLIB_OBJECT_TRACE_CONSTRUCTION)
klib_log (KLIB_LOG_TRACE, "Called new for NVPair\n");
klib_NVPair *self = (klib_NVPair *) malloc (sizeof (klib_NVPair));
memset (self, 0, sizeof (klib_NVPair));
klib_nvpair_construct (self, "NVPair", name, value);
return self;
}
| void klib_nvpair_set_value | ( | klib_NVPair * | pair, |
| klib_Object * | value | ||
| ) |
Sets the value of of the NV pair.
The previous value is unreference, and a new reference added to the supplied value
{
if (pair->priv->value)
klib_object_unref ((klib_Object *) pair->priv->value);
pair->priv->value = value;
klib_object_add_ref (pair->priv->value);
}
| klib_String* klib_nvpair_tostring | ( | klib_NVPair * | self | ) |
{
klib_String *s = klib_string_new_empty();
klib_String *ss = klib_object_tostring (self->priv->value);
klib_string_printf (s, "%s=%s\n", self->priv->name,
ss->str);
klib_object_unref ((klib_Object *)ss);
return s;
}
1.7.4