fdfe62f461a652512f706f4c70145cbbf3c223ff
[pspp-builds.git] / src / data / case.h
1 /* PSPP - computes sample statistics.
2    Copyright (C) 2004, 2007 Free Software Foundation, Inc.
3
4    This program is free software; you can redistribute it and/or
5    modify it under the terms of the GNU General Public License as
6    published by the Free Software Foundation; either version 2 of the
7    License, or (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful, but
10    WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    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, write to the Free Software
16    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17    02110-1301, USA. */
18
19 #ifndef HEADER_CASE
20 #define HEADER_CASE
21
22 #include <limits.h>
23 #include <stddef.h>
24 #include <stdbool.h>
25 #include "value.h"
26
27 struct variable;
28
29 /* A count of cases or the index of a case within a collection of
30    them. */
31 #define CASENUMBER_MAX LONG_MAX
32 typedef long int casenumber;
33
34 /* Opaque structure that represents a case.  Use accessor
35    functions instead of accessing any members directly.  Use
36    case_move() or case_clone() instead of copying.  */
37 struct ccase
38   {
39     struct case_data *case_data;        /* Actual data. */
40   };
41
42 void case_nullify (struct ccase *);
43 bool case_is_null (const struct ccase *);
44
45 void case_create (struct ccase *, size_t value_cnt);
46 void case_clone (struct ccase *, const struct ccase *);
47 void case_move (struct ccase *, struct ccase *);
48 void case_destroy (struct ccase *);
49
50 size_t case_get_value_cnt (const struct ccase *);
51
52 void case_resize (struct ccase *, size_t new_cnt);
53 void case_swap (struct ccase *, struct ccase *);
54
55 bool case_try_create (struct ccase *, size_t value_cnt);
56 bool case_try_clone (struct ccase *, const struct ccase *);
57
58 void case_copy (struct ccase *dst, size_t dst_idx,
59                 const struct ccase *src, size_t src_idx,
60                 size_t cnt);
61
62 void case_copy_out (const struct ccase *,
63                        size_t start_idx, union value *, size_t value_cnt);
64 void case_copy_in (struct ccase *,
65                        size_t start_idx, const union value *, size_t value_cnt);
66
67 const union value *case_data (const struct ccase *, const struct variable *);
68 double case_num (const struct ccase *, const struct variable *);
69 const char *case_str (const struct ccase *, const struct variable *);
70 union value *case_data_rw (struct ccase *, const struct variable *);
71
72 const union value *case_data_idx (const struct ccase *, size_t idx);
73 double case_num_idx (const struct ccase *, size_t idx);
74 const char *case_str_idx (const struct ccase *, size_t idx);
75 union value *case_data_rw_idx (struct ccase *, size_t idx);
76
77 int case_compare (const struct ccase *, const struct ccase *,
78                   const struct variable *const *, size_t var_cnt);
79 int case_compare_2dict (const struct ccase *, const struct ccase *,
80                         const struct variable *const *,
81                         const struct variable *const *,
82                         size_t var_cnt);
83
84 const union value *case_data_all (const struct ccase *);
85 union value *case_data_all_rw (struct ccase *);
86
87 #endif /* case.h */