Compilation: clean up dialog including.
[gnumeric.git] / src / value.h
blob344ed4a4a5624de9108a211595eaede81e33b405
1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 #ifndef _GNM_VALUE_H_
3 # define _GNM_VALUE_H_
5 #include "gnumeric.h"
6 #include "position.h"
7 #include "numbers.h"
8 #include "parse-util.h"
9 #include <glib-object.h>
11 G_BEGIN_DECLS
13 typedef enum {
14 /* Use magic values to act as a signature
15 * DO NOT CHANGE THESE NUMBERS
16 * As of version 0.57 they are using as keys
17 * in the xml
19 VALUE_EMPTY = 10,
20 VALUE_BOOLEAN = 20,
21 VALUE_FLOAT = 40,
22 VALUE_ERROR = 50,
23 VALUE_STRING = 60,
24 VALUE_CELLRANGE = 70,
25 VALUE_ARRAY = 80
26 } GnmValueType;
29 * This one lives only in old XML files and is understood by
30 * value_new_from_string.
32 #define VALUE_INTEGER ((GnmValueType)30)
35 typedef struct {
36 GnmValueType const type;
37 GOFormat const *fmt;
38 } GnmValueAny;
39 struct _GnmValueBool {
40 GnmValueType const type;
41 GOFormat *fmt;
42 gboolean val;
44 struct _GnmValueFloat {
45 GnmValueType const type;
46 GOFormat *fmt;
47 gnm_float val;
49 struct _GnmValueErr {
50 GnmValueType const type;
51 GOFormat *fmt;
52 GOString *mesg;
54 struct _GnmValueStr {
55 GnmValueType const type;
56 GOFormat *fmt;
57 GOString *val;
59 struct _GnmValueRange {
60 GnmValueType const type;
61 GOFormat *fmt;
62 GnmRangeRef cell;
64 struct _GnmValueArray {
65 GnmValueType const type;
66 GOFormat *fmt;
67 int x, y;
68 GnmValue ***vals; /* Array [x][y] */
71 union _GnmValue {
72 GnmValueAny v_any;
73 GnmValueBool v_bool;
74 GnmValueFloat v_float;
75 GnmValueErr v_err;
76 GnmValueStr v_str;
77 GnmValueRange v_range;
78 GnmValueArray v_array;
81 #define VALUE_FMT(v) ((v)->v_any.fmt)
82 #define VALUE_IS_EMPTY(v) (((v) == NULL) || ((v)->v_any.type == VALUE_EMPTY))
83 #define VALUE_IS_EMPTY_OR_ERROR(v) (VALUE_IS_EMPTY(v) || (v)->v_any.type == VALUE_ERROR)
84 #define VALUE_IS_STRING(v) ((v)->v_any.type == VALUE_STRING)
85 #define VALUE_IS_BOOLEAN(v) ((v)->v_any.type == VALUE_BOOLEAN)
86 #define VALUE_IS_ERROR(v) ((v)->v_any.type == VALUE_ERROR)
87 #define VALUE_IS_NUMBER(v) (((v)->v_any.type == VALUE_FLOAT) || \
88 ((v)->v_any.type == VALUE_BOOLEAN))
89 #define VALUE_IS_FLOAT(v) ((v)->v_any.type == VALUE_FLOAT)
90 #define VALUE_IS_ARRAY(v) ((v)->v_any.type == VALUE_ARRAY)
91 #define VALUE_IS_CELLRANGE(v) ((v)->v_any.type == VALUE_CELLRANGE)
93 typedef enum {
94 IS_EQUAL,
95 IS_LESS,
96 IS_GREATER,
97 TYPE_MISMATCH
98 } GnmValDiff;
100 GType gnm_value_get_type (void); /* a boxed type */
102 GnmValue *value_new_empty (void);
103 GnmValue *value_new_bool (gboolean b);
104 GnmValue *value_new_int (int i);
105 GnmValue *value_new_float (gnm_float f);
106 GnmValue *value_new_error (GnmEvalPos const *pos, char const *mesg);
107 GnmValue *value_new_error_str (GnmEvalPos const *pos, GOString *mesg);
108 GnmValue *value_new_error_std (GnmEvalPos const *pos, GnmStdError err);
109 GnmValue *value_new_error_NULL (GnmEvalPos const *pos);
110 GnmValue *value_new_error_DIV0 (GnmEvalPos const *pos);
111 GnmValue *value_new_error_VALUE (GnmEvalPos const *pos);
112 GnmValue *value_new_error_REF (GnmEvalPos const *pos);
113 GnmValue *value_new_error_NAME (GnmEvalPos const *pos);
114 GnmValue *value_new_error_NUM (GnmEvalPos const *pos);
115 GnmValue *value_new_error_NA (GnmEvalPos const *pos);
116 GnmValue *value_new_string (char const *str);
117 GnmValue *value_new_string_nocopy (char *str);
118 GnmValue *value_new_string_str (GOString *str);
119 GnmValue *value_new_cellrange_unsafe (GnmCellRef const *a, GnmCellRef const *b);
120 GnmValue *value_new_cellrange (GnmCellRef const *a, GnmCellRef const *b,
121 int eval_col, int eval_row);
122 GnmValue *value_new_cellrange_r (Sheet *sheet, GnmRange const *r);
123 GnmValue *value_new_cellrange_str (Sheet *sheet, char const *str);
124 GnmValue *value_new_cellrange_parsepos_str (GnmParsePos const *pp,
125 char const *str,
126 GnmExprParseFlags flags);
127 GnmValue *value_new_array (guint cols, guint rows);
128 GnmValue *value_new_array_empty (guint cols, guint rows);
129 GnmValue *value_new_array_non_init (guint cols, guint rows);
130 GnmValue *value_new_from_string (GnmValueType t, char const *str,
131 GOFormat *sf, gboolean translated);
133 void value_release (GnmValue *v);
134 void value_set_fmt (GnmValue *v, GOFormat const *fmt);
135 void value_dump (GnmValue const *v);
136 GnmValue *value_dup (GnmValue const *v);
138 gnm_float value_diff (GnmValue const *a, GnmValue const *b);
139 GnmValDiff value_compare (GnmValue const *a, GnmValue const *b,
140 gboolean case_sensitive);
141 GnmValDiff value_compare_no_cache (GnmValue const *a, GnmValue const *b,
142 gboolean case_sensitive);
143 int value_cmp (void const *ptr_a, void const *ptr_b);
144 int value_cmp_reverse (void const *ptr_a, void const *ptr_b);
145 gboolean value_equal (GnmValue const *a, GnmValue const *b);
146 guint value_hash (GnmValue const *v);
148 char const *value_peek_string (GnmValue const *v);
149 char *value_get_as_string (GnmValue const *v);
150 void value_get_as_gstring (GnmValue const *v, GString *target,
151 GnmConventions const *conv);
152 char *value_stringify (GnmValue const *v);
154 GnmValueType value_type_of (GnmValue const *v);
155 int value_get_as_int (GnmValue const *v);
156 gnm_float value_get_as_float (GnmValue const *v);
157 gboolean value_is_zero (GnmValue const *v);
158 GnmValue *value_coerce_to_number (GnmValue *v, gboolean *valid,
159 GnmEvalPos const *ep);
161 GnmValue *value_error_set_pos (GnmValueErr *err, GnmEvalPos const *pos);
162 GnmStdError value_error_classify (GnmValue const *v);
163 char const *value_error_name (GnmStdError err, gboolean translated);
165 gboolean value_get_as_bool (GnmValue const *v, gboolean *err);
166 gboolean value_get_as_checked_bool (GnmValue const *v);
167 GnmRangeRef const *value_get_rangeref (GnmValue const *v);
169 typedef struct {
170 GnmValue const *v; /* value at position */
171 int x, y; /* coordinates within input region */
172 GnmValue const *region; /* input region */
173 GnmEvalPos const *ep; /* context for region */
174 GnmCellIter const *cell_iter; /* non-NULL for ranges */
175 } GnmValueIter;
176 typedef GnmValue *(*GnmValueIterFunc) (GnmValueIter const *iter, gpointer user_data);
178 /* Area functions ( for VALUE_RANGE or VALUE_ARRAY ) */
179 GnmValue *value_area_foreach (GnmValue const *v, GnmEvalPos const *ep,
180 CellIterFlags flags,
181 GnmValueIterFunc func, gpointer user_data);
182 int value_area_get_width (GnmValue const *v, GnmEvalPos const *ep);
183 int value_area_get_height (GnmValue const *v, GnmEvalPos const *ep);
184 GnmValue const *value_area_fetch_x_y (GnmValue const *v, int x, int y,
185 GnmEvalPos const *ep);
186 GnmValue const *value_area_get_x_y (GnmValue const *v, int x, int y,
187 GnmEvalPos const *ep);
189 /* A zero integer, not to be freed or changed. */
190 extern GnmValue const *value_zero;
191 extern GnmValueErr const value_terminate_err;
192 #define VALUE_TERMINATE ((GnmValue *)&value_terminate_err)
194 void value_array_set (GnmValue *array, int col, int row, GnmValue *v);
197 /* Protected */
198 void value_init (void);
199 void value_shutdown (void);
201 G_END_DECLS
203 #endif /* _GNM_VALUE_H_ */