view src/prop.c @ 1224:5d731460b32c

Remove search_by_id() from frameline. - frameline is only responsible for drawing a row of frames. - layers and scenes are managed by MBScene_dom. So, function of search_by_id() must move to MBScene_dom class. - onCellClick() and _change_active_frame() are responsible for handling GUI event. - It should not be used with workaround to implement some function. - Solutions - MBScene_dom.find_layer_n_scene_of_nod() is used to replace search_by_id(). - MBScene_framelines.active_frame() is used to replace the workaround.
author Thinker K.F. Li <thinker@codemud.net>
date Thu, 06 Jan 2011 11:11:27 +0800
parents 586e50f82c1f
children
line wrap: on
line source

// -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*-
// vim: sw=4:ts=8:sts=4
#include "mb_prop.h"

#define ASSERT(x)


static
mb_prop_entry_t *_mb_prop_find(mb_prop_store_t *prop_store, int id) {
    mb_prop_entry_t *entry;

    for(entry = STAILQ_HEAD(prop_store->entries);
	entry != NULL;
	entry = STAILQ_NEXT(mb_prop_entry_t, next, entry)) {
	if(entry->id == id)
	    return entry;
    }

    return NULL;
}

void mb_prop_store_destroy(mb_prop_store_t *prop_store) {
    mb_prop_entry_t *entry, *last;

    last = STAILQ_HEAD(prop_store->entries);
    if(last == NULL)
	return;

    for(entry = STAILQ_NEXT(mb_prop_entry_t, next, last);
	entry != NULL;
	entry = STAILQ_NEXT(mb_prop_entry_t, next, entry)) {
	STAILQ_REMOVE(prop_store->entries, mb_prop_entry_t, next, last);
	elmpool_elm_free(prop_store->entry_pool, last);
	last = entry;
    }
    STAILQ_REMOVE(prop_store->entries, mb_prop_entry_t, next, last);
    elmpool_elm_free(prop_store->entry_pool, last);
}

void *mb_prop_set(mb_prop_store_t *prop_store, int id, void *value) {
    mb_prop_entry_t *entry;
    void *old;

    entry = _mb_prop_find(prop_store, id);
    if(entry) {
	old = entry->value;
	entry->value = value;
	return old;
    }

    entry = elmpool_elm_alloc(prop_store->entry_pool);
    ASSERT(entry != NULL);
    entry->id = id;
    entry->value = value;
    STAILQ_INS(prop_store->entries, mb_prop_entry_t, next, entry);

    return NULL;
}

void *mb_prop_get(mb_prop_store_t *prop_store, int id) {
    mb_prop_entry_t *entry;

    entry = _mb_prop_find(prop_store, id);
    if(entry)
	return entry->value;

    return NULL;
}

void mb_prop_del(mb_prop_store_t *prop_store, int id) {
    mb_prop_entry_t *entry;

    entry = _mb_prop_find(prop_store, id);
    if(entry)
	STAILQ_REMOVE(prop_store->entries, mb_prop_entry_t, next, entry);
}

int mb_prop_has(mb_prop_store_t *prop_store, int id) {
    mb_prop_entry_t *entry;

    entry = _mb_prop_find(prop_store, id);
    if(entry)
	return 1;

    return 0;
}