b0712fcc8f4a8ab6f5f5d2ec1a9662b80fe4ea5c
[pspp] / src / data / attributes.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2008, 2011, 2012, 2016 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 /* This header supports custom attribute of the sort maintained
23    by the DATAFILE ATTRIBUTE and VARIABLE ATTRIBUTE commands.
24
25    Attributes have a name (the rules for which are the same as
26    those for PSPP variable names) and one or more values, each of
27    which is a string.  An attribute may be part of one attribute
28    set.
29
30    An attribute set is an unordered collection of attributes
31    with names that are unique (case-insensitively). */
32
33 struct attribute *attribute_create (const char *name);
34 struct attribute *attribute_clone (const struct attribute *);
35 void attribute_destroy (struct attribute *);
36
37 const char *attribute_get_name (const struct attribute *);
38 const char *attribute_get_value (const struct attribute *, size_t index);
39 void attribute_add_value (struct attribute *, const char *);
40 void attribute_set_value (struct attribute *, size_t index, const char *);
41 void attribute_del_value (struct attribute *, size_t index);
42 size_t attribute_get_n_values (const struct attribute *);
43
44 struct attrset
45   {
46     struct hmap map;
47   };
48
49 void attrset_init (struct attrset *);
50 void attrset_clone (struct attrset *, const struct attrset *);
51 void attrset_destroy (struct attrset *);
52
53 size_t attrset_count (const struct attrset *);
54
55 struct attribute *attrset_lookup (const struct attrset *, const char *);
56 void attrset_add (struct attrset *, struct attribute *);
57 void attrset_delete (struct attrset *, const char *);
58 void attrset_clear (struct attrset *);
59
60 struct attrset_iterator
61   {
62     struct hmap_node *node;
63   };
64 struct attribute *attrset_first (const struct attrset *,
65                                  struct attrset_iterator *);
66 struct attribute *attrset_next (const struct attrset *,
67                                 struct attrset_iterator *);
68 struct attribute **attrset_sorted (const struct attrset *);
69
70 #endif /* data/attributes.h */