mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-11-30 02:58:26 +08:00
improve object default
This commit is contained in:
parent
a78307488d
commit
b8372b0069
@ -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",
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user