Edinburgh Speech Tools 2.4-release
EST_Val_defs.h
1/*************************************************************************/
2/* */
3/* Centre for Speech Technology Research */
4/* University of Edinburgh, UK */
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/* THE UNIVERSITY OF EDINBURGH 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 THE UNIVERSITY OF EDINBURGH 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 */
34/* Date : March 1999 */
35/*-----------------------------------------------------------------------*/
36/* */
37/* Macros definitions for defining anything as vals */
38/* */
39/*=======================================================================*/
40#ifndef __EST_VAL_DEFS_H__
41#define __EST_VAL_DEFS_H__
42
43/* Macro for defining new class as values public functions */
44#define VAL_REGISTER_CLASS_DCLS(NAME,CLASS) \
45extern val_type val_type_##NAME; \
46class CLASS *NAME(const EST_Val &v); \
47EST_Val est_val(const class CLASS *v);
48
49/* For things that aren't classes (typed def something else) */
50#define VAL_REGISTER_TYPE_DCLS(NAME,CLASS) \
51extern val_type val_type_##NAME; \
52CLASS *NAME(const EST_Val &v); \
53EST_Val est_val(const CLASS *v);
54
55#define VAL_REGISTER_FUNCPTR_DCLS(NAME,TYPE) \
56extern val_type val_type_##NAME; \
57TYPE NAME(const EST_Val &v); \
58EST_Val est_val(const TYPE v);
59
60
61/* Macro for defining new class as values */
62#define VAL_REGISTER_CLASS(NAME,CLASS) \
63val_type val_type_##NAME=#NAME; \
64class CLASS *NAME(const EST_Val &v) \
65{ \
66 if (v.type() == val_type_##NAME) \
67 return (class CLASS *)v.internal_ptr(); \
68 else \
69 EST_error("val not of type val_type_"#NAME); \
70 return NULL; \
71} \
72 \
73static void val_delete_##NAME(void *v) \
74{ \
75 delete (class CLASS *)v; \
76} \
77 \
78EST_Val est_val(const class CLASS *v) \
79{ \
80 return EST_Val(val_type_##NAME, \
81 (void *)v,val_delete_##NAME); \
82} \
83
84/* Macro for defining new typedef'd things as vals */
85/* You don't need CLASS and TYPE but it often convenient */
86#define VAL_REGISTER_TYPE(NAME,CLASS) \
87val_type val_type_##NAME=#NAME; \
88CLASS *NAME(const EST_Val &v) \
89{ \
90 if (v.type() == val_type_##NAME) \
91 return (CLASS *)v.internal_ptr(); \
92 else \
93 EST_error("val not of type val_type_"#NAME); \
94 return NULL; \
95} \
96 \
97static void val_delete_##NAME(void *v) \
98{ \
99 delete (CLASS *)v; \
100} \
101 \
102EST_Val est_val(const CLASS *v) \
103{ \
104 return EST_Val(val_type_##NAME, \
105 (void *)v,val_delete_##NAME); \
106} \
107
108/* Macro for defining new typedef'd things as vals that don't get deleted */
109/* You don't need CLASS and TYPE but it often convenient */
110#define VAL_REGISTER_TYPE_NODEL(NAME,CLASS) \
111val_type val_type_##NAME=#NAME; \
112CLASS *NAME(const EST_Val &v) \
113{ \
114 if (v.type() == val_type_##NAME) \
115 return (CLASS *)v.internal_ptr(); \
116 else \
117 EST_error("val not of type val_type_"#NAME); \
118 return NULL; \
119} \
120 \
121static void val_delete_##NAME(void *v) \
122{ \
123 (void)v; \
124} \
125 \
126EST_Val est_val(const CLASS *v) \
127{ \
128 return EST_Val(val_type_##NAME, \
129 (void *)v,val_delete_##NAME); \
130} \
131
132/* Macro for defining new class as values */
133#define VAL_REGISTER_CLASS_NODEL(NAME,CLASS) \
134val_type val_type_##NAME=#NAME; \
135class CLASS *NAME(const EST_Val &v) \
136{ \
137 if (v.type() == val_type_##NAME) \
138 return (class CLASS *)v.internal_ptr(); \
139 else \
140 EST_error("val not of type val_type_"#NAME); \
141 return NULL; \
142} \
143 \
144static void val_delete_##NAME(void *v) \
145{ \
146 (void)v; \
147} \
148 \
149EST_Val est_val(const class CLASS *v) \
150{ \
151 return EST_Val(val_type_##NAME, \
152 (void *)v,val_delete_##NAME); \
153} \
154
155/* Macro for defining function pointers as values */
156#define VAL_REGISTER_FUNCPTR(NAME,CLASS) \
157val_type val_type_##NAME=#NAME; \
158CLASS NAME(const EST_Val &v) \
159{ \
160 if (v.type() == val_type_##NAME) \
161 return (CLASS)v.internal_ptr(); \
162 else \
163 EST_error("val not of type val_type_"#NAME); \
164 return NULL; \
165} \
166 \
167static void val_delete_##NAME(void *v) \
168{ \
169 (void)v; \
170} \
171 \
172EST_Val est_val(const CLASS v) \
173{ \
174 return EST_Val(val_type_##NAME, \
175 (void *)v,val_delete_##NAME); \
176} \
177
178
179
180#endif