| 1 | /* |
| 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
| 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 5 | * |
| 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2019 MonetDB B.V. |
| 7 | */ |
| 8 | |
| 9 | #ifndef _SQL_ATOM_H_ |
| 10 | #define _SQL_ATOM_H_ |
| 11 | |
| 12 | #include "sql_mem.h" |
| 13 | #include "sql_types.h" |
| 14 | |
| 15 | typedef struct atom { |
| 16 | int isnull; |
| 17 | sql_subtype tpe; |
| 18 | ValRecord data; |
| 19 | dbl d; |
| 20 | int varid;/* used during code generation only */ |
| 21 | } atom; |
| 22 | |
| 23 | #define atom_null(a) (((atom*)a)->isnull) |
| 24 | |
| 25 | extern void atom_init( atom *a ); |
| 26 | extern atom *atom_bool( sql_allocator *sa, sql_subtype *tpe, bit t); |
| 27 | #ifdef HAVE_HGE |
| 28 | extern atom *atom_int( sql_allocator *sa, sql_subtype *tpe, hge val); |
| 29 | #else |
| 30 | extern atom *atom_int( sql_allocator *sa, sql_subtype *tpe, lng val); |
| 31 | #endif |
| 32 | extern atom *atom_float( sql_allocator *sa, sql_subtype *tpe, double val); |
| 33 | extern atom *atom_string( sql_allocator *sa, sql_subtype *tpe, const char *val); |
| 34 | extern atom *atom_general( sql_allocator *sa, sql_subtype *tpe, const char *val); |
| 35 | #ifdef HAVE_HGE |
| 36 | extern atom *atom_dec( sql_allocator *sa, sql_subtype *tpe, hge val, double dval); |
| 37 | #else |
| 38 | extern atom *atom_dec( sql_allocator *sa, sql_subtype *tpe, lng val, double dval); |
| 39 | #endif |
| 40 | extern atom *atom_ptr( sql_allocator *sa, sql_subtype *tpe, void *v); |
| 41 | |
| 42 | extern int atom_neg( atom *a ); |
| 43 | extern unsigned int atom_num_digits( atom *a ); |
| 44 | |
| 45 | /* duplicate atom */ |
| 46 | extern atom *atom_dup( sql_allocator *sa, atom *a); |
| 47 | |
| 48 | /* cast atom a to type tp (success == 1, fail == 0) */ |
| 49 | extern int atom_cast(sql_allocator *sa, atom *a, sql_subtype *tp); |
| 50 | |
| 51 | extern char *atom2string(sql_allocator *sa, atom *a); |
| 52 | extern char *atom2sql(atom *a); |
| 53 | extern sql_subtype *atom_type(atom *a); |
| 54 | |
| 55 | #ifdef HAVE_HGE |
| 56 | extern hge atom_get_int(atom *a); |
| 57 | #else |
| 58 | extern lng atom_get_int(atom *a); |
| 59 | #endif |
| 60 | |
| 61 | extern int atom_cmp(atom *a1, atom *a2); |
| 62 | |
| 63 | extern atom *atom_add(atom *a1, atom *a2); |
| 64 | extern atom *atom_sub(atom *a1, atom *a2); |
| 65 | extern atom *atom_mul(atom *a1, atom *a2); |
| 66 | extern int atom_inc(atom *a); |
| 67 | extern int atom_is_true(atom *a); |
| 68 | extern int atom_is_zero(atom *a); |
| 69 | |
| 70 | #ifdef HAVE_HGE |
| 71 | extern hge scales[39]; |
| 72 | #else |
| 73 | extern lng scales[19]; |
| 74 | #endif |
| 75 | |
| 76 | extern atom* atom_zero_value(sql_allocator *sa, sql_subtype* tpe); |
| 77 | |
| 78 | #endif /* _SQL_ATOM_H_ */ |
| 79 | |
| 80 | |