2
* @file geis_filterable.c
3
* @brief internal Geis filterable entities implementation
6
* Copyright 2011 Canonical Ltd.
8
* This library is free software; you can redistribute it and/or modify it under
9
* the terms of the GNU Lesser General Public License as published by the Free
10
* Software Foundation; either version 3 of the License, or (at your option) any
13
* This library is distributed in the hope that it will be useful, but WITHOUT
14
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
18
* You should have received a copy of the GNU Lesser General Public License
19
* along with this program; if not, write to the Free Software Foundation, Inc.,
20
* 51 Franklin St, Fifth Floor#include "geis_filterable.h"
22
#include "geis_config.h"
23
#include "geis_filterable.h"
25
#include "geis_logging.h"
30
* An internal struct to collect filterable attributes for facilities.
32
struct FilterableAttributeBag
34
GeisFilterableAttribute store;
41
* Constructs a new filterable attribute bag.
43
FilterableAttributeBag
44
geis_filterable_attribute_bag_new()
46
FilterableAttributeBag bag = calloc(1, sizeof(struct FilterableAttributeBag));
49
geis_error("failed to allocate filterable attribute bag");
56
bag->store = calloc(1, sizeof(struct GeisFilterableAttribute));
59
geis_error("failed to allocate filterable attribute bag store");
73
* Destroys a filterable attribute bag.
76
geis_filterable_attribute_bag_delete(FilterableAttributeBag bag)
81
for (i = 0; i < bag->count; ++i)
83
free((char *)bag->store[i].name);
92
geis_filterable_attribute_copy(GeisFilterableAttribute src,
93
GeisFilterableAttribute dst)
95
dst->name = strdup(src->name);
96
dst->type = src->type;
97
dst->add_term_callback = src->add_term_callback;
98
dst->add_term_context = src->add_term_context;
102
GeisFilterableAttributeBagIter
103
geis_filterable_attribute_bag_begin(FilterableAttributeBag bag)
106
return &bag->store[0];
107
return geis_filterable_attribute_bag_end(bag);
111
GeisFilterableAttributeBagIter
112
geis_filterable_attribute_bag_end(FilterableAttributeBag bag GEIS_UNUSED)
118
GeisFilterableAttributeBagIter
119
geis_filterable_attribute_bag_next(FilterableAttributeBag bag,
120
GeisFilterableAttributeBagIter iter)
122
if (iter < bag->store + bag->count - 1)
124
return geis_filterable_attribute_bag_end(bag);
129
geis_filterable_attribute_bag_insert(FilterableAttributeBag bag,
130
GeisFilterableAttribute fa)
132
GeisSize new_count = bag->count + 1;
133
if (new_count >= bag->size)
135
GeisSize new_size = bag->size * 2;
136
GeisSize allocation_size = new_size * sizeof(struct GeisFilterableAttribute);
137
GeisFilterableAttribute new_store = realloc(bag->store, allocation_size);
140
geis_error("failed to reallocate filterable attribute bag store");
144
bag->store = new_store;
145
bag->size = new_size;
148
geis_filterable_attribute_copy(fa, &bag->store[bag->count]);
149
bag->count = new_count;