UVES Pipeline Reference Manual  5.4.0
uves_propertylist.c
1 /* $Id: uves_propertylist.c,v 1.20 2013-02-19 13:24:28 amodigli Exp $
2  *
3  * This file is part of the ESO Common Pipeline Library
4  * Copyright (C) 2001-2005 European Southern Observatory
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 /*
22  * $Author: amodigli $
23  * $Date: 2013-02-19 13:24:28 $
24  * $Revision: 1.20 $
25  * $Name: not supported by cvs2svn $
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 # include <config.h>
30 #endif
31 #include <uves_msg.h>
32 
33 #include <uves_propertylist.h>
34 #include <uves_utils_wrappers.h>
35 #include <uves_error.h>
36 
37 #ifdef USE_CPL
38 #else
39 
40 #include <uves_utils_wrappers.h>
41 #include <uves_deque.h>
42 #include <uves_dump.h>
43 #include <cpl.h>
44 
45 //#include <cxmacros.h>
46 #include <cxmemory.h>
47 #include <cxmessages.h>
48 #include <cxstrutils.h>
49 #include <cxutils.h>
50 //#include "cpl_error_impl.h"
51 //#include "cpl_propertylist_impl.h"
52 #include <qfits.h>
53 
54 #include <stdio.h>
55 #include <string.h>
56 #include <sys/types.h>
57 #include <regex.h>
58 #include <assert.h>
59 
60 
61 #include <cxdeque.h>
62 
79 enum {
80  FITS_STDKEY_MAX = 8,
81  FITS_SVALUE_MAX = 68
82 };
83 
84 
85 /*
86  * The property list type.
87  */
88 
90  uves_deque *properties;
91 };
92 
93 
94 /*
95  * Regular expresion filter type
96  */
97 
98 struct _uves_regexp_ {
99  regex_t re;
100  cxbool invert;
101 };
102 
103 typedef struct _uves_regexp_ uves_regexp;
104 
105 
106 static void
107 propertylist_append_property(uves_propertylist *plist, const cpl_property *p)
108 {
109  switch(cpl_property_get_type(p)) {
110  case CPL_TYPE_CHAR:
111  uves_propertylist_append_char(plist, cpl_property_get_name(p), cpl_property_get_char(p));
112  break;
113  case CPL_TYPE_BOOL:
114  uves_propertylist_append_bool(plist, cpl_property_get_name(p), cpl_property_get_bool(p));
115  break;
116  case CPL_TYPE_INT:
117  uves_propertylist_append_int(plist, cpl_property_get_name(p), cpl_property_get_int(p));
118  break;
119  case CPL_TYPE_LONG:
120  uves_propertylist_append_long(plist, cpl_property_get_name(p), cpl_property_get_long(p));
121  break;
122  case CPL_TYPE_FLOAT:
123  uves_propertylist_append_float(plist, cpl_property_get_name(p), cpl_property_get_float(p));
124  break;
125  case CPL_TYPE_DOUBLE:
126  uves_propertylist_append_double(plist, cpl_property_get_name(p), cpl_property_get_double(p));
127  break;
128  case CPL_TYPE_STRING:
129  uves_propertylist_append_string(plist, cpl_property_get_name(p), cpl_property_get_string(p));
130  break;
131  default:
132  cpl_msg_error(__func__,"Unknown property type: %s", uves_tostring_cpl_type(cpl_property_get_type(p)));
133  cpl_error_set(__func__, CPL_ERROR_UNSUPPORTED_MODE);
134  break;
135  }
136  /* This is constant time!! */
137  cpl_property_set_comment(uves_propertylist_get(plist, uves_propertylist_get_size(plist) - 1),
138  cpl_property_get_comment(p));
139  return;
140 }
141 
142 static void
143 propertylist_prepend_property_cpl(cpl_propertylist *plist, const cpl_property *p)
144 {
145  switch(cpl_property_get_type(p)) {
146  case CPL_TYPE_CHAR:
147  cpl_propertylist_prepend_char(plist, cpl_property_get_name(p), cpl_property_get_char(p));
148  break;
149  case CPL_TYPE_BOOL:
150  cpl_propertylist_prepend_bool(plist, cpl_property_get_name(p), cpl_property_get_bool(p));
151  break;
152  case CPL_TYPE_INT:
153  cpl_propertylist_prepend_int(plist, cpl_property_get_name(p), cpl_property_get_int(p));
154  break;
155  case CPL_TYPE_LONG:
156  cpl_propertylist_prepend_long(plist, cpl_property_get_name(p), cpl_property_get_long(p));
157  break;
158  case CPL_TYPE_FLOAT:
159  cpl_propertylist_prepend_float(plist, cpl_property_get_name(p), cpl_property_get_float(p));
160  break;
161  case CPL_TYPE_DOUBLE:
162  cpl_propertylist_prepend_double(plist, cpl_property_get_name(p), cpl_property_get_double(p));
163  break;
164  case CPL_TYPE_STRING:
165  cpl_propertylist_prepend_string(plist, cpl_property_get_name(p), cpl_property_get_string(p));
166  break;
167  default:
168  cpl_msg_error(__func__,"Unknown property type: %s", uves_tostring_cpl_type(cpl_property_get_type(p)));
169  cpl_error_set(__func__, CPL_ERROR_UNSUPPORTED_MODE);
170  break;
171  }
172  cpl_propertylist_set_comment(plist, cpl_property_get_name(p), cpl_property_get_comment(p));
173  return;
174 }
175 
176 static cpl_propertylist *
177 uves_propertylist_to_cpl(const uves_propertylist *self)
178 {
179  cpl_propertylist *result;
180  long i;
181 
182  if (self == NULL) {
183  result = NULL;
184  }
185  else {
186  result = cpl_propertylist_new();
187 
188  for (i = uves_propertylist_get_size(self)-1; i >= 0; i--) {
189  propertylist_prepend_property_cpl(
190  result,
191  uves_propertylist_get_const(self, i));
192  }
193  }
194  return result;
195 }
196 
197 static void
198 uves_propertylist_from_cpl(uves_propertylist *self, const cpl_propertylist *list_cpl)
199 {
200  long N = cpl_propertylist_get_size(list_cpl); /* O(n) */
201  cpl_propertylist *copy = cpl_propertylist_duplicate(list_cpl); /* O(n) */
202  long i;
203 
204  assert( uves_propertylist_is_empty(self));
205 
206  for (i = 0; i < N; i++) {
207  const cpl_property *p = cpl_propertylist_get(copy, 0); /* O(1) */
208  propertylist_append_property(self, p); /* O(1) */
209  cpl_propertylist_erase(copy, cpl_property_get_name(p)); /* O(1),
210  erases only first match */
211  }
212  assert( cpl_propertylist_is_empty(copy));
213  cpl_propertylist_delete(copy);
214 
215  return;
216 }
217 
218 /* Wrappers for often used functions which have cpl_propertylists in their interface */
219 cpl_error_code uves_vector_save(const cpl_vector *v, const char *f, cpl_type_bpp bpp,
220  const uves_propertylist *header, unsigned mode)
221 {
222  cpl_propertylist *header_cpl = uves_propertylist_to_cpl(header);
223  cpl_vector_save(v, f, bpp, header_cpl, mode);
224  cpl_propertylist_delete(header_cpl);
225 
226  return cpl_error_get_code();
227 }
228 cpl_error_code
229 uves_image_save(const cpl_image *image, const char *f, cpl_type_bpp bpp,
230  const uves_propertylist *header, unsigned mode)
231 {
232  cpl_propertylist *header_cpl = NULL;
233  check_nomsg(header_cpl=uves_propertylist_to_cpl(header));
234  check_nomsg(cpl_image_save(image, f, bpp, header_cpl, mode));
235  cleanup:
236  cpl_propertylist_delete(header_cpl);
237 
238  return cpl_error_get_code();
239 }
240 cpl_error_code uves_imagelist_save(const cpl_imagelist *imagelist, const char *f, cpl_type_bpp bpp,
241  const uves_propertylist *header, unsigned mode)
242 {
243  cpl_propertylist *header_cpl = uves_propertylist_to_cpl(header);
244  cpl_imagelist_save(imagelist, f, bpp, header_cpl, mode);
245  cpl_propertylist_delete(header_cpl);
246 
247  return cpl_error_get_code();
248 }
249 cpl_error_code uves_table_save(const cpl_table *table, const uves_propertylist *header,
250  const uves_propertylist *ext_header, const char *filename,
251  unsigned mode)
252 {
253  cpl_propertylist *header_cpl = uves_propertylist_to_cpl(header);
254  cpl_propertylist *ext_header_cpl = uves_propertylist_to_cpl(ext_header);
255  cpl_table_save(table, header_cpl, ext_header_cpl, filename, mode);
256  cpl_propertylist_delete(header_cpl);
257  cpl_propertylist_delete(ext_header_cpl);
258 
259  return cpl_error_get_code();
260 }
261 
262 cpl_error_code uves_dfs_setup_product_header(uves_propertylist *header,
263  const cpl_frame *product_frame,
264  const cpl_frameset *framelist,
265  const cpl_parameterlist *parlist,
266  const char *recid,
267  const char *pipeline_id,
268  const char *dictionary_id)
269 {
270  cpl_propertylist *header_cpl = uves_propertylist_to_cpl(header);
271 
272  cpl_dfs_setup_product_header(header_cpl,
273  product_frame,
274  framelist,
275  parlist,
276  recid,
277  pipeline_id,
278  dictionary_id,NULL);
279 
280  uves_propertylist_empty(header);
281  uves_propertylist_from_cpl(header, header_cpl);
282  cpl_propertylist_delete(header_cpl);
283 
284  return cpl_error_get_code();
285 }
286 
287 cpl_error_code uves_table_sort(cpl_table *t, const uves_propertylist *list)
288 {
289  /* Just use this workaround ... */
290  cpl_table_sort(t, (const cpl_propertylist*) list);
291 
292  /* ... instead of this one */
293 #if 0
294  cpl_propertylist *list_cpl = uves_propertylist_to_cpl(list);
295  cpl_table_sort(t, list_cpl);
296  cpl_propertylist_delete(list_cpl);
297 #endif
298  return cpl_error_get_code();
299 }
300 
301 
302 /*
303  * Private methods
304  */
305 
306 
307 /* Workarounds for cpl_error_push/pop which are not exported */
308 static cpl_error_code push_pop_error;
309 
310 static void error_push(void)
311 {
312  push_pop_error = cpl_error_get_code();
313  /* Don't track location */
314  cpl_error_reset();
315  return;
316 }
317 static void error_pop(void)
318 {
319  if (push_pop_error != CPL_ERROR_NONE)
320  {
321  cpl_error_set(__func__, push_pop_error);
322  }
323  return;
324 }
325 
326 
327 
328 
329 
330 
331 
332 
333 static cxint
334 _uves_propertylist_filter_regexp(cxcptr key, cxcptr filter)
335 {
336 
337  const uves_regexp *_filter = (const uves_regexp *)filter;
338 
339  if (regexec(&_filter->re, key, (size_t)0, NULL, 0) == REG_NOMATCH)
340  return _filter->invert == TRUE ? TRUE : FALSE;
341 
342  return _filter->invert == TRUE ? FALSE : TRUE;
343 
344 }
345 
346 
347 static cxbool
348 _uves_propertylist_compare(const cpl_property *property, const char *name)
349 {
350  const cxchar *key = cpl_property_get_name(property);
351 
352  return strcmp(key, name) == 0 ? TRUE : FALSE;
353 
354 }
355 
356 /* The following function is not used
357 static cxbool
358 _uves_propertylist_compare_start(const cpl_property *property,
359  const char *part_name)
360 {
361 
362  const cxchar *key = cpl_property_get_name(property);
363 
364  if (strstr(key, part_name) == key)
365  return TRUE;
366 
367  return FALSE;
368 
369 }
370 */
371 
372 static cxbool
373 _uves_propertylist_compare_regexp(const cpl_property *property, uves_regexp *re)
374 {
375 
376  const cxchar *key = cpl_property_get_name(property);
377 
378  return _uves_propertylist_filter_regexp(key, re);
379 
380 }
381 
382 
383 static uves_deque_iterator
384 _uves_propertylist_find(const uves_propertylist *self, const char *name)
385 {
386 
387  uves_deque_iterator first, last;
388  cpl_property *p;
389 
390  first = uves_deque_begin(self->properties);
391  last = uves_deque_end(self->properties);
392 
393  while (first != last) {
394  p = uves_deque_get(self->properties, first);
395 
396  if (_uves_propertylist_compare(p, name))
397  break;
398 
399  first = uves_deque_next(self->properties, first);
400  }
401 
402  return first;
403 
404 }
405 
406 static cpl_property *
407 _uves_propertylist_get(const uves_propertylist *self, const char *name)
408 {
409  uves_deque_iterator pos = _uves_propertylist_find(self, name);
410 
411  if (pos == uves_deque_end(self->properties))
412  return NULL;
413 
414  return uves_deque_get(self->properties, pos);
415 
416 }
417 
418 
419 static int
420 _uves_propertylist_insert(uves_propertylist *self, const cxchar *where,
421  cxbool after, const cxchar *name, cpl_type type,
422  cxptr value)
423 {
424 
425  uves_deque_iterator pos;
426  cpl_property *property;
427 
428 
429  /*
430  * Find the position where value should be inserted.
431  */
432 
433  pos = _uves_propertylist_find(self, where);
434 
435  if (pos == uves_deque_end(self->properties)) {
436  return 1;
437  }
438 
439  if (after) {
440  pos = uves_deque_next(self->properties, pos);
441  }
442 
443 
444  /*
445  * Create the property for value and fill it.
446  */
447 
448  property = cpl_property_new(name, type);
449  if (!property) {
450  return 1;
451  }
452 
453 
454  /*
455  * Map property type to the driver function's argument type.
456  */
457 
458  switch (type) {
459  case CPL_TYPE_CHAR:
460  cpl_property_set_char(property, *((cxchar *)value));
461  break;
462 
463  case CPL_TYPE_BOOL:
464  cpl_property_set_bool(property, *((cxint *)value));
465  break;
466 
467  case CPL_TYPE_INT:
468  cpl_property_set_int(property, *((cxint *)value));
469  break;
470 
471  case CPL_TYPE_LONG:
472  cpl_property_set_long(property, *((cxlong *)value));
473  break;
474 
475  case CPL_TYPE_FLOAT:
476  cpl_property_set_float(property, *((cxfloat *)value));
477  break;
478 
479  case CPL_TYPE_DOUBLE:
480  cpl_property_set_double(property, *((cxdouble *)value));
481  break;
482 
483  case CPL_TYPE_STRING:
484  cpl_property_set_string(property, ((const cxchar *)value));
485  break;
486 
487  default:
488  return 1;
489  break;
490  }
491 
492 
493  /*
494  * Insert it into the list
495  */
496 
497  uves_deque_insert(self->properties, pos, property);
498 
499  return 0;
500 
501 }
502 
503 /*
504  * Parser for FITS cards. Returns 0 if the card was successfully parsed
505  * into its components, 1 if the card should be ignored and a negative
506  * number if an error occurred. If the parsing was successful the function
507  * fills the buffers pointed to by key, value, comment and type.
508  *
509  * The buffers key, value and comment must, at least, have the size
510  * FITS_LINESZ + 1!
511  *
512  * Errors:
513  * -1 Invalid pointer to the input FITS header.
514  * -2 Invalid keyword name detected (cf. qfits_header_getitem())
515  */
516 
517 static cxint
518 _uves_propertylist_decode_fits(const qfits_header *header, cxint i,
519  cxchar *key, cxint *type, cxchar *value,
520  cxchar *comment)
521 {
522 
523  cxchar _key[FITS_LINESZ + 1];
524  cxchar _value[FITS_LINESZ + 1];
525  cxchar _comment[FITS_LINESZ + 1];
526  cxchar *s;
527 
528  if (!header)
529  return -1;
530 
531  /*
532  * Get a FITS card, decode it into its components and determine
533  * its type.
534  */
535 
536  if (qfits_header_getitem((qfits_header *)header, i, _key, _value,
537  _comment, NULL) != 0) {
538  return -2;
539  }
540 
541 
542  /*
543  * Skip the END record. Qfits ignores empty header cards. Therefore
544  * we do not need to take care of them here, but who knows.
545  */
546 
547  s = _key;
548 
549  if (strncmp(s, "END", 3) == 0 || strncmp(s, " ", 8) == 0 ||
550  strlen(s) == 0) {
551  return 1;
552  }
553 
554 
555  /*
556  * strip the HIERARCH prefix from the keyword name if it
557  * is present.
558  */
559 
560  if (strncmp(s, "HIERARCH ", 9) == 0)
561  s += 9;
562 
563  strncpy(key, s, FITS_LINESZ);
564  key[FITS_LINESZ] = '\0';
565 
566 
567  /*
568  * Parse the value string and determine its type. Comment and
569  * history records are forced to be strings. The type check
570  * has to be done before cleaning the value, so that strings
571  * like '1.0' are still recognized as such.
572  */
573 
574  s = _value;
575 
576  if (strncmp(_key, "COMMENT", 7) == 0 || strncmp(_key, "HISTORY", 7) == 0) {
577  *type = QFITS_STRING;
578 
579  /*
580  * qfits returns an empty string if there is no value for a keyword
581  */
582 
583  if (strlen(s) == 0) {
584  value[0] = '\0';
585  }
586  else {
587  strncpy(value, s, FITS_LINESZ);
588  }
589  }
590  else {
591  *type = qfits_get_type(s);
592  strncpy(value, qfits_pretty_string(s), FITS_LINESZ);
593  value[FITS_LINESZ] = '\0';
594  }
595 
596 
597  /*
598  * Parse the comment
599  */
600 
601  s = _comment;
602 
603  /*
604  * qfits returns an empty string if there is no value for a keyword
605  */
606 
607  if (strlen(s) == 0)
608  comment[0] = '\0';
609  else {
610  strncpy(comment, s, FITS_LINESZ);
611  comment[FITS_LINESZ] = '\0';
612  }
613 
614  return 0;
615 
616 }
617 
618 
619 
620 
621 /*
622  * The function converts a FITS header to a property list ignoring
623  * keywords for which _uves_propertylist_decode_fits() returns 1. If
624  * parsing a FITS keyword fails the function returns the status from
625  * _uves_propertylist_decode_fits(). If the type of a FITS keyword is not
626  * supported -1 is returned.
627  */
628 
629 static cxint
630 _uves_propertylist_from_fits(uves_propertylist *self,
631  const qfits_header *header,
632  cx_compare_func filter,
633  cxcptr data)
634 {
635 
636  register cxint i;
637 
638 
639  cx_assert(self != NULL);
640  cx_assert(header != NULL);
641 
642 
643  /*
644  * Build the property list from the header.
645  */
646 
647  for (i = 0; i < header->n; i++) {
648  register cxint status;
649 
650  cxint type;
651  cxint ival;
652 
653  cxdouble dval;
654 
655  cxchar key[FITS_LINESZ + 1];
656  cxchar value[FITS_LINESZ + 1];
657  cxchar comment[FITS_LINESZ + 1];
658 
659  cpl_property *property;
660 
661 
662  status = _uves_propertylist_decode_fits(header, i, key, &type,
663  value, comment);
664 
665  if (status) {
666  switch (status) {
667  case 1:
668  continue;
669  break;
670 
671  default:
672  return status;
673  break;
674  }
675  }
676 
677 
678  if (filter != NULL && filter(key, data) == FALSE) {
679  continue;
680  }
681 
682 
683  /*
684  * Create the property from the parsed FITS card.
685  */
686 
687  switch (type) {
688  case QFITS_BOOLEAN:
689  property = cpl_property_new(key, CPL_TYPE_BOOL);
690 
691  ival = *value == 'T' ? 1 : 0;
692  cpl_property_set_bool(property, ival);
693  cpl_property_set_comment(property, comment);
694  break;
695 
696  case QFITS_INT:
697  property = cpl_property_new(key, CPL_TYPE_INT);
698 
699  sscanf(value, "%d", &ival);
700  cpl_property_set_int(property, ival);
701  cpl_property_set_comment(property, comment);
702  break;
703 
704  case QFITS_FLOAT:
705  property = cpl_property_new(key, CPL_TYPE_DOUBLE);
706 
707  sscanf(value, "%lf", &dval);
708  cpl_property_set_double(property, dval);
709  cpl_property_set_comment(property, comment);
710  break;
711 
712  /* FIXME: qfits does not correctly report the type for
713  * string values if the single quotes have been
714  * stripped. In this case it reports QFITS_UNKNOWN
715  * for the value's type. As a temporary (!) work
716  * around we accept everything unknown as a string.
717  */
718 
719  case QFITS_UNKNOWN:
720  case QFITS_STRING:
721  property = cpl_property_new(key, CPL_TYPE_STRING);
722 
723  cpl_property_set_string(property, value);
724  cpl_property_set_comment(property, comment);
725  break;
726 
727  case QFITS_COMPLEX:
728 
729  /* FIXME: Add support for complex keywords. */
730 
731  default:
732  return 1;
733  break;
734  }
735 
736  uves_deque_push_back(self->properties, property);
737  }
738 
739  return 0;
740 
741 }
742 
743 
744 
745 /*
746  * Public methods
747  */
748 
765 {
766 
767  uves_propertylist *self = cx_malloc(sizeof *self);
768 
769  self->properties = uves_deque_new();
770  return self;
771 
772 }
773 
774 
802 {
803 
804  const cxchar *const _id = "uves_propertylist_duplicate";
805 
806  uves_deque_iterator first, last;
807 
808  uves_propertylist *copy = NULL;
809 
810 
811  if (self == NULL) {
812  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
813  return NULL;
814  }
815 
816  cx_assert(self->properties != NULL);
817 
818 
819  copy = uves_propertylist_new();
820 
821  first = uves_deque_begin(self->properties);
822  last = uves_deque_end(self->properties);
823 
824  while (first != last) {
825  cpl_property *tmp = uves_deque_get(self->properties, first);
826 
827  uves_deque_push_back(copy->properties, cpl_property_duplicate(tmp));
828  first = uves_deque_next(self->properties, first);
829  }
830 
831  return copy;
832 
833 }
834 
835 
849 void
851 {
852 
853  if (self) {
854  uves_deque_destroy(self->properties, (cx_free_func)cpl_property_delete);
855  cx_free((void *)self);
856  }
857 
858  return;
859 
860 }
861 
862 
889 long
891 {
892 
893  const cxchar *const _id = "uves_propertylist_get_size";
894 
895 
896  if (self == NULL) {
897  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
898  return 0L;
899  }
900 
901  return (long) uves_deque_size(self->properties);
902 
903 }
904 
905 
931 int
933 {
934 
935  const cxchar *const _id = "uves_propertylist_is_empty";
936 
937 
938  if (self == NULL) {
939  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
940  return -1;
941  }
942 
943  return uves_deque_empty(self->properties);
944 
945 }
946 
947 
982 cpl_type
983 uves_propertylist_get_type(const uves_propertylist *self, const char *name)
984 {
985 
986  const cxchar *const _id = "uves_propertylist_get_type";
987 
988  cpl_property *property;
989 
990 
991  if (self == NULL || name == NULL) {
992  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
993  return CPL_TYPE_INVALID;
994  }
995 
996  property = _uves_propertylist_get(self, name);
997 
998  if (property == NULL) {
999  cpl_error_set(_id, CPL_ERROR_DATA_NOT_FOUND);
1000  return CPL_TYPE_INVALID;
1001  }
1002 
1003  return cpl_property_get_type(property);
1004 
1005 }
1006 
1007 
1036 int
1037 uves_propertylist_contains(const uves_propertylist *self, const char *name)
1038 {
1039 
1040  const cxchar *const _id = "uves_propertylist_contains";
1041 
1042 
1043  if (self == NULL || name == NULL) {
1044  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
1045  return 0;
1046  }
1047 
1048  return _uves_propertylist_get(self, name) != NULL ? 1 : 0;
1049 
1050 }
1051 
1052 
1053 
1054 
1055 
1084 int
1085 my_uves_propertylist_contains(const cpl_propertylist *self, const char *name)
1086 {
1087 
1088  const cxchar *const _id = "my_uves_propertylist_contains";
1089 
1090 
1091  if (self == NULL || name == NULL) {
1092  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
1093  return 0;
1094  }
1095 
1096  return cpl_propertylist_has(self, name);
1097 
1098 }
1099 
1100 
1101 
1102 
1103 
1104 
1105 
1106 
1144 cpl_error_code
1146  const char *comment)
1147 {
1148 
1149  const cxchar *const _id = "uves_propertylist_set_comment";
1150 
1151  cpl_property *property;
1152 
1153 
1154  if (self == NULL || name == NULL) {
1155  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
1156  return CPL_ERROR_NULL_INPUT;
1157  }
1158 
1159  property = _uves_propertylist_get(self, name);
1160 
1161  if (property == NULL) {
1162  cpl_error_set(_id, CPL_ERROR_DATA_NOT_FOUND);
1163  return CPL_ERROR_DATA_NOT_FOUND;
1164  }
1165 
1166  cpl_property_set_comment(property, comment);
1167 
1168  return CPL_ERROR_NONE;
1169 
1170 }
1171 
1172 
1209 cpl_error_code
1211  char value)
1212 {
1213 
1214  const cxchar *const _id = "uves_propertylist_set_char";
1215 
1216  cpl_property *property;
1217 
1218 
1219  if (self == NULL || name == NULL) {
1220  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
1221  return CPL_ERROR_NULL_INPUT;
1222  }
1223 
1224  property = _uves_propertylist_get(self, name);
1225 
1226  if (property == NULL) {
1227  cpl_error_set(_id, CPL_ERROR_DATA_NOT_FOUND);
1228  return CPL_ERROR_DATA_NOT_FOUND;
1229  }
1230 
1231  return cpl_property_set_char(property, value);
1232 
1233 }
1234 
1235 
1272 cpl_error_code
1273 uves_propertylist_set_bool(uves_propertylist *self, const char *name, int value)
1274 {
1275 
1276  const cxchar *const _id = "uves_propertylist_set_bool";
1277 
1278  cpl_property *property;
1279 
1280 
1281  if (self == NULL || name == NULL) {
1282  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
1283  return CPL_ERROR_NULL_INPUT;
1284  }
1285 
1286  property = _uves_propertylist_get(self, name);
1287 
1288  if (property == NULL) {
1289  cpl_error_set(_id, CPL_ERROR_DATA_NOT_FOUND);
1290  return CPL_ERROR_DATA_NOT_FOUND;
1291  }
1292 
1293  return cpl_property_set_bool(property, value);
1294 
1295 }
1296 
1297 
1334 cpl_error_code
1335 uves_propertylist_set_int(uves_propertylist *self, const char *name, int value)
1336 {
1337 
1338  const cxchar *const _id = "uves_propertylist_set_int";
1339 
1340  cpl_property *property;
1341 
1342 
1343  if (self == NULL || name == NULL) {
1344  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
1345  return CPL_ERROR_NULL_INPUT;
1346  }
1347 
1348  property = _uves_propertylist_get(self, name);
1349 
1350  if (property == NULL) {
1351  cpl_error_set(_id, CPL_ERROR_DATA_NOT_FOUND);
1352  return CPL_ERROR_DATA_NOT_FOUND;
1353  }
1354 
1355  return cpl_property_set_int(property, value);
1356 
1357 }
1358 
1359 
1396 cpl_error_code
1398  long value)
1399 {
1400 
1401  const cxchar *const _id = "uves_propertylist_set_long";
1402 
1403  cpl_property *property;
1404 
1405 
1406  if (self == NULL || name == NULL) {
1407  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
1408  return CPL_ERROR_NULL_INPUT;
1409  }
1410 
1411  property = _uves_propertylist_get(self, name);
1412 
1413  if (property == NULL) {
1414  cpl_error_set(_id, CPL_ERROR_DATA_NOT_FOUND);
1415  return CPL_ERROR_DATA_NOT_FOUND;
1416  }
1417 
1418  return cpl_property_set_long(property, value);
1419 
1420 }
1421 
1422 
1459 cpl_error_code
1461  float value)
1462 {
1463 
1464  const cxchar *const _id = "uves_propertylist_set_float";
1465 
1466  cpl_property *property;
1467 
1468 
1469  if (self == NULL || name == NULL) {
1470  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
1471  return CPL_ERROR_NULL_INPUT;
1472  }
1473 
1474  property = _uves_propertylist_get(self, name);
1475 
1476  if (property == NULL) {
1477  cpl_error_set(_id, CPL_ERROR_DATA_NOT_FOUND);
1478  return CPL_ERROR_DATA_NOT_FOUND;
1479  }
1480 
1481  return cpl_property_set_float(property, value);
1482 
1483 }
1484 
1485 
1522 cpl_error_code
1524  double value)
1525 {
1526 
1527  const cxchar *const _id = "uves_propertylist_set_double";
1528 
1529  cpl_property *property;
1530 
1531 
1532  if (self == NULL || name == NULL) {
1533  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
1534  return CPL_ERROR_NULL_INPUT;
1535  }
1536 
1537  property = _uves_propertylist_get(self, name);
1538 
1539  if (property == NULL) {
1540  cpl_error_set(_id, CPL_ERROR_DATA_NOT_FOUND);
1541  return CPL_ERROR_DATA_NOT_FOUND;
1542  }
1543 
1544  return cpl_property_set_double(property, value);
1545 
1546 }
1547 
1548 
1585 cpl_error_code
1587  const char *value)
1588 {
1589 
1590  const cxchar *const _id = "uves_propertylist_set_string";
1591 
1592  cpl_property *property;
1593 
1594 
1595  if (self == NULL || name == NULL) {
1596  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
1597  return CPL_ERROR_NULL_INPUT;
1598  }
1599 
1600  property = _uves_propertylist_get(self, name);
1601 
1602  if (property == NULL) {
1603  cpl_error_set(_id, CPL_ERROR_DATA_NOT_FOUND);
1604  return CPL_ERROR_DATA_NOT_FOUND;
1605  }
1606 
1607  return cpl_property_set_string(property, value);
1608 
1609 }
1610 
1611 
1641 const cpl_property *
1643 {
1644 
1645  const cxchar *const _id = "uves_propertylist_get";
1646 
1647 // register cxsize i = 0;
1648 
1649  uves_deque_iterator first, last;
1650 
1651 
1652  if (self == NULL) {
1653  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
1654  return NULL;
1655  }
1656 
1657  if (position < 0) {
1658  return NULL;
1659  }
1660 
1661  first = uves_deque_begin(self->properties);
1662  last = uves_deque_end(self->properties);
1663 
1664 // while (i < (cxsize)position && first != last) {
1665 // first = uves_deque_next(self->properties, first);
1666 // i++;
1667 // }
1668 
1669  if (first == last) {
1670  return NULL;
1671  }
1672 
1673 // return uves_deque_get(self->properties, first);
1674  return uves_deque_get(self->properties, position);
1675 
1676 }
1677 
1678 cpl_property *
1679 uves_propertylist_get(uves_propertylist *self, long position)
1680 {
1681  return (cpl_property *)uves_propertylist_get_const(self, position);
1682 }
1683 
1684 
1720 const char *
1721 uves_propertylist_get_comment(const uves_propertylist *self, const char *name)
1722 {
1723 
1724  const cxchar *const _id = "uves_propertylist_get_comment";
1725 
1726  cpl_property *property;
1727 
1728 
1729  if (self == NULL || name == NULL) {
1730  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
1731  return NULL;
1732  }
1733 
1734  property = _uves_propertylist_get(self, name);
1735 
1736  if (!property) {
1737  cpl_error_set(_id, CPL_ERROR_DATA_NOT_FOUND);
1738  return NULL;
1739  }
1740 
1741  return cpl_property_get_comment(property);
1742 
1743 }
1744 
1745 
1787 char
1788 uves_propertylist_get_char(const uves_propertylist *self, const char *name)
1789 {
1790 
1791  const cxchar *const _id = "uves_propertylist_get_char";
1792 
1793  cxchar result;
1794 
1795  cpl_property *property;
1796 
1797 
1798  if (self == NULL || name == NULL) {
1799  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
1800  return '\0';
1801  }
1802 
1803  property = _uves_propertylist_get(self, name);
1804 
1805  if (!property) {
1806  cpl_error_set(_id, CPL_ERROR_DATA_NOT_FOUND);
1807  return '\0';
1808  }
1809 
1810  error_push();
1811 //jmlarsen: this is not exported cpl_error_push();
1812 
1813  result = cpl_property_get_char(property);
1814 
1815  /*
1816  * If an error occurred change any possibly set location to this
1817  * function.
1818  */
1819 
1820  if (cpl_error_get_code() != CPL_ERROR_NONE) {
1821  cpl_error_set_where(_id);
1822  return '\0';
1823  }
1824 
1825 //jmlarsen: this is not exported cpl_error_pop();
1826  error_pop();
1827 
1828  return result;
1829 
1830 }
1831 
1832 
1876 int
1877 uves_propertylist_get_bool(const uves_propertylist *self, const char *name)
1878 {
1879 
1880  const cxchar *const _id = "uves_propertylist_get_bool";
1881 
1882  cxbool result;
1883 
1884  cpl_property *property;
1885 
1886 
1887  if (self == NULL || name == NULL) {
1888  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
1889  return 0;
1890  }
1891 
1892  property = _uves_propertylist_get(self, name);
1893 
1894  if (!property) {
1895  cpl_error_set(_id, CPL_ERROR_DATA_NOT_FOUND);
1896  return 0;
1897  }
1898 
1899  error_push();
1900 //jmlarsen: this is not exported cpl_error_push();
1901 
1902  result = cpl_property_get_bool(property);
1903 
1904  /*
1905  * If an error occurred change any possibly set location to this
1906  * function.
1907  */
1908 
1909  if (cpl_error_get_code() != CPL_ERROR_NONE) {
1910  cpl_error_set_where(_id);
1911  return 0;
1912  }
1913 
1914 //jmlarsen: this is not exported cpl_error_pop();
1915  error_pop();
1916 
1917  return result == TRUE ? 1 : 0;
1918 
1919 }
1920 
1921 
1963 int
1964 uves_propertylist_get_int(const uves_propertylist *self, const char *name)
1965 {
1966 
1967  const cxchar *const _id = "uves_propertylist_get_int";
1968 
1969  cxint result;
1970 
1971  cpl_property *property;
1972 
1973 
1974  if (self == NULL || name == NULL) {
1975  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
1976  return 0;
1977  }
1978 
1979  property = _uves_propertylist_get(self, name);
1980 
1981  if (!property) {
1982  cpl_error_set(_id, CPL_ERROR_DATA_NOT_FOUND);
1983  return 0;
1984  }
1985 
1986  error_push();
1987 //jmlarsen: this is not exported cpl_error_push();
1988 
1989  result = cpl_property_get_int(property);
1990 
1991  /*
1992  * If an error occurred change any possibly set location to this
1993  * function.
1994  */
1995 
1996  if (cpl_error_get_code() != CPL_ERROR_NONE) {
1997  cpl_error_set_where(_id);
1998  return 0;
1999  }
2000 
2001 //jmlarsen: this is not exported cpl_error_pop();
2002  error_pop();
2003 
2004  return result;
2005 
2006 }
2007 
2008 
2050 long
2051 uves_propertylist_get_long(const uves_propertylist *self, const char *name)
2052 {
2053 
2054  const cxchar *const _id = "uves_propertylist_get_long";
2055 
2056  cxlong result;
2057 
2058  cpl_property *property;
2059 
2060 
2061  if (self == NULL || name == NULL) {
2062  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
2063  return 0;
2064  }
2065 
2066  property = _uves_propertylist_get(self, name);
2067 
2068  if (!property) {
2069  cpl_error_set(_id, CPL_ERROR_DATA_NOT_FOUND);
2070  return 0;
2071  }
2072 
2073  error_push();
2074 //jmlarsen: this is not exported cpl_error_push();
2075 
2076  result = cpl_property_get_long(property);
2077 
2078  /*
2079  * If an error occurred change any possibly set location to this
2080  * function.
2081  */
2082 
2083  if (cpl_error_get_code() != CPL_ERROR_NONE) {
2084  cpl_error_set_where(_id);
2085  return 0;
2086  }
2087 
2088 //jmlarsen: this is not exported cpl_error_pop();
2089  error_pop();
2090 
2091  return result;
2092 
2093 }
2094 
2095 
2137 float
2138 uves_propertylist_get_float(const uves_propertylist *self, const char *name)
2139 {
2140 
2141  const cxchar *const _id = "uves_propertylist_get_float";
2142 
2143  cxfloat result;
2144 
2145  cpl_property *property;
2146 
2147 
2148  if (self == NULL || name == NULL) {
2149  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
2150  return 0;
2151  }
2152 
2153  property = _uves_propertylist_get(self, name);
2154 
2155  if (!property) {
2156  cpl_error_set(_id, CPL_ERROR_DATA_NOT_FOUND);
2157  return 0;
2158  }
2159 
2160  error_push();
2161 //jmlarsen: this is not exported cpl_error_push();
2162 
2163  result = cpl_property_get_float(property);
2164 
2165  /*
2166  * If an error occurred change any possibly set location to this
2167  * function.
2168  */
2169 
2170  if (cpl_error_get_code() != CPL_ERROR_NONE) {
2171  cpl_error_set_where(_id);
2172  return 0;
2173  }
2174 
2175 //jmlarsen: this is not exported cpl_error_pop();
2176  error_pop();
2177 
2178  return result;
2179 
2180 }
2181 
2182 
2224 double
2225 uves_propertylist_get_double(const uves_propertylist *self, const char *name)
2226 {
2227 
2228  const cxchar *const _id = "uves_propertylist_get_double";
2229 
2230  cxdouble result;
2231 
2232  cpl_property *property;
2233 
2234 
2235  if (self == NULL || name == NULL) {
2236  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
2237  return 0;
2238  }
2239 
2240  property = _uves_propertylist_get(self, name);
2241 
2242  if (!property) {
2243  cpl_error_set(_id, CPL_ERROR_DATA_NOT_FOUND);
2244  return 0;
2245  }
2246 
2247  error_push();
2248 //jmlarsen: this is not exported cpl_error_push();
2249 
2250  result = cpl_property_get_double(property);
2251 
2252  /*
2253  * If an error occurred change any possibly set location to this
2254  * function.
2255  */
2256 
2257  if (cpl_error_get_code() != CPL_ERROR_NONE) {
2258  cpl_error_set_where(_id);
2259  return 0;
2260  }
2261 
2262 //jmlarsen: this is not exported cpl_error_pop();
2263  error_pop();
2264 
2265  return result;
2266 
2267 }
2268 
2269 
2313 const char *
2314 uves_propertylist_get_string(const uves_propertylist *self, const char *name)
2315 {
2316 
2317  const cxchar *const _id = "uves_propertylist_get_string";
2318 
2319  const cxchar *result;
2320 
2321  cpl_property *property;
2322 
2323 
2324  if (self == NULL || name == NULL) {
2325  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
2326  return NULL;
2327  }
2328 
2329  property = _uves_propertylist_get(self, name);
2330 
2331  if (!property) {
2332  cpl_error_set(_id, CPL_ERROR_DATA_NOT_FOUND);
2333  return NULL;
2334  }
2335 
2336  error_push();
2337 //jmlarsen: this is not exported cpl_error_push();
2338 
2339  result = cpl_property_get_string(property);
2340 
2341  /*
2342  * If an error occurred change any possibly set location to this
2343  * function.
2344  */
2345 
2346  if (cpl_error_get_code() != CPL_ERROR_NONE) {
2347  cpl_error_set_where(_id);
2348  return NULL;
2349  }
2350 
2351 //jmlarsen: this is not exported cpl_error_pop();
2352  error_pop();
2353 
2354  return result;
2355 
2356 }
2357 
2358 
2396 cpl_error_code
2398  const char *name, char value)
2399 {
2400 
2401  const cxchar *const _id = "uves_propertylist_insert_char";
2402 
2403  cxint status = 0;
2404 
2405 
2406  if (self == NULL || here == NULL || name == NULL) {
2407  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
2408  return CPL_ERROR_NULL_INPUT;
2409  }
2410 
2411  status = _uves_propertylist_insert(self, here, FALSE, name,
2412  CPL_TYPE_CHAR, &value);
2413 
2414  if (status) {
2415  cpl_error_set(_id, CPL_ERROR_UNSPECIFIED);
2416  return CPL_ERROR_UNSPECIFIED;
2417  }
2418 
2419  return CPL_ERROR_NONE;
2420 
2421 }
2422 
2423 
2461 cpl_error_code
2463  const char *name, int value)
2464 {
2465 
2466  const cxchar *const _id = "uves_propertylist_insert_bool";
2467 
2468  cxint status = 0;
2469 
2470 
2471  if (self == NULL || here == NULL || name == NULL) {
2472  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
2473  return CPL_ERROR_NULL_INPUT;
2474  }
2475 
2476  status = _uves_propertylist_insert(self, here, FALSE, name,
2477  CPL_TYPE_BOOL, &value);
2478 
2479  if (status) {
2480  cpl_error_set(_id, CPL_ERROR_UNSPECIFIED);
2481  return CPL_ERROR_UNSPECIFIED;
2482  }
2483 
2484  return CPL_ERROR_NONE;
2485 
2486 }
2487 
2488 
2526 cpl_error_code
2528  const char *name, int value)
2529 {
2530 
2531  const cxchar *const _id = "uves_propertylist_insert_int";
2532 
2533  cxint status = 0;
2534 
2535 
2536  if (self == NULL || here == NULL || name == NULL) {
2537  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
2538  return CPL_ERROR_NULL_INPUT;
2539  }
2540 
2541  status = _uves_propertylist_insert(self, here, FALSE, name,
2542  CPL_TYPE_INT, &value);
2543 
2544  if (status) {
2545  cpl_error_set(_id, CPL_ERROR_UNSPECIFIED);
2546  return CPL_ERROR_UNSPECIFIED;
2547  }
2548 
2549  return CPL_ERROR_NONE;
2550 
2551 }
2580 int
2581 uves_propertylist_has(const uves_propertylist *self, const char *name)
2582 {
2583 
2584  const cxchar *const _id = "cpl_propertylist_has";
2585 
2586 
2587  if (self == NULL || name == NULL) {
2588  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
2589  return 0;
2590  }
2591 
2592  return _uves_propertylist_get(self, name) != NULL ? 1 : 0;
2593 
2594 }
2595 
2596 
2634 cpl_error_code
2636  const char *name, long value)
2637 {
2638 
2639  const cxchar *const _id = "uves_propertylist_insert_long";
2640 
2641  cxint status = 0;
2642 
2643 
2644  if (self == NULL || here == NULL || name == NULL) {
2645  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
2646  return CPL_ERROR_NULL_INPUT;
2647  }
2648 
2649  status = _uves_propertylist_insert(self, here, FALSE, name,
2650  CPL_TYPE_LONG, &value);
2651 
2652  if (status) {
2653  cpl_error_set(_id, CPL_ERROR_UNSPECIFIED);
2654  return CPL_ERROR_UNSPECIFIED;
2655  }
2656 
2657  return CPL_ERROR_NONE;
2658 
2659 }
2660 
2661 
2699 cpl_error_code
2701  const char *name, float value)
2702 {
2703 
2704  const cxchar *const _id = "uves_propertylist_insert_float";
2705 
2706  cxint status = 0;
2707 
2708 
2709  if (self == NULL || here == NULL || name == NULL) {
2710  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
2711  return CPL_ERROR_NULL_INPUT;
2712  }
2713 
2714  status = _uves_propertylist_insert(self, here, FALSE, name,
2715  CPL_TYPE_FLOAT, &value);
2716 
2717  if (status) {
2718  cpl_error_set(_id, CPL_ERROR_UNSPECIFIED);
2719  return CPL_ERROR_UNSPECIFIED;
2720  }
2721 
2722  return CPL_ERROR_NONE;
2723 
2724 }
2725 
2726 
2764 cpl_error_code
2766  const char *name, double value)
2767 {
2768 
2769  const cxchar *const _id = "uves_propertylist_insert_char";
2770 
2771  cxint status = 0;
2772 
2773 
2774  if (self == NULL || here == NULL || name == NULL) {
2775  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
2776  return CPL_ERROR_NULL_INPUT;
2777  }
2778 
2779  status = _uves_propertylist_insert(self, here, FALSE, name,
2780  CPL_TYPE_DOUBLE, &value);
2781 
2782  if (status) {
2783  cpl_error_set(_id, CPL_ERROR_UNSPECIFIED);
2784  return CPL_ERROR_UNSPECIFIED;
2785  }
2786 
2787  return CPL_ERROR_NONE;
2788 
2789 }
2790 
2791 
2829 cpl_error_code
2831  const char *name, const char *value)
2832 {
2833 
2834  const cxchar *const _id = "uves_propertylist_insert_string";
2835 
2836  cxint status = 0;
2837 
2838 
2839  if (self == NULL || here == NULL || name == NULL) {
2840  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
2841  return CPL_ERROR_NULL_INPUT;
2842  }
2843 
2844  status = _uves_propertylist_insert(self, here, FALSE, name,
2845  CPL_TYPE_STRING, (cxptr)value);
2846 
2847  if (status) {
2848  cpl_error_set(_id, CPL_ERROR_UNSPECIFIED);
2849  return CPL_ERROR_UNSPECIFIED;
2850  }
2851 
2852  return CPL_ERROR_NONE;
2853 
2854 }
2855 
2856 
2894 cpl_error_code
2896  const char *name, char value)
2897 {
2898 
2899  const cxchar *const _id = "uves_propertylist_insert_after_char";
2900 
2901  cxint status = 0;
2902 
2903 
2904  if (self == NULL || after == NULL || name == NULL) {
2905  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
2906  return CPL_ERROR_NULL_INPUT;
2907  }
2908 
2909  status = _uves_propertylist_insert(self, after, TRUE, name,
2910  CPL_TYPE_CHAR, &value);
2911 
2912  if (status) {
2913  cpl_error_set(_id, CPL_ERROR_UNSPECIFIED);
2914  return CPL_ERROR_UNSPECIFIED;
2915  }
2916 
2917  return CPL_ERROR_NONE;
2918 
2919 }
2920 
2921 
2959 cpl_error_code
2961  const char *name, int value)
2962 {
2963 
2964  const cxchar *const _id = "uves_propertylist_insert_after_bool";
2965 
2966  cxint status = 0;
2967 
2968 
2969  if (self == NULL || after == NULL || name == NULL) {
2970  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
2971  return CPL_ERROR_NULL_INPUT;
2972  }
2973 
2974  status = _uves_propertylist_insert(self, after, TRUE, name,
2975  CPL_TYPE_BOOL, &value);
2976 
2977  if (status) {
2978  cpl_error_set(_id, CPL_ERROR_UNSPECIFIED);
2979  return CPL_ERROR_UNSPECIFIED;
2980  }
2981 
2982  return CPL_ERROR_NONE;
2983 
2984 }
2985 
2986 
3024 cpl_error_code
3026  const char *name, int value)
3027 {
3028 
3029  const cxchar *const _id = "uves_propertylist_insert_after_int";
3030 
3031  cxint status = 0;
3032 
3033 
3034  if (self == NULL || after == NULL || name == NULL) {
3035  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
3036  return CPL_ERROR_NULL_INPUT;
3037  }
3038 
3039  status = _uves_propertylist_insert(self, after, TRUE, name,
3040  CPL_TYPE_INT, &value);
3041 
3042  if (status) {
3043  cpl_error_set(_id, CPL_ERROR_UNSPECIFIED);
3044  return CPL_ERROR_UNSPECIFIED;
3045  }
3046 
3047  return CPL_ERROR_NONE;
3048 
3049 }
3050 
3051 
3089 cpl_error_code
3091  const char *name, long value)
3092 {
3093 
3094  const cxchar *const _id = "uves_propertylist_insert_after_long";
3095 
3096  cxint status = 0;
3097 
3098 
3099  if (self == NULL || after == NULL || name == NULL) {
3100  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
3101  return CPL_ERROR_NULL_INPUT;
3102  }
3103 
3104  status = _uves_propertylist_insert(self, after, TRUE, name,
3105  CPL_TYPE_LONG, &value);
3106 
3107  if (status) {
3108  cpl_error_set(_id, CPL_ERROR_UNSPECIFIED);
3109  return CPL_ERROR_UNSPECIFIED;
3110  }
3111 
3112  return CPL_ERROR_NONE;
3113 
3114 }
3115 
3116 
3154 cpl_error_code
3156  const char *name, float value)
3157 {
3158 
3159  const cxchar *const _id = "uves_propertylist_insert_after_float";
3160 
3161  cxint status = 0;
3162 
3163 
3164  if (self == NULL || after == NULL || name == NULL) {
3165  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
3166  return CPL_ERROR_NULL_INPUT;
3167  }
3168 
3169  status = _uves_propertylist_insert(self, after, TRUE, name,
3170  CPL_TYPE_FLOAT, &value);
3171 
3172  if (status) {
3173  cpl_error_set(_id, CPL_ERROR_UNSPECIFIED);
3174  return CPL_ERROR_UNSPECIFIED;
3175  }
3176 
3177  return CPL_ERROR_NONE;
3178 
3179 }
3180 
3181 
3219 cpl_error_code
3221  const char *after, const char *name,
3222  double value)
3223 {
3224 
3225  const cxchar *const _id = "uves_propertylist_insert_after_double";
3226 
3227  cxint status = 0;
3228 
3229 
3230  if (self == NULL || after == NULL || name == NULL) {
3231  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
3232  return CPL_ERROR_NULL_INPUT;
3233  }
3234 
3235  status = _uves_propertylist_insert(self, after, TRUE, name,
3236  CPL_TYPE_DOUBLE, &value);
3237 
3238  if (status) {
3239  cpl_error_set(_id, CPL_ERROR_UNSPECIFIED);
3240  return CPL_ERROR_UNSPECIFIED;
3241  }
3242 
3243  return CPL_ERROR_NONE;
3244 
3245 }
3246 
3247 
3285 cpl_error_code
3287  const char *after, const char *name,
3288  const char *value)
3289 {
3290 
3291  const cxchar *const _id = "uves_propertylist_insert_after_string";
3292 
3293  cxint status = 0;
3294 
3295 
3296  if (self == NULL || after == NULL || name == NULL) {
3297  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
3298  return CPL_ERROR_NULL_INPUT;
3299  }
3300 
3301  status = _uves_propertylist_insert(self, after, TRUE, name,
3302  CPL_TYPE_STRING, (cxptr)value);
3303 
3304  if (status) {
3305  cpl_error_set(_id, CPL_ERROR_UNSPECIFIED);
3306  return CPL_ERROR_UNSPECIFIED;
3307  }
3308 
3309  return CPL_ERROR_NONE;
3310 
3311 }
3312 
3313 
3342 cpl_error_code
3344  char value)
3345 {
3346 
3347  const cxchar *const _id = "uves_propertylist_prepend_char";
3348 
3349  cpl_property *property = NULL;
3350 
3351 
3352  if (self == NULL || name == NULL) {
3353  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
3354  return CPL_ERROR_NULL_INPUT;
3355  }
3356 
3357  property = cpl_property_new(name, CPL_TYPE_CHAR);
3358  cx_assert(property != NULL);
3359 
3360  cpl_property_set_char(property, value);
3361  uves_deque_push_front(self->properties, property);
3362 
3363  return CPL_ERROR_NONE;
3364 
3365 }
3366 
3367 
3396 cpl_error_code
3398  int value)
3399 {
3400 
3401  const cxchar *const _id = "uves_propertylist_prepend_bool";
3402 
3403  cpl_property *property = NULL;
3404 
3405 
3406  if (self == NULL || name == NULL) {
3407  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
3408  return CPL_ERROR_NULL_INPUT;
3409  }
3410 
3411  property = cpl_property_new(name, CPL_TYPE_BOOL);
3412  cx_assert(property != NULL);
3413 
3414  cpl_property_set_bool(property, value);
3415  uves_deque_push_front(self->properties, property);
3416 
3417  return CPL_ERROR_NONE;
3418 
3419 }
3420 
3421 
3450 cpl_error_code
3452  int value)
3453 {
3454 
3455  const cxchar *const _id = "uves_propertylist_prepend_int";
3456 
3457  cpl_property *property = NULL;
3458 
3459 
3460  if (self == NULL || name == NULL) {
3461  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
3462  return CPL_ERROR_NULL_INPUT;
3463  }
3464 
3465  property = cpl_property_new(name, CPL_TYPE_INT);
3466  cx_assert(property != NULL);
3467 
3468  cpl_property_set_int(property, value);
3469  uves_deque_push_front(self->properties, property);
3470 
3471  return CPL_ERROR_NONE;
3472 
3473 }
3474 
3475 
3504 cpl_error_code
3506  long value)
3507 {
3508 
3509  const cxchar *const _id = "uves_propertylist_prepend_long";
3510 
3511  cpl_property *property = NULL;
3512 
3513 
3514  if (self == NULL || name == NULL) {
3515  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
3516  return CPL_ERROR_NULL_INPUT;
3517  }
3518 
3519  property = cpl_property_new(name, CPL_TYPE_LONG);
3520  cx_assert(property != NULL);
3521 
3522  cpl_property_set_long(property, value);
3523  uves_deque_push_front(self->properties, property);
3524 
3525  return CPL_ERROR_NONE;
3526 
3527 }
3528 
3529 
3558 cpl_error_code
3560  float value)
3561 {
3562 
3563  const cxchar *const _id = "uves_propertylist_prepend_float";
3564 
3565  cpl_property *property = NULL;
3566 
3567 
3568  if (self == NULL || name == NULL) {
3569  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
3570  return CPL_ERROR_NULL_INPUT;
3571  }
3572 
3573  property = cpl_property_new(name, CPL_TYPE_FLOAT);
3574  cx_assert(property != NULL);
3575 
3576  cpl_property_set_float(property, value);
3577  uves_deque_push_front(self->properties, property);
3578 
3579  return CPL_ERROR_NONE;
3580 
3581 }
3582 
3583 
3612 cpl_error_code
3614  double value)
3615 {
3616 
3617  const cxchar *const _id = "uves_propertylist_prepend_double";
3618 
3619  cpl_property *property = NULL;
3620 
3621 
3622  if (self == NULL || name == NULL) {
3623  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
3624  return CPL_ERROR_NULL_INPUT;
3625  }
3626 
3627  property = cpl_property_new(name, CPL_TYPE_DOUBLE);
3628  cx_assert(property != NULL);
3629 
3630  cpl_property_set_double(property, value);
3631  uves_deque_push_front(self->properties, property);
3632 
3633  return CPL_ERROR_NONE;
3634 
3635 }
3636 
3637 
3666 cpl_error_code
3668  const char *value)
3669 {
3670 
3671  const cxchar *const _id = "uves_propertylist_prepend_string";
3672 
3673  cpl_property *property = NULL;
3674 
3675 
3676  if (self == NULL || name == NULL) {
3677  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
3678  return CPL_ERROR_NULL_INPUT;
3679  }
3680 
3681  property = cpl_property_new(name, CPL_TYPE_STRING);
3682  cx_assert(property != NULL);
3683 
3684  cpl_property_set_string(property, value);
3685  uves_deque_push_front(self->properties, property);
3686 
3687  return CPL_ERROR_NONE;
3688 
3689 }
3690 
3691 
3692 
3693 cpl_error_code
3694 uves_propertylist_append_char(uves_propertylist *self, const char *name,
3695  char value)
3696 {
3697  return uves_propertylist_append_c_char(self, name, value, NULL);
3698 }
3699 cpl_error_code
3700 uves_propertylist_append_bool(uves_propertylist *self, const char *name,
3701  int value)
3702 {
3703  return uves_propertylist_append_c_bool(self, name, value, NULL);
3704 }
3705 
3706 cpl_error_code
3707 uves_propertylist_append_int(uves_propertylist *self, const char *name,
3708  int value)
3709 {
3710  return uves_propertylist_append_c_int(self, name, value, NULL);
3711 }
3712 
3713 cpl_error_code
3714 uves_propertylist_append_long(uves_propertylist *self, const char *name,
3715  long value)
3716 {
3717  return uves_propertylist_append_c_long(self, name, value, NULL);
3718 }
3719 
3720 cpl_error_code
3721 uves_propertylist_append_float(uves_propertylist *self, const char *name,
3722  float value)
3723 {
3724  return uves_propertylist_append_c_float(self, name, value, NULL);
3725 }
3726 
3727 cpl_error_code
3728 uves_propertylist_append_double(uves_propertylist *self, const char *name,
3729  double value)
3730 {
3731  return uves_propertylist_append_c_double(self, name, value, NULL);
3732 }
3733 
3734 cpl_error_code
3735 uves_propertylist_append_string(uves_propertylist *self, const char *name,
3736  const char *value)
3737 {
3738  return uves_propertylist_append_c_string(self, name, value, NULL);
3739 }
3740 
3741 
3742 
3743 
3744 
3745 
3746 
3747 
3748 
3749 
3750 
3751 
3752 
3753 
3754 
3755 
3756 
3757 
3786 cpl_error_code
3788  char value, const char *comment)
3789 {
3790 
3791  const cxchar *const _id = "uves_propertylist_append_char";
3792 
3793  cpl_property *property = NULL;
3794 
3795 
3796  if (self == NULL || name == NULL) {
3797  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
3798  return CPL_ERROR_NULL_INPUT;
3799  }
3800 
3801  property = cpl_property_new(name, CPL_TYPE_CHAR);
3802  cx_assert(property != NULL);
3803 
3804  if (comment != NULL) cpl_property_set_comment(property, comment);
3805 
3806  cpl_property_set_char(property, value);
3807  uves_deque_push_back(self->properties, property);
3808 
3809  return CPL_ERROR_NONE;
3810 
3811 }
3812 
3813 
3842 cpl_error_code
3844  int value, const char *comment)
3845 {
3846 
3847  const cxchar *const _id = "uves_propertylist_append_bool";
3848 
3849  cpl_property *property = NULL;
3850 
3851 
3852  if (self == NULL || name == NULL) {
3853  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
3854  return CPL_ERROR_NULL_INPUT;
3855  }
3856 
3857  property = cpl_property_new(name, CPL_TYPE_BOOL);
3858  cx_assert(property != NULL);
3859 
3860  if (comment != NULL) cpl_property_set_comment(property, comment);
3861 
3862  cpl_property_set_bool(property, value);
3863  uves_deque_push_back(self->properties, property);
3864 
3865  return CPL_ERROR_NONE;
3866 
3867 }
3868 
3869 
3898 cpl_error_code
3900  int value, const char *comment)
3901 {
3902 
3903  const cxchar *const _id = "uves_propertylist_append_int";
3904 
3905  cpl_property *property = NULL;
3906 
3907 
3908  if (self == NULL || name == NULL) {
3909  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
3910  return CPL_ERROR_NULL_INPUT;
3911  }
3912 
3913  property = cpl_property_new(name, CPL_TYPE_INT);
3914  cx_assert(property != NULL);
3915 
3916  if (comment != NULL) cpl_property_set_comment(property, comment);
3917 
3918  cpl_property_set_int(property, value);
3919  uves_deque_push_back(self->properties, property);
3920 
3921  return CPL_ERROR_NONE;
3922 
3923 }
3924 
3925 
3954 cpl_error_code
3956  long value, const char *comment)
3957 {
3958 
3959  const cxchar *const _id = "uves_propertylist_append_long";
3960 
3961  cpl_property *property = NULL;
3962 
3963 
3964  if (self == NULL || name == NULL) {
3965  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
3966  return CPL_ERROR_NULL_INPUT;
3967  }
3968 
3969  property = cpl_property_new(name, CPL_TYPE_LONG);
3970  cx_assert(property != NULL);
3971 
3972  if (comment != NULL) cpl_property_set_comment(property, comment);
3973 
3974  cpl_property_set_long(property, value);
3975  uves_deque_push_back(self->properties, property);
3976 
3977  return CPL_ERROR_NONE;
3978 
3979 }
3980 
3981 
4010 cpl_error_code
4012  float value, const char *comment)
4013 {
4014 
4015  const cxchar *const _id = "uves_propertylist_append_float";
4016 
4017  cpl_property *property = NULL;
4018 
4019 
4020  if (self == NULL || name == NULL) {
4021  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
4022  return CPL_ERROR_NULL_INPUT;
4023  }
4024 
4025  property = cpl_property_new(name, CPL_TYPE_FLOAT);
4026  cx_assert(property != NULL);
4027 
4028  if (comment != NULL) cpl_property_set_comment(property, comment);
4029 
4030  cpl_property_set_float(property, value);
4031  uves_deque_push_back(self->properties, property);
4032 
4033  return CPL_ERROR_NONE;
4034 
4035 }
4036 
4037 
4066 cpl_error_code
4068  double value, const char *comment)
4069 {
4070 
4071  const cxchar *const _id = "uves_propertylist_append_double";
4072 
4073  cpl_property *property = NULL;
4074 
4075 
4076  if (self == NULL || name == NULL) {
4077  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
4078  return CPL_ERROR_NULL_INPUT;
4079  }
4080 
4081  property = cpl_property_new(name, CPL_TYPE_DOUBLE);
4082  cx_assert(property != NULL);
4083 
4084  if (comment != NULL) cpl_property_set_comment(property, comment);
4085 
4086  cpl_property_set_double(property, value);
4087  uves_deque_push_back(self->properties, property);
4088 
4089  return CPL_ERROR_NONE;
4090 
4091 }
4092 
4093 
4122 cpl_error_code
4124  const char *value, const char *comment)
4125 {
4126 
4127  const cxchar *const _id = "uves_propertylist_append_string";
4128 
4129  cpl_property *property = NULL;
4130 
4131 
4132  if (self == NULL || name == NULL) {
4133  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
4134  return CPL_ERROR_NULL_INPUT;
4135  }
4136 
4137  property = cpl_property_new(name, CPL_TYPE_STRING);
4138  cx_assert(property != NULL);
4139 
4140  if (comment != NULL) cpl_property_set_comment(property, comment);
4141 
4142  cpl_property_set_string(property, value);
4143  uves_deque_push_back(self->properties, property);
4144 
4145  return CPL_ERROR_NONE;
4146 
4147 }
4148 
4149 
4176 cpl_error_code
4178  const uves_propertylist *other)
4179 {
4180 
4181  const cxchar *const _id = "uves_propertylist_append";
4182 
4183  if (self == NULL) {
4184  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
4185  return CPL_ERROR_NULL_INPUT;
4186  }
4187 
4188  if (other != NULL) {
4189 
4190  uves_deque_const_iterator pos = uves_deque_begin(other->properties);
4191 
4192  while (pos != uves_deque_end(other->properties)) {
4193 
4194  const cpl_property *p = uves_deque_get(other->properties, pos);
4195 
4196  uves_deque_push_back(self->properties, cpl_property_duplicate(p));
4197  pos = uves_deque_next(other->properties, pos);
4198 
4199  }
4200 
4201  }
4202 
4203  return CPL_ERROR_NONE;
4204 
4205 }
4206 
4207 
4238 int
4240 {
4241 
4242  const cxchar *const _id = "uves_propertylist_erase";
4243 
4244  uves_deque_iterator pos;
4245 
4246 
4247  if (self == NULL || name == NULL) {
4248  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
4249  return 0;
4250  }
4251 
4252  pos = _uves_propertylist_find(self, name);
4253  if (pos == uves_deque_end(self->properties)) {
4254  return 0;
4255  }
4256 // fprintf(stderr, "%d\n", __LINE__);
4257 
4258  uves_deque_erase(self->properties, pos, (cx_free_func)cpl_property_delete);
4259 
4260  return 1;
4261 
4262 }
4263 
4299 int
4301  int invert)
4302 {
4303 
4304  const cxchar *const _id = "uves_propertylist_erase_regexp";
4305 
4306  cxint status = 0;
4307  cxint count = 0;
4308 
4309  uves_deque_iterator first, last, pos;
4310 
4311  cpl_property *p;
4312 
4313  uves_regexp filter;
4314 
4315 
4316  if (self == NULL || regexp == NULL) {
4317  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
4318  return 0;
4319  }
4320 
4321 
4322  status = regcomp(&filter.re, regexp, REG_EXTENDED | REG_NOSUB);
4323  if (status) {
4324  cpl_error_set(_id, CPL_ERROR_ILLEGAL_INPUT);
4325  return 0;
4326  }
4327 
4328  filter.invert = invert == 0 ? FALSE : TRUE;
4329 
4330  first = uves_deque_begin(self->properties);
4331  last = uves_deque_end(self->properties);
4332 
4333  while (first < uves_deque_end(self->properties)) {
4334  pos = first;
4335 // first = uves_deque_next(self->properties, first);
4336 
4337  p = uves_deque_get(self->properties, pos);
4338  if (_uves_propertylist_compare_regexp(p, &filter) == TRUE) {
4339 
4340 // fprintf(stderr, "%d\n", __LINE__);
4341 
4342  uves_deque_erase(self->properties, pos,
4343  (cx_free_func)cpl_property_delete);
4344  count++;
4345  }
4346  else
4347  first = uves_deque_next(self->properties, first);
4348  }
4349 
4350  regfree(&filter.re);
4351 
4352  return count;
4353 
4354 }
4355 
4356 
4381 void
4383 {
4384 
4385  const cxchar *const _id = "uves_propertylist_empty";
4386 
4387  uves_deque_iterator first, last;
4388 
4389 
4390  if (self == NULL) {
4391  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
4392  return;
4393  }
4394 
4395  first = uves_deque_begin(self->properties);
4396  last = uves_deque_end(self->properties);
4397 
4398  while (first < uves_deque_end(self->properties)) {
4399  uves_deque_iterator pos = first;
4400 
4401 // first = uves_deque_next(self->properties, first);
4402 // fprintf(stderr, "%d %d %d %d\n", __LINE__, first, last, pos);
4403  uves_deque_erase(self->properties, pos,
4404  (cx_free_func)cpl_property_delete);
4405 
4406 // first = uves_deque_next(self->properties, first);
4407  }
4408 
4409  return;
4410 
4411 }
4412 
4413 
4452 cpl_error_code
4454  char value)
4455 {
4456 
4457  const cxchar *const _id = "uves_propertylist_update_char";
4458 
4459  uves_deque_iterator pos;
4460 
4461 
4462  if (self == NULL || name == NULL) {
4463  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
4464  return CPL_ERROR_NULL_INPUT;
4465  }
4466 
4467  pos = _uves_propertylist_find(self, name);
4468 
4469  if (pos == uves_deque_end(self->properties)) {
4470 
4471  cpl_property *property = cpl_property_new(name, CPL_TYPE_CHAR);
4472 
4473 
4474  cx_assert(property != NULL);
4475 
4476  cpl_property_set_char(property, value);
4477  uves_deque_push_back(self->properties, property);
4478  }
4479  else {
4480 
4481  cpl_property *property = uves_deque_get(self->properties, pos);
4482 
4483 
4484  cx_assert(property != NULL);
4485 
4486  if (cpl_property_get_type(property) != CPL_TYPE_CHAR) {
4487  cpl_error_set(_id, CPL_ERROR_TYPE_MISMATCH);
4488  return CPL_ERROR_TYPE_MISMATCH;
4489  }
4490 
4491  cpl_property_set_char(property, value);
4492 
4493  }
4494 
4495  return CPL_ERROR_NONE;
4496 
4497 }
4498 
4499 
4538 cpl_error_code
4540  int value)
4541 {
4542 
4543  const cxchar *const _id = "uves_propertylist_update_bool";
4544 
4545  uves_deque_iterator pos;
4546 
4547 
4548  if (self == NULL || name == NULL) {
4549  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
4550  return CPL_ERROR_NULL_INPUT;
4551  }
4552 
4553  pos = _uves_propertylist_find(self, name);
4554 
4555  if (pos == uves_deque_end(self->properties)) {
4556 
4557  cpl_property *property = cpl_property_new(name, CPL_TYPE_BOOL);
4558 
4559 
4560  cx_assert(property != NULL);
4561 
4562  cpl_property_set_bool(property, value);
4563  uves_deque_push_back(self->properties, property);
4564  }
4565  else {
4566 
4567  cpl_property *property = uves_deque_get(self->properties, pos);
4568 
4569 
4570  cx_assert(property != NULL);
4571 
4572  if (cpl_property_get_type(property) != CPL_TYPE_BOOL) {
4573  cpl_error_set(_id, CPL_ERROR_TYPE_MISMATCH);
4574  return CPL_ERROR_TYPE_MISMATCH;
4575  }
4576 
4577  cpl_property_set_bool(property, value);
4578 
4579  }
4580 
4581  return CPL_ERROR_NONE;
4582 
4583 }
4584 
4585 
4624 cpl_error_code
4626  int value)
4627 {
4628 
4629  const cxchar *const _id = "uves_propertylist_update_int";
4630 
4631  uves_deque_iterator pos;
4632 
4633 
4634  if (self == NULL || name == NULL) {
4635  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
4636  return CPL_ERROR_NULL_INPUT;
4637  }
4638 
4639  pos = _uves_propertylist_find(self, name);
4640 
4641  if (pos == uves_deque_end(self->properties)) {
4642 
4643  cpl_property *property = cpl_property_new(name, CPL_TYPE_INT);
4644 
4645 
4646  cx_assert(property != NULL);
4647 
4648  cpl_property_set_int(property, value);
4649  uves_deque_push_back(self->properties, property);
4650  }
4651  else {
4652 
4653  cpl_property *property = uves_deque_get(self->properties, pos);
4654 
4655 
4656  cx_assert(property != NULL);
4657 
4658  if (cpl_property_get_type(property) != CPL_TYPE_INT) {
4659  cpl_error_set(_id, CPL_ERROR_TYPE_MISMATCH);
4660  return CPL_ERROR_TYPE_MISMATCH;
4661  }
4662 
4663  cpl_property_set_int(property, value);
4664 
4665  }
4666 
4667  return CPL_ERROR_NONE;
4668 
4669 }
4670 
4671 
4710 cpl_error_code
4712  long value)
4713 {
4714 
4715  const cxchar *const _id = "uves_propertylist_update_long";
4716 
4717  uves_deque_iterator pos;
4718 
4719 
4720  if (self == NULL || name == NULL) {
4721  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
4722  return CPL_ERROR_NULL_INPUT;
4723  }
4724 
4725  pos = _uves_propertylist_find(self, name);
4726 
4727  if (pos == uves_deque_end(self->properties)) {
4728 
4729  cpl_property *property = cpl_property_new(name, CPL_TYPE_LONG);
4730 
4731 
4732  cx_assert(property != NULL);
4733 
4734  cpl_property_set_long(property, value);
4735  uves_deque_push_back(self->properties, property);
4736  }
4737  else {
4738 
4739  cpl_property *property = uves_deque_get(self->properties, pos);
4740 
4741 
4742  cx_assert(property != NULL);
4743 
4744  if (cpl_property_get_type(property) != CPL_TYPE_LONG) {
4745  cpl_error_set(_id, CPL_ERROR_TYPE_MISMATCH);
4746  return CPL_ERROR_TYPE_MISMATCH;
4747  }
4748 
4749  cpl_property_set_long(property, value);
4750 
4751  }
4752 
4753  return CPL_ERROR_NONE;
4754 
4755 }
4756 
4757 
4796 cpl_error_code
4798  float value)
4799 {
4800 
4801  const cxchar *const _id = "uves_propertylist_update_float";
4802 
4803  uves_deque_iterator pos;
4804 
4805 
4806  if (self == NULL || name == NULL) {
4807  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
4808  return CPL_ERROR_NULL_INPUT;
4809  }
4810 
4811  pos = _uves_propertylist_find(self, name);
4812 
4813  if (pos == uves_deque_end(self->properties)) {
4814 
4815  cpl_property *property = cpl_property_new(name, CPL_TYPE_FLOAT);
4816 
4817 
4818  cx_assert(property != NULL);
4819 
4820  cpl_property_set_float(property, value);
4821  uves_deque_push_back(self->properties, property);
4822  }
4823  else {
4824 
4825  cpl_property *property = uves_deque_get(self->properties, pos);
4826 
4827 
4828  cx_assert(property != NULL);
4829 
4830  if (cpl_property_get_type(property) != CPL_TYPE_FLOAT) {
4831  cpl_error_set(_id, CPL_ERROR_TYPE_MISMATCH);
4832  return CPL_ERROR_TYPE_MISMATCH;
4833  }
4834 
4835  cpl_property_set_float(property, value);
4836 
4837  }
4838 
4839  return CPL_ERROR_NONE;
4840 
4841 }
4842 
4843 
4882 cpl_error_code
4884  double value)
4885 {
4886 
4887  const cxchar *const _id = "uves_propertylist_update_double";
4888 
4889  uves_deque_iterator pos;
4890 
4891 
4892  if (self == NULL || name == NULL) {
4893  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
4894  return CPL_ERROR_NULL_INPUT;
4895  }
4896 
4897  pos = _uves_propertylist_find(self, name);
4898 
4899  if (pos == uves_deque_end(self->properties)) {
4900 
4901  cpl_property *property = cpl_property_new(name, CPL_TYPE_DOUBLE);
4902 
4903 
4904  cx_assert(property != NULL);
4905 
4906  cpl_property_set_double(property, value);
4907  uves_deque_push_back(self->properties, property);
4908  }
4909  else {
4910 
4911  cpl_property *property = uves_deque_get(self->properties, pos);
4912 
4913 
4914  cx_assert(property != NULL);
4915 
4916  if (cpl_property_get_type(property) != CPL_TYPE_DOUBLE) {
4917  cpl_error_set(_id, CPL_ERROR_TYPE_MISMATCH);
4918  return CPL_ERROR_TYPE_MISMATCH;
4919  }
4920 
4921  cpl_property_set_double(property, value);
4922 
4923  }
4924 
4925  return CPL_ERROR_NONE;
4926 
4927 }
4928 
4929 
4968 cpl_error_code
4970  const char *value)
4971 {
4972 
4973  const cxchar *const _id = "uves_propertylist_update_string";
4974 
4975  uves_deque_iterator pos;
4976 
4977 
4978  if (self == NULL || name == NULL) {
4979  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
4980  return CPL_ERROR_NULL_INPUT;
4981  }
4982 
4983  pos = _uves_propertylist_find(self, name);
4984 
4985  if (pos == uves_deque_end(self->properties)) {
4986 
4987  cpl_property *property = cpl_property_new(name, CPL_TYPE_STRING);
4988 
4989 
4990  cx_assert(property != NULL);
4991 
4992  cpl_property_set_string(property, value);
4993  uves_deque_push_back(self->properties, property);
4994  }
4995  else {
4996 
4997  cpl_property *property = uves_deque_get(self->properties, pos);
4998 
4999 
5000  cx_assert(property != NULL);
5001 
5002  if (cpl_property_get_type(property) != CPL_TYPE_STRING) {
5003  cpl_error_set(_id, CPL_ERROR_TYPE_MISMATCH);
5004  return CPL_ERROR_TYPE_MISMATCH;
5005  }
5006 
5007  cpl_property_set_string(property, value);
5008 
5009  }
5010 
5011  return CPL_ERROR_NONE;
5012 
5013 }
5014 
5015 
5063 cpl_error_code
5065  const uves_propertylist *other,
5066  const char *name)
5067 {
5068 
5069  const cxchar *const _id = "uves_propertylist_copy_property";
5070 
5071  uves_deque_iterator spos;
5072  uves_deque_iterator tpos;
5073 
5074 
5075  if (self == NULL || other == NULL || name == NULL) {
5076  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
5077  return CPL_ERROR_NULL_INPUT;
5078  }
5079 
5080  spos = _uves_propertylist_find(other, name);
5081 
5082  if (spos == uves_deque_end(other->properties)) {
5083  cpl_error_set(_id, CPL_ERROR_DATA_NOT_FOUND);
5084  return CPL_ERROR_DATA_NOT_FOUND;
5085  }
5086 
5087  tpos = _uves_propertylist_find(self, name);
5088 
5089  if (tpos == uves_deque_end(self->properties)) {
5090 
5091  cpl_property *p = cpl_property_duplicate(uves_deque_get(other->properties,
5092  spos));
5093  uves_deque_push_back(self->properties, p);
5094 
5095  }
5096  else {
5097 
5098  cpl_property *p = uves_deque_get(self->properties, tpos);
5099  cpl_property *_p = uves_deque_get(self->properties, spos);
5100 
5101 
5102  if (cpl_property_get_type(p) != cpl_property_get_type(_p)) {
5103  cpl_error_set(_id, CPL_ERROR_TYPE_MISMATCH);
5104  return CPL_ERROR_TYPE_MISMATCH;
5105  }
5106 
5107  switch (cpl_property_get_type(_p)) {
5108 
5109  case CPL_TYPE_CHAR:
5110  cpl_property_set_char(p, cpl_property_get_char(_p));
5111  break;
5112 
5113  case CPL_TYPE_BOOL:
5114  cpl_property_set_bool(p, cpl_property_get_bool(_p));
5115  break;
5116 
5117  case CPL_TYPE_INT:
5118  cpl_property_set_int(p, cpl_property_get_int(_p));
5119  break;
5120 
5121  case CPL_TYPE_LONG:
5122  cpl_property_set_long(p, cpl_property_get_long(_p));
5123  break;
5124 
5125  case CPL_TYPE_FLOAT:
5126  cpl_property_set_float(p, cpl_property_get_float(_p));
5127  break;
5128 
5129  case CPL_TYPE_DOUBLE:
5130  cpl_property_set_double(p, cpl_property_get_double(_p));
5131  break;
5132 
5133  case CPL_TYPE_STRING:
5134  cpl_property_set_string(p, cpl_property_get_string(_p));
5135  break;
5136 
5137  default:
5138  /* This point should never be reached */
5139  cx_error("%s: Unsupported type encountered!", CX_CODE_POS);
5140  break;
5141 
5142  }
5143 
5144  cpl_property_set_comment(p, cpl_property_get_comment(_p));
5145 
5146  }
5147 
5148  return CPL_ERROR_NONE;
5149 
5150 }
5151 
5152 
5212 cpl_error_code
5214  const uves_propertylist *other,
5215  const char *regexp,
5216  int invert)
5217 {
5218 
5219  const cxchar *const _id = "uves_propertylist_copy_property_regexp";
5220 
5221  cxint status;
5222 
5223  cxsize i;
5224  cxsize count = 0;
5225 
5226  uves_deque_const_iterator first, last;
5227 
5228  typedef struct _property_pair_ {
5229  cpl_property *s;
5230  cpl_property *t;
5231  } property_pair;
5232 
5233  property_pair *pairs = NULL;
5234 
5235  uves_regexp filter;
5236 
5237 
5238  if (self == NULL || other == NULL || regexp == NULL) {
5239  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
5240  return CPL_ERROR_NULL_INPUT;
5241  }
5242 
5243  status = regcomp(&filter.re, regexp, REG_EXTENDED | REG_NOSUB);
5244  if (status) {
5245  cpl_error_set(_id, CPL_ERROR_ILLEGAL_INPUT);
5246  return CPL_ERROR_ILLEGAL_INPUT;
5247  }
5248 
5249  filter.invert = invert == 0 ? FALSE : TRUE;
5250 
5251 
5252  count = uves_deque_size(other->properties);
5253 
5254  if (count == 0) {
5255  regfree(&filter.re);
5256  return CPL_ERROR_NONE;
5257  }
5258 
5259  pairs = cx_malloc(count * sizeof(property_pair));
5260  cx_assert(pairs != NULL);
5261 
5262  count = 0;
5263 
5264 
5265  first = uves_deque_begin(other->properties);
5266  last = uves_deque_end(other->properties);
5267 
5268  while (first != last) {
5269 
5270  cpl_property *p = uves_deque_get(other->properties, first);
5271 
5272 
5273  if (_uves_propertylist_compare_regexp(p, &filter) == TRUE) {
5274 
5275  const cxchar *name = cpl_property_get_name(p);
5276 
5277  uves_deque_const_iterator pos = _uves_propertylist_find(self, name);
5278 
5279  cpl_property *_p = NULL;
5280 
5281 
5282  if (pos != uves_deque_end(self->properties)) {
5283 
5284  _p = uves_deque_get(self->properties, pos);
5285 
5286  if (cpl_property_get_type(p) != cpl_property_get_type(_p)) {
5287 
5288  regfree(&filter.re);
5289 
5290  cx_free(pairs);
5291  pairs = NULL;
5292 
5293  cpl_error_set(_id, CPL_ERROR_TYPE_MISMATCH);
5294 
5295  return CPL_ERROR_TYPE_MISMATCH;
5296 
5297  }
5298 
5299  }
5300 
5301  pairs[count].s = p;
5302  pairs[count].t = _p;
5303  ++count;
5304 
5305  }
5306 
5307  first = uves_deque_next(other->properties, first);
5308 
5309  }
5310 
5311  regfree(&filter.re);
5312 
5313 
5314  for (i = 0; i < count; i++) {
5315 
5316  if (pairs[i].t == NULL) {
5317 
5318  cpl_property *p = cpl_property_duplicate(pairs[i].s);
5319  uves_deque_push_back(self->properties, p);
5320 
5321  }
5322  else {
5323 
5324  switch (cpl_property_get_type(pairs[i].s)) {
5325 
5326  case CPL_TYPE_CHAR:
5327  cpl_property_set_char(pairs[i].t,
5328  cpl_property_get_char(pairs[i].s));
5329  break;
5330 
5331  case CPL_TYPE_BOOL:
5332  cpl_property_set_bool(pairs[i].t,
5333  cpl_property_get_bool(pairs[i].s));
5334  break;
5335 
5336  case CPL_TYPE_INT:
5337  cpl_property_set_int(pairs[i].t,
5338  cpl_property_get_int(pairs[i].s));
5339  break;
5340 
5341  case CPL_TYPE_LONG:
5342  cpl_property_set_long(pairs[i].t,
5343  cpl_property_get_long(pairs[i].s));
5344  break;
5345 
5346  case CPL_TYPE_FLOAT:
5347  cpl_property_set_float(pairs[i].t,
5348  cpl_property_get_float(pairs[i].s));
5349  break;
5350 
5351  case CPL_TYPE_DOUBLE:
5352  cpl_property_set_double(pairs[i].t,
5353  cpl_property_get_double(pairs[i].s));
5354  break;
5355 
5356  case CPL_TYPE_STRING:
5357  cpl_property_set_string(pairs[i].t,
5358  cpl_property_get_string(pairs[i].s));
5359  break;
5360 
5361  default:
5362  /* This point should never be reached */
5363  cx_free(pairs);
5364  cx_error("%s: Unsupported type encountered!", CX_CODE_POS);
5365  break;
5366 
5367  }
5368 
5369  }
5370 
5371  }
5372 
5373  cx_free(pairs);
5374 
5375  return CPL_ERROR_NONE;
5376 
5377 }
5378 
5379 
5441 uves_propertylist_load(const char *name, int position)
5442 {
5443 
5444  const cxchar *const _id = "uves_propertylist_load";
5445 
5446  register cxint n, status;
5447 
5448  qfits_header *header;
5449 
5450  uves_propertylist *self;
5451 
5452 
5453  if (name == NULL) {
5454  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
5455  return NULL;
5456  }
5457 
5458  if (position < 0) {
5459  cpl_error_set(_id, CPL_ERROR_ILLEGAL_INPUT);
5460  return NULL;
5461  }
5462 
5463  status = qfits_is_fits((cxchar *)name);
5464  if (status == -1) {
5465  cpl_error_set(_id, CPL_ERROR_FILE_IO);
5466  return NULL;
5467  }
5468  else {
5469  if (status == 0) {
5470  cpl_error_set(_id, CPL_ERROR_BAD_FILE_FORMAT);
5471  return NULL;
5472  }
5473  }
5474 
5475  /*
5476  * qfits_query_n_ext() only counts true extensions, i.e. it does not
5477  * count the primary FITS unit. But since we passed the qfits_is_fits()
5478  * check we can safely assume that there is one.
5479  */
5480 
5481  n = qfits_query_n_ext((cxchar *)name);
5482 
5483  if (n < position) {
5484  cpl_error_set(_id, CPL_ERROR_DATA_NOT_FOUND);
5485  return NULL;
5486  }
5487 
5488 
5489  header = qfits_header_readext((cxchar *)name, position);
5490 
5491  if (header == NULL) {
5492  cpl_error_set(_id, CPL_ERROR_ILLEGAL_INPUT);
5493  return NULL;
5494  }
5495 
5496  self = uves_propertylist_new();
5497  cx_assert(self);
5498 
5499  status = _uves_propertylist_from_fits(self, header, NULL, NULL);
5500 
5501  if (status) {
5503  qfits_header_destroy(header);
5504 
5505  cpl_error_set(_id, CPL_ERROR_ILLEGAL_INPUT);
5506  return NULL;
5507  }
5508 
5509  qfits_header_destroy(header);
5510 
5511  return self;
5512 
5513 }
5514 
5515 
5588 uves_propertylist_load_regexp(const char *name, int position,
5589  const char *regexp, int invert)
5590 {
5591 
5592  const cxchar *const _id = "uves_propertylist_load_regexp";
5593 
5594  register cxint n, status;
5595 
5596  qfits_header *header;
5597 
5598  uves_propertylist *self;
5599 
5600  uves_regexp filter;
5601 
5602 
5603  if (name == NULL || regexp == NULL) {
5604  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
5605  return NULL;
5606  }
5607 
5608  if (position < 0) {
5609  cpl_error_set(_id, CPL_ERROR_ILLEGAL_INPUT);
5610  return NULL;
5611  }
5612 
5613  status = regcomp(&filter.re, regexp, REG_EXTENDED | REG_NOSUB);
5614  if (status) {
5615  cpl_error_set(_id, CPL_ERROR_ILLEGAL_INPUT);
5616  return NULL;
5617  }
5618 
5619  filter.invert = invert == 0 ? FALSE : TRUE;
5620 
5621 
5622  status = qfits_is_fits((cxchar *)name);
5623  if (status == -1) {
5624  cpl_error_set(_id, CPL_ERROR_FILE_IO);
5625  return NULL;
5626  }
5627  else {
5628  if (status == 0) {
5629  cpl_error_set(_id, CPL_ERROR_BAD_FILE_FORMAT);
5630  return NULL;
5631  }
5632  }
5633 
5634  /*
5635  * qfits_query_n_ext() only counts true extensions, i.e. it does not
5636  * count the primary FITS unit. But since we passed the qfits_is_fits()
5637  * check we can safely assume that there is one.
5638  */
5639 
5640  n = qfits_query_n_ext((cxchar *)name);
5641 
5642  if (n < position) {
5643  cpl_error_set(_id, CPL_ERROR_DATA_NOT_FOUND);
5644  return NULL;
5645  }
5646 
5647 
5648  header = qfits_header_readext((cxchar *)name, position);
5649 
5650  if (header == NULL) {
5651  cpl_error_set(_id, CPL_ERROR_ILLEGAL_INPUT);
5652  return NULL;
5653  }
5654 
5655  self = uves_propertylist_new();
5656  cx_assert(self);
5657 
5658  status = _uves_propertylist_from_fits(self, header,
5659  _uves_propertylist_filter_regexp,
5660  &filter);
5661 
5662  if (status) {
5664  qfits_header_destroy(header);
5665 
5666  regfree(&filter.re);
5667 
5668  cpl_error_set(_id, CPL_ERROR_ILLEGAL_INPUT);
5669  return NULL;
5670  }
5671 
5672  qfits_header_destroy(header);
5673  regfree(&filter.re);
5674 
5675  return self;
5676 
5677 }
5678 
5679 
5697 qfits_header *
5698 uves_propertylist_to_fits(const uves_propertylist *self)
5699 {
5700  const cxchar *const _id = "uves_propertylist_to_fits";
5701 
5702  qfits_header *header;
5703 
5704 
5705  cx_assert(self != NULL);
5706 
5707  header = qfits_header_new();
5708 
5709  if (!uves_deque_empty(self->properties)) {
5710  uves_deque_iterator i = uves_deque_begin(self->properties);
5711  uves_deque_iterator last = uves_deque_end(self->properties);
5712 
5713  while (i != last) {
5714  cxchar tmp[FITS_LINESZ + 1];
5715  cxchar key[FITS_LINESZ + 1];
5716  cxchar value[FITS_LINESZ + 1];
5717  cxfloat fval;
5718  cxdouble dval;
5719  cpl_property *property;
5720 
5721  property = uves_deque_get(self->properties, i);
5722 
5723  /*
5724  * Convert each property into a FITS keyword an error is
5725  * triggered for unsupported types. Also, since the FITS
5726  * format does not support array keywords, apart from strings,
5727  * i.e. character arrays, an error is triggered in this case too.
5728  *
5729  * A possible solution for the array case would be to create
5730  * a sequence of indexed keywords. But this must be checked.
5731  */
5732 
5733  strncpy(tmp, cpl_property_get_name(property), FITS_LINESZ);
5734  tmp[FITS_LINESZ] = '\0';
5735 
5736  if (!cx_strupper(tmp)) {
5737  cpl_error_set(_id, CPL_ERROR_INCOMPATIBLE_INPUT);
5738 
5739  qfits_header_destroy(header);
5740 
5741  return NULL;
5742  }
5743 
5744  key[0] = '\0';
5745 
5746  if (strlen(tmp) > FITS_STDKEY_MAX &&
5747  strncmp(tmp, "HIERARCH ", 9)) {
5748  strncat(key, "HIERARCH ", 9);
5749  }
5750  strncat(key, tmp, FITS_LINESZ - strlen(key));
5751 
5752  switch (cpl_property_get_type(property)) {
5753  case CPL_TYPE_CHAR:
5754  cx_snprintf(value, FITS_LINESZ, "'%c'",
5755  cpl_property_get_char(property));
5756  break;
5757 
5758  case CPL_TYPE_BOOL:
5759  {
5760  cxint pvalue = cpl_property_get_bool(property);
5761 
5762  cx_snprintf(value, FITS_LINESZ, "%c",
5763  pvalue == 1 ? 'T' : 'F');
5764  break;
5765  }
5766 
5767  case CPL_TYPE_INT:
5768  cx_snprintf(value, FITS_LINESZ, "%d",
5769  cpl_property_get_int(property));
5770  break;
5771 
5772  case CPL_TYPE_LONG:
5773  cx_snprintf(value, FITS_LINESZ, "%ld",
5774  cpl_property_get_long(property));
5775  break;
5776 
5777  case CPL_TYPE_FLOAT:
5778  fval = cpl_property_get_float(property);
5779  cx_snprintf(value, FITS_LINESZ, "%.7G", fval);
5780 
5781  if (!strchr(value, '.')) {
5782  if (strchr(value, 'E'))
5783  cx_snprintf(value, FITS_LINESZ, "%.1E", fval);
5784  else
5785  strcat(value, ".");
5786  }
5787  break;
5788 
5789  case CPL_TYPE_DOUBLE:
5790  dval = cpl_property_get_double(property);
5791  cx_snprintf(value, FITS_LINESZ, "%.15G", dval);
5792 
5793  if (!strchr(value, '.')) {
5794  if (strchr(value, 'E'))
5795  cx_snprintf(value, FITS_LINESZ, "%.1E", dval);
5796  else
5797  strcat(value, ".");
5798  }
5799  break;
5800 
5801  case CPL_TYPE_STRING:
5802  if (!strcmp(key, "COMMENT") || !strcmp(key, "HISTORY")) {
5803  cx_snprintf(value, FITS_LINESZ, "%s",
5804  cpl_property_get_string(property));
5805  }
5806  else {
5807 
5808  cxint n = 0;
5809 
5810  n = cx_snprintf(value, FITS_SVALUE_MAX + 1, "'%s'",
5811  cpl_property_get_string(property));
5812 
5813  if (n > FITS_SVALUE_MAX) {
5814  value[FITS_SVALUE_MAX - 1] = '\'';
5815  value[FITS_SVALUE_MAX] = '\0';
5816  }
5817 
5818  }
5819  break;
5820 
5821  default:
5822  cpl_error_set(_id, CPL_ERROR_INCOMPATIBLE_INPUT);
5823 
5824  qfits_header_destroy(header);
5825 
5826  return NULL;
5827  break;
5828  }
5829 
5830  qfits_header_append(header, key, value,
5831  (cxchar *)cpl_property_get_comment(property),
5832  NULL);
5833 
5834  i = uves_deque_next(self->properties, i);
5835  }
5836  }
5837 
5838 
5839  /*
5840  * Add the END keyword as last entry.
5841  */
5842 
5843  /* FIXME: Maybe better to check if end is already present */
5844 
5845  qfits_header_append(header, "END", NULL, NULL, NULL);
5846 
5847 
5848  /*
5849  * Sort the header according to ESO's DICB standard
5850  */
5851 
5852  if (qfits_header_sort(&header) != 0) {
5853  cpl_error_set(_id, CPL_ERROR_INCOMPATIBLE_INPUT);
5854 
5855  qfits_header_destroy(header);
5856 
5857  return NULL;
5858  }
5859 
5860  return header;
5861 
5862 }
5863 
5888 uves_propertylist_from_fits(const qfits_header *header)
5889 {
5890 
5891  const cxchar *const _id = "uves_propertylist_from_fits";
5892 
5893  register cxint status;
5894 
5895  uves_propertylist *self;
5896 
5897 
5898  if (!header) {
5899  cpl_error_set(_id, CPL_ERROR_NULL_INPUT);
5900  return NULL;
5901  }
5902 
5903  self = uves_propertylist_new();
5904  cx_assert(self != NULL);
5905 
5906  status = _uves_propertylist_from_fits(self, header, NULL, NULL);
5907 
5908  if (status) {
5910 
5911 // cpl_error_set_where(_id);
5912 
5913  switch (status) {
5914  case -2:
5915  case -1:
5916  cpl_error_set(_id, CPL_ERROR_ILLEGAL_INPUT);
5917  break;
5918 
5919  case 1:
5920  cpl_error_set(_id, CPL_ERROR_INVALID_TYPE);
5921  break;
5922 
5923  default:
5924  /* This should never be reached */
5925  break;
5926  }
5927 
5928  return NULL;
5929  }
5930 
5931  return self;
5932 
5933 }
5934 
5935 #endif /* USE_CPL */
5936