| 1 | /* |
| 2 | * Copyright 2009 Red Hat Inc., Durham, North Carolina. |
| 3 | * All Rights Reserved. |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2.1 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Lesser General Public |
| 16 | * License along with this library; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | * |
| 19 | * Authors: |
| 20 | * "Daniel Kopecek" <[email protected]> |
| 21 | */ |
| 22 | |
| 23 | #pragma once |
| 24 | #ifndef _SEXP_DATATYPE |
| 25 | #define _SEXP_DATATYPE |
| 26 | |
| 27 | #include "public/sexp-datatype.h" |
| 28 | #include "generic/rbt/rbt.h" |
| 29 | #include "../../../common/util.h" |
| 30 | |
| 31 | |
| 32 | struct SEXP_datatype { |
| 33 | uint16_t dt_flg; |
| 34 | uint8_t _dt[]; |
| 35 | }; |
| 36 | |
| 37 | #define SEXP_DTFLG_LOCALDATA 0x01 /* whether a extended pointer should be used */ |
| 38 | #define SEXP_DTFLG_HAVEDTOPS 0x02 /* whether there are defined some operations */ |
| 39 | |
| 40 | struct SEXP_datatype_ops { |
| 41 | uint16_t dt_opcnt; |
| 42 | SEXP_datatypeOP_t *dt_op; |
| 43 | }; |
| 44 | |
| 45 | struct SEXP_datatypeTbl { |
| 46 | rbt_t *tree; |
| 47 | }; |
| 48 | |
| 49 | /* |
| 50 | * Datatype pointer |
| 51 | */ |
| 52 | typedef struct rbt_str_node SEXP_datatypePtr_t; |
| 53 | |
| 54 | /* |
| 55 | * Extended datatype pointer |
| 56 | */ |
| 57 | struct SEXP_datatype_extptr { |
| 58 | struct rbt_str_node *n; /* datatype tree node */ |
| 59 | void *l; /* local data related to an S-exp reference */ |
| 60 | }; |
| 61 | |
| 62 | typedef struct SEXP_datatype_extptr SEXP_datatypeExtptr_t; |
| 63 | |
| 64 | |
| 65 | const char *SEXP_datatype_name(SEXP_datatypePtr_t *p); |
| 66 | |
| 67 | void SEXP_datatype_once(void); |
| 68 | void SEXP_datatypeGlobalTbl_init(void); |
| 69 | void SEXP_datatypeGlobalTbl_free(void); |
| 70 | |
| 71 | SEXP_datatypeTbl_t *SEXP_datatypeTbl_new (void); |
| 72 | int SEXP_datatypeTbl_init(SEXP_datatypeTbl_t *t); |
| 73 | void SEXP_datatypeTbl_free(SEXP_datatypeTbl_t *t); |
| 74 | |
| 75 | SEXP_datatypePtr_t *SEXP_datatype_get(SEXP_datatypeTbl_t *t, const char *name); |
| 76 | SEXP_datatypePtr_t *SEXP_datatype_add(SEXP_datatypeTbl_t *t, char *name); |
| 77 | int SEXP_datatype_del(SEXP_datatypeTbl_t *t, const char *name); |
| 78 | |
| 79 | #define SEXP_OP_CONTINUE 0 /* continue with the default handler */ |
| 80 | #define SEXP_OP_ABORT 1 /* abort with an error status */ |
| 81 | #define SEXP_OP_RETURN 2 /* return success, don't execute default handler */ |
| 82 | |
| 83 | #define SEXP_DATATYPEPTR_MASK (UINTPTR_MAX << 2) |
| 84 | #define SEXP_DATATYPEPTR_ALIGN (4 > sizeof(void *) ? 4 : sizeof (void *)) |
| 85 | |
| 86 | |
| 87 | #endif /* _SEXP_DATATYPE */ |