1 /*
2    Copyright (c) 2003 Matt Emmerton
3 
4    Permission is hereby granted, free of charge, to any person
5    obtaining a copy of this software and associated documentation
6    files (the "Software"), to deal in the Software without
7    restriction, including without limitation the rights to use, copy,
8    modify, merge, publish, distribute, sublicense, and/or sell copies
9    of the Software, and to permit persons to whom the Software is
10    furnished to do so, subject to the following conditions:
11 
12    The above copyright notice and this permission notice shall be
13    included in all copies or substantial portions of the Software.
14 
15    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19    BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20    ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21    CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22    SOFTWARE.
23 */
24 /*=============================================================
25  * pvalue.h -- PVALUE structures and prototypes
26  * Copyright(c) 2003 by Matt Emmerton; all rights reserved
27  *===========================================================*/
28 #ifndef _PVALUE_H
29 #define _PVALUE_H
30 
31 #include "array.h"      /* for ARRAY */
32 #include "list.h"       /* for LIST */
33 #include "cache.h"      /* for CACHEEL */
34 #include "gedcom.h"     /* for NODE, RECORD */
35 
36 #ifndef _INDISEQ_H
37 #include "indiseq.h"    /* for INDISEQ */
38 #endif
39 
40 #include "table.h"      /* for TABLE */
41 
42 typedef union {
43 	/* "basic" types, should be same as UNION */
44         BOOLEAN bxd;
45         INT     ixd;
46         FLOAT   fxd;
47 	STRING	sxd;
48         VPTR    pxd;	/* Try not to use this! */
49 	/* "complex" types */
50 	NODE	nxd;
51 	ARRAY	axd;
52 	LIST	lxd;
53 	CACHEEL	cxd;
54 	RECORD	rxd;
55 	INDISEQ	qxd;
56 	TABLE	txd;
57 } PVALUE_DATA;
58 
59 typedef struct tag_pvalue *PVALUE;
60 struct tag_pvalue {
61         struct tag_vtable * vtable;
62         unsigned char type;     /* type of value */
63 	PVALUE_DATA value;
64 };
65 
66 /* PVALUE types */
67 
68 #define PNULL      1  /* pxd=0 */ /* (freed pvalue) any value -- no type restriction - always NULL value */
69 #define PINT       2  /* ixd */ /* integer */
70 /* PLONG==3 is obsolete */
71 #define PFLOAT     4  /* fxd */ /* floating point */
72 #define PBOOL      5  /* bxd */ /* boolean */
73 #define PSTRING    6  /* sxd */ /* string */
74 #define PGNODE	   7  /* nxd */ /* GEDCOM node */
75 #define PINDI      8  /* rxd */ /* GEDCOM person record */
76 #define PFAM       9  /* rxd */ /* GEDCOM family record */
77 #define PSOUR     10  /* rxd */ /* GEDCOM source record */
78 #define PEVEN     11  /* rxd */ /* GEDCOM event record */
79 #define POTHR     12  /* rxd */ /* GEDCOM other record */
80 #define PLIST     13  /* lxd */ /* list */
81 #define PTABLE    14  /* txd */ /* table */
82 #define PSET      15  /* qxd */ /* set/indiseq */
83 #define PARRAY    16  /* axd */ /* array */
84 #define PMAXLIVE  PARRAY /* maximum live type */
85 #define PFREED    99  /* returned to free list */
86 
87 /* Handy PVALUE macros */
88 #define ptype(p)        ((p)->type)     /* type of expression */
89 #define pvalvv(p)       ((p)->value)    /* value of expression */
90 
91 /* PVALUE Arithmetic Functions */
92 void add_pvalues(PVALUE, PVALUE, BOOLEAN*eflg, ZSTR * zerr);
93 void sub_pvalues(PVALUE, PVALUE, BOOLEAN*eflg, ZSTR * zerr);
94 void mul_pvalues(PVALUE, PVALUE, BOOLEAN*eflg, ZSTR * zerr);
95 void div_pvalues(PVALUE, PVALUE, BOOLEAN*eflg, ZSTR * zerr);
96 void mod_pvalues(PVALUE, PVALUE, BOOLEAN*eflg, ZSTR * zerr);
97 void neg_pvalue(PVALUE, BOOLEAN*eflg, ZSTR * zerr);
98 void decr_pvalue(PVALUE, BOOLEAN*eflg, ZSTR * zerr);
99 void incr_pvalue(PVALUE, BOOLEAN*eflg, ZSTR * zerr);
100 void exp_pvalues(PVALUE, PVALUE, BOOLEAN*eflg, ZSTR * zerr);
101 void gt_pvalues(PVALUE, PVALUE, BOOLEAN*eflg, ZSTR * zerr);
102 void ge_pvalues(PVALUE, PVALUE, BOOLEAN*eflg, ZSTR * zerr);
103 void lt_pvalues(PVALUE, PVALUE, BOOLEAN*eflg, ZSTR * zerr);
104 void le_pvalues(PVALUE, PVALUE, BOOLEAN*eflg, ZSTR * zerr);
105 void ne_pvalues(PVALUE, PVALUE, BOOLEAN*eflg, ZSTR * zerr);
106 void eq_pvalues(PVALUE, PVALUE, BOOLEAN*eflg, ZSTR * zerr);
107 
108 /* PVALUE Functions */
109 void bad_type_error(CNSTRING op, ZSTR *zerr, PVALUE val1, PVALUE val2);
110 void clear_pvalue(PVALUE val);
111 void coerce_pvalue(INT, PVALUE, BOOLEAN*);
112 PVALUE copy_pvalue(PVALUE);
113 PVALUE create_new_pvalue_list(void);
114 PVALUE create_new_pvalue_table(void);
115 PVALUE create_pvalue(INT type, PVALUE_DATA pvd);
116 PVALUE create_pvalue_any(void);
117 PVALUE create_pvalue_from_bool(BOOLEAN bval);
118 PVALUE create_pvalue_from_cel(INT type, CACHEEL cel);
119 PVALUE create_pvalue_from_float(float fval);
120 PVALUE create_pvalue_from_even_keynum(INT i);
121 PVALUE create_pvalue_from_fam(NODE fam);
122 PVALUE create_pvalue_from_fam_key(STRING key);
123 PVALUE create_pvalue_from_fam_keynum(INT i);
124 PVALUE create_pvalue_from_indi(NODE indi);
125 PVALUE create_pvalue_from_indi_key(CNSTRING key);
126 PVALUE create_pvalue_from_indi_keynum(INT i);
127 PVALUE create_pvalue_from_int(INT ival);
128 PVALUE create_pvalue_from_list(LIST list);
129 PVALUE create_pvalue_from_node(NODE node);
130 PVALUE create_pvalue_from_othr_keynum(INT i);
131 PVALUE create_pvalue_from_seq(INDISEQ seq);
132 PVALUE create_pvalue_from_sour_keynum(INT i);
133 PVALUE create_pvalue_from_string(CNSTRING str);
134 PVALUE create_pvalue_from_zstr(ZSTR * pzstr);
135 PVALUE create_pvalue_from_table(TABLE tab);
136 PVALUE create_pvalue_of_null_fam(void);
137 PVALUE create_pvalue_of_null_indi(void);
138 ZSTR describe_pvalue(PVALUE);
139 void delete_vptr_pvalue(VPTR ptr);
140 void delete_pvalue(PVALUE);
141 void delete_pvalue_ptr(PVALUE * valp);
142 NODE remove_node_and_delete_pvalue(PVALUE *);
143 void eq_conform_pvalues(PVALUE, PVALUE, BOOLEAN*);
144 BOOLEAN eqv_pvalues(VPTR, VPTR);
145 BOOLEAN is_node_pvalue(PVALUE value);
146 BOOLEAN is_numeric_pvalue(PVALUE);
147 BOOLEAN is_pvalue(PVALUE);
148 BOOLEAN is_record_pvalue(PVALUE);
149 BOOLEAN is_numeric_zero(PVALUE);
150 void pvalues_begin(void);
151 void pvalues_end(void);
152 
153 BOOLEAN pvalue_to_bool(PVALUE);
154 CACHEEL pvalue_to_cel(PVALUE val);
155 float pvalue_to_float(PVALUE val);
156 INT pvalue_to_int(PVALUE);
157 LIST pvalue_to_list(PVALUE val);
158 NODE pvalue_to_node(PVALUE val);
159 RECORD pvalue_to_record(PVALUE val);
160 INDISEQ pvalue_to_seq(PVALUE val);
161 STRING pvalue_to_string(PVALUE);
162 TABLE pvalue_to_table(PVALUE val);
163 struct tag_array *pvalue_to_array(PVALUE val);
164 void set_pvalue_bool(PVALUE val, BOOLEAN bv);
165 void set_pvalue_float(PVALUE val, float fnum);
166 void set_pvalue_int(PVALUE val, INT iv);
167 void set_pvalue_to_pvalue(PVALUE val, const PVALUE src);
168 void set_pvalue_seq(PVALUE val, INDISEQ seq);
169 void set_pvalue_string(PVALUE val, CNSTRING str);
170 void show_pvalue(PVALUE);
171 INT which_pvalue_type(PVALUE);
172 
173 PVALUE alloc_pvalue_memory(void);
174 void check_pvalue_validity(PVALUE val);
175 PVALUE create_new_pvalue(void);
176 void free_pvalue_memory(PVALUE val);
177 void set_pvalue_node(PVALUE val, NODE node);
178 INT pvalues_collate(PVALUE val1, PVALUE val2);
179 void init_pvalue_vtable(PVALUE val);
180 
181 #endif /* _PVALUE_H */
182