improve object default

This commit is contained in:
lixianjing 2019-09-24 14:50:39 +08:00
parent a78307488d
commit b8372b0069
2 changed files with 31 additions and 0 deletions

View File

@ -262,6 +262,23 @@ static ret_t object_default_foreach_prop(object_t* obj, tk_visit_t on_prop, void
return ret;
}
value_t* object_default_find_prop(object_t* obj, tk_compare_t cmp, const void* ctx) {
object_default_t* o = OBJECT_DEFAULT(obj);
return_value_if_fail(o != NULL && cmp != NULL, NULL);
if (o->props_size > 0) {
uint32_t i = 0;
for (i = 0; i < o->props_size; i++) {
named_value_t* iter = o->props + i;
if(cmp(iter, ctx) == 0) {
return &(iter->value);
}
}
}
return NULL;
}
static const object_vtable_t s_object_default_vtable = {
.type = "object_default",
.desc = "object_default",

View File

@ -117,6 +117,20 @@ ret_t object_default_unref(object_t* obj);
*/
ret_t object_default_clear_props(object_t* obj);
/**
* @method object_default_find_prop
*
*
*
* @param {object_t*} obj
* @param {tk_compare_t} cmp
* @param {const void*} data
*
* @return {value_t*}
*
*/
value_t* object_default_find_prop(object_t* obj, tk_compare_t cmp, const void* data);
object_default_t* object_default_cast(object_t* obj);
#define OBJECT_DEFAULT(obj) object_default_cast(obj)