pxd: initial work
[pspp] / src / data / attributes.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2008, 2010, 2011, 2012 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17 #ifndef DATA_ATTRIBUTES_H
18 #define DATA_ATTRIBUTES_H 1
19
20 #include "libpspp/hmapx.h"
21
22 struct pxd;
23
24 /* This header supports custom attribute of the sort maintained
25    by the DATAFILE ATTRIBUTE and VARIABLE ATTRIBUTE commands.
26
27    Attributes have a name (the rules for which are the same as
28    those for PSPP variable names) and one or more values, each of
29    which is a string.  An attribute may be part of one attribute
30    set.
31
32    An attribute set is an unordered collection of attributes
33    with names that are unique (case-insensitively). */
34
35 struct attribute *attribute_create (const char *name);
36 struct attribute *attribute_clone (const struct attribute *);
37 void attribute_destroy (struct attribute *);
38
39 const char *attribute_get_name (const struct attribute *);
40 const char *attribute_get_value (const struct attribute *, size_t index);
41 void attribute_add_value (struct attribute *, const char *);
42 void attribute_set_value (struct attribute *, size_t index, const char *);
43 void attribute_del_value (struct attribute *, size_t index);
44 size_t attribute_get_n_values (const struct attribute *);
45
46 struct pxd_object *attribute_save (const struct attribute *, struct pxd *);
47 struct attribute *attribute_load (struct pxd_object *, const struct pxd *);
48
49 struct attrset 
50   {
51     struct hmap map;
52   };
53
54 void attrset_init (struct attrset *);
55 void attrset_clone (struct attrset *, const struct attrset *);
56 void attrset_destroy (struct attrset *);
57
58 size_t attrset_count (const struct attrset *);
59
60 struct attribute *attrset_lookup (struct attrset *, const char *);
61 void attrset_add (struct attrset *, struct attribute *);
62 void attrset_delete (struct attrset *, const char *);
63 void attrset_clear (struct attrset *);
64
65 struct pxd_object *attrset_save (const struct attrset *, struct pxd *);
66 void attrset_load (struct attrset *, struct pxd_object *, const struct pxd *);
67
68 struct attrset_iterator
69   {
70     struct hmap_node *node;
71   };
72 struct attribute *attrset_first (const struct attrset *,
73                                  struct attrset_iterator *);
74 struct attribute *attrset_next (const struct attrset *,
75                                 struct attrset_iterator *);
76 struct attribute **attrset_sorted (const struct attrset *);
77
78 #endif /* data/attributes.h */