1/*************************************************************************/
2/* */
3/* Language Technologies Institute */
4/* Carnegie Mellon University */
5/* Copyright (c) 1999 */
6/* All Rights Reserved. */
7/* */
8/* Permission is hereby granted, free of charge, to use and distribute */
9/* this software and its documentation without restriction, including */
10/* without limitation the rights to use, copy, modify, merge, publish, */
11/* distribute, sublicense, and/or sell copies of this work, and to */
12/* permit persons to whom this work is furnished to do so, subject to */
13/* the following conditions: */
14/* 1. The code must retain the above copyright notice, this list of */
15/* conditions and the following disclaimer. */
16/* 2. Any modifications must be clearly marked as such. */
17/* 3. Original authors' names are not deleted. */
18/* 4. The authors' names are not used to endorse or promote products */
19/* derived from this software without specific prior written */
20/* permission. */
21/* */
22/* CARNEGIE MELLON UNIVERSITY AND THE CONTRIBUTORS TO THIS WORK */
23/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
24/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
25/* SHALL CARNEGIE MELLON UNIVERSITY NOR THE CONTRIBUTORS BE LIABLE */
26/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
27/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
28/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
29/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
30/* THIS SOFTWARE. */
31/* */
32/*************************************************************************/
33/* Author: Alan W Black (awb@cs.cmu.edu) */
34/* Date: December 1999 */
35/*************************************************************************/
36/* */
37/* Macros for user defined type objects */
38/* */
39/*************************************************************************/
40#ifndef _CST_VAL_DEFS_H__
41#define _CST_VAL_DEFS_H__
42
43#include <stdlib.h>
44
45/* Macro for defining new user structs as vals */
46#define CST_VAL_USER_TYPE_DCLS(NAME,TYPE) \
47extern const int cst_val_type_##NAME; \
48TYPE *val_##NAME(const cst_val *v); \
49cst_val *NAME##_val(const TYPE *v);
50
51#define CST_VAL_USER_FUNCPTR_DCLS(NAME,TYPE) \
52extern const int cst_val_type_##NAME; \
53TYPE val_##NAME(const cst_val *v); \
54cst_val *NAME##_val(const TYPE v);
55
56#define CST_VAL_REGISTER_TYPE(NAME,TYPE) \
57TYPE *val_##NAME(const cst_val *v) \
58{ \
59 return (TYPE *)val_generic(v,cst_val_type_##NAME,#NAME); \
60} \
61void val_delete_##NAME(void *v) \
62{ \
63 delete_##NAME((TYPE *)v); \
64} \
65 \
66cst_val *NAME##_val(const TYPE *v) \
67{ \
68 return val_new_typed(cst_val_type_##NAME, \
69 (void *)v); \
70} \
71
72#define CST_VAL_REG_TD_TYPE(NAME,TYPE,NUM) \
73extern const int cst_val_type_##NAME; \
74const int cst_val_type_##NAME=NUM; \
75void val_delete_##NAME(void *v); \
76
77/* When objects of this type can never be owned by vals */
78#define CST_VAL_REGISTER_TYPE_NODEL(NAME,TYPE) \
79TYPE *val_##NAME(const cst_val *v) \
80{ \
81 return (TYPE *)val_generic(v,cst_val_type_##NAME,#NAME); \
82} \
83 \
84cst_val *NAME##_val(const TYPE *v) \
85{ \
86 return val_new_typed(cst_val_type_##NAME, \
87 (void *)v); \
88} \
89
90#define CST_VAL_REG_TD_TYPE_NODEL(NAME,TYPE,NUM) \
91extern const int cst_val_type_##NAME; \
92const int cst_val_type_##NAME=NUM; \
93void val_delete_##NAME(void *v) { (void)v; } \
94
95#define CST_VAL_REGISTER_FUNCPTR(NAME,TYPE) \
96TYPE val_##NAME(const cst_val *v) \
97{ \
98 return (TYPE)val_generic(v,cst_val_type_##NAME,#NAME); \
99} \
100 \
101cst_val *NAME##_val(const TYPE v) \
102{ \
103 return val_new_typed(cst_val_type_##NAME, \
104 (void *)v); \
105} \
106
107#define CST_VAL_REG_TD_FUNCPTR(NAME,TYPE,NUM) \
108extern const int cst_val_type_##NAME; \
109const int cst_val_type_##NAME=NUM; \
110void val_delete_##NAME(void *v) { (void)v; } \
111
112#endif
113

source code of include/flite/cst_val_defs.h