Updated htsmsg support with a few extra support routines and corrected a mistake in the XML attrib support routine.

This commit is contained in:
Adam Sutton 2012-09-13 12:01:47 +01:00
parent e81e4f4fa1
commit c2b967fbc4
3 changed files with 48 additions and 13 deletions

View file

@ -316,6 +316,16 @@ htsmsg_get_s64(htsmsg_t *msg, const char *name, int64_t *s64p)
return 0;
}
/**
*
*/
int64_t
htsmsg_get_s64_or_default(htsmsg_t *msg, const char *name, int64_t def)
{
int64_t s64;
return htsmsg_get_s64(msg, name, &s64) ? def : s64;
}
/**
*
*/
@ -363,15 +373,13 @@ htsmsg_get_u32(htsmsg_t *msg, const char *name, uint32_t *u32p)
/**
*
*/
int
uint32_t
htsmsg_get_u32_or_default(htsmsg_t *msg, const char *name, uint32_t def)
{
uint32_t u32;
return htsmsg_get_u32(msg, name, &u32) ? def : u32;
return htsmsg_get_u32(msg, name, &u32) ? def : u32;
}
/*
*
*/
@ -449,6 +457,13 @@ htsmsg_get_str(htsmsg_t *msg, const char *name)
}
const char *
htsmsg_get_str_or_default(htsmsg_t *msg, const char *name, const char *def)
{
const char *str = htsmsg_get_str(msg, name);
return str ?: def;
}
/*
*
*/

View file

@ -160,6 +160,15 @@ void htsmsg_add_binptr(htsmsg_t *msg, const char *name, const void *bin,
*/
int htsmsg_get_u32(htsmsg_t *msg, const char *name, uint32_t *u32p);
/**
* Return the field \p name as an u32.
*
* @return An unsigned 32 bit integer or def if the field can not be found
* or if conversion is not possible.
*/
uint32_t htsmsg_get_u32_or_default
(htsmsg_t *msg, const char *name, uint32_t def);
/**
* Get an integer as an signed 32 bit integer.
*
@ -178,6 +187,16 @@ int htsmsg_get_s32(htsmsg_t *msg, const char *name, int32_t *s32p);
*/
int htsmsg_get_s64(htsmsg_t *msg, const char *name, int64_t *s64p);
/**
* Return the field \p name as an s64.
*
* @return A signed 64 bit integer or def if the field can not be found
* or if conversion is not possible.
*/
int64_t htsmsg_get_s64_or_default
(htsmsg_t *msg, const char *name, int64_t def);
/**
* Get an integer as an unsigned 64 bit integer.
*
@ -217,6 +236,15 @@ htsmsg_t *htsmsg_get_list(htsmsg_t *msg, const char *name);
*/
const char *htsmsg_get_str(htsmsg_t *msg, const char *name);
/**
* Get a field of type 'string'. No copying is done.
*
* @return def if the field can not be found or not of string type.
* Otherwise a pointer to the data is returned.
*/
const char *htsmsg_get_str_or_default
(htsmsg_t *msg, const char *name, const char *def);
/**
* Get a field of type 'map'. No copying is done.
*
@ -236,14 +264,6 @@ htsmsg_t *htsmsg_get_map_multi(htsmsg_t *msg, ...);
*/
const char *htsmsg_field_get_string(htsmsg_field_t *f);
/**
* Return the field \p name as an u32.
*
* @return An unsigned 32 bit integer or NULL if the field can not be found
* or if conversion is not possible.
*/
int htsmsg_get_u32_or_default(htsmsg_t *msg, const char *name, uint32_t def);
/**
* Remove the given field called \p name from the message \p msg.
*/

View file

@ -897,7 +897,7 @@ const char *
htsmsg_xml_get_attr_str ( htsmsg_t *tag, const char *name )
{
htsmsg_t *attr = htsmsg_get_map(tag, "attrib");
if (attr) return htsmsg_get_str(tag, name);
if (attr) return htsmsg_get_str(attr, name);
return NULL;
}