~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pbxt/src/ccutils_xt.cc

lp:drizzle + pbxt 1.1 + test results

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2005 PrimeBase Technologies GmbH
 
2
 *
 
3
 * PrimeBase XT
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
18
 *
 
19
 * 2006-05-16   Paul McCullagh
 
20
 *
 
21
 * H&G2JCtL
 
22
 *
 
23
 * C++ Utilities
 
24
 */
 
25
 
 
26
#include "xt_config.h"
 
27
 
 
28
#include "pthread_xt.h"
 
29
#include "ccutils_xt.h"
 
30
#include "bsearch_xt.h"
 
31
 
 
32
static int ccu_compare_object(XTThreadPtr XT_UNUSED(self), register const void *XT_UNUSED(thunk), register const void *a, register const void *b)
 
33
{
 
34
        XTObject *obj_ptr = (XTObject *) b;
 
35
 
 
36
        return obj_ptr->compare(a);
 
37
}
 
38
 
 
39
void XTListImp::append(XTThreadPtr self, XTObject *info, void *key) {
 
40
        size_t idx;
 
41
 
 
42
        if (li_item_count == 0)
 
43
                idx = 0;
 
44
        else if (li_item_count == 1) {
 
45
                int r;
 
46
 
 
47
                if ((r = li_items[0]->compare(key)) == 0)
 
48
                        idx = 0;
 
49
                else if (r < 0)
 
50
                        idx = 0;
 
51
                else
 
52
                        idx = 1;
 
53
        }
 
54
        else {
 
55
                xt_bsearch(self, key, li_items, li_item_count, sizeof(void *), &idx, NULL, ccu_compare_object);
 
56
        }
 
57
 
 
58
        if (!xt_realloc(NULL, (void **) &li_items, (li_item_count + 1) * sizeof(void *))) {
 
59
                if (li_referenced)
 
60
                        info->release(self);
 
61
                xt_throw_errno(XT_CONTEXT, XT_ENOMEM);
 
62
                return;
 
63
        }
 
64
        memmove(&li_items[idx+1], &li_items[idx], (li_item_count-idx) * sizeof(void *));
 
65
        li_items[idx] = info;
 
66
        li_item_count++;
 
67
}
 
68
 
 
69