summaryrefslogtreecommitdiff
path: root/lib/item.c
blob: 1d12357662de6fab0f8409deca1e009e87e74343 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "internal.h"
#include <stdlib.h>
#include <assert.h>
#include <string.h>

struct bm_item*
bm_item_new(const char *text)
{
    struct bm_item *item;
    if (!(item = calloc(1, sizeof(struct bm_item))))
        return NULL;

    bm_item_set_text(item, text);
    return item;
}

void
bm_item_free(struct bm_item *item)
{
    assert(item);
    free(item->text);
    free(item);
}

void
bm_item_set_userdata(struct bm_item *item, void *userdata)
{
    assert(item);
    item->userdata = userdata;
}

void*
bm_item_get_userdata(struct bm_item *item)
{
    assert(item);
    return item->userdata;
}

bool
bm_item_set_text(struct bm_item *item, const char *text)
{
    assert(item);

    char *copy = NULL;
    if (text && !(copy = bm_strdup(text)))
        return false;

    free(item->text);
    item->text = copy;
    return true;
}

const char*
bm_item_get_text(const struct bm_item *item)
{
    assert(item);
    return item->text;
}

/* vim: set ts=8 sw=4 tw=0 :*/