127 |
static void |
static void |
128 |
pspp_dict_init (PSPP_Dict *pspp_dict) |
pspp_dict_init (PSPP_Dict *pspp_dict) |
129 |
{ |
{ |
130 |
pspp_dict->array = g_ptr_array_new(); |
pspp_dict->dict = dict_create(); |
131 |
} |
} |
132 |
|
|
133 |
/** |
/** |
152 |
g_assert(G_IS_PSPP_DICT(d)); |
g_assert(G_IS_PSPP_DICT(d)); |
153 |
|
|
154 |
/* Do nothing if it's out of bounds */ |
/* Do nothing if it's out of bounds */ |
155 |
if ( idx >= d->array->len) |
if ( idx >= dict_get_var_cnt (d->dict)) |
156 |
return; |
return; |
157 |
|
|
158 |
var = g_ptr_array_index(d->array, idx); |
var = dict_get_var(d->dict, idx); |
159 |
|
dict_delete_var (d->dict, var); |
|
g_ptr_array_remove_index(d->array, idx); |
|
|
g_free(var); |
|
160 |
|
|
161 |
g_signal_emit(d, signal[VARIABLE_DELETED], 0, idx); |
g_signal_emit(d, signal[VARIABLE_DELETED], 0, idx); |
162 |
} |
} |
169 |
g_assert(G_IS_PSPP_DICT(d)); |
g_assert(G_IS_PSPP_DICT(d)); |
170 |
|
|
171 |
|
|
172 |
if ( idx < d->array->len) |
if ( idx < dict_get_var_cnt(d->dict)) |
173 |
{ |
{ |
174 |
/* This is an existing variable? */ |
/* This is an existing variable? */ |
175 |
var = g_ptr_array_index(d->array,idx); |
var = dict_get_var(d->dict, idx); |
176 |
|
dict_rename_var(d->dict, var, name); |
177 |
} |
} |
178 |
else |
else |
179 |
{ |
{ |
180 |
/* new variable */ |
/* new variable */ |
181 |
var = g_malloc(sizeof(struct variable)); |
dict_create_var(d->dict, name, 8); |
|
g_ptr_array_add(d->array,var); |
|
182 |
} |
} |
|
strncpy(var->name,name,9); |
|
183 |
|
|
184 |
g_signal_emit(d, signal[VARIABLE_CHANGED], 0, idx); |
g_signal_emit(d, signal[VARIABLE_CHANGED], 0, idx); |
185 |
|
|
186 |
} |
} |
187 |
|
|
188 |
|
|
189 |
|
|
190 |
|
/* Return the variable indexed by IDX. |
191 |
|
returns NULL if IDX is not valid. |
192 |
|
*/ |
193 |
|
struct variable * |
194 |
|
pspp_dict_get_var(PSPP_Dict *d, gint idx) |
195 |
|
{ |
196 |
|
if (idx < 0 || idx >= pspp_dict_get_var_cnt(d)) |
197 |
|
return NULL; |
198 |
|
|
199 |
|
return dict_get_var(d->dict, idx); |
200 |
|
} |
201 |
|
|
202 |
|
/* Return the number of variables in the dictionary */ |
203 |
|
gint |
204 |
|
pspp_dict_get_var_cnt(const PSPP_Dict *d) |
205 |
|
{ |
206 |
|
return dict_get_var_cnt(d->dict); |
207 |
|
} |
208 |
|
|
209 |
|
|
210 |
|
/* Return a variable by name. |
211 |
|
Return NULL if it doesn't exist |
212 |
|
*/ |
213 |
|
struct variable * |
214 |
|
pspp_dict_lookup_var (const PSPP_Dict *d, const gchar *name) |
215 |
|
{ |
216 |
|
return dict_lookup_var(d->dict, name); |
217 |
|
} |
218 |
|
|