Edinburgh Speech Tools 2.4-release
named_enum_regression.cc
1 /************************************************************************/
2 /* */
3 /* Centre for Speech Technology Research */
4 /* University of Edinburgh, UK */
5 /* Copyright (c) 1996,1997 */
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: Richard Caley (rjc@cstr.ed.ac.uk) */
34 /* Date: Tue Apr 29 1997 */
35 /************************************************************************/
36 /* */
37 /* Regression test for named enum type. */
38 /* */
39 /************************************************************************/
40
41#include <iostream>
42#include "EST_TNamedEnum.h"
43#include "EST_String.h"
44
45// #if defined(__GNUC__)
46// # define InfoType EST_String
47// #else
48# define InfoType const char *
49// #endif
50
51typedef enum { c_red=1, c_blue=2, c_green=3, c_unknown=666} Colour;
52
53Start_TNamedEnumI(Colour, InfoType, ColourMap)
54 { c_unknown, {"grey"}, "Xenon"},
55 { c_red, {"red", "scarlet"}, "Mercury"},
56 { c_blue, {"blue", "navy", "sad"}, "Steel"},
57 { c_unknown, {"UNKNOWN COLOUR"}, "x"}
58End_TNamedEnumI(Colour, InfoType, ColourMap)
59
60typedef void (*PrintFn)(void);
61
62void print_q(void) { cout << "???\n"; }
63void print_1(void) { cout << "111\n"; }
64void print_2(void) { cout << "222\n"; }
65void print_3(void) { cout << "333\n"; }
66
67
68Start_TValuedEnum(Colour, PrintFn, FnColourMap)
69 { c_unknown, {print_q}},
70 { c_red, {print_1, print_3}},
71 { c_blue, {print_2}},
72 { c_unknown, {NULL}}
73End_TValuedEnum(Colour, PrintFn, FnColourMap)
74
75int main(void)
76{
77 Colour c1 = c_red;
78 Colour c2 = c_green;
79 Colour c3 = c_blue;
80 const char *n;
81
82 n = ColourMap.name(c1);
83 cout << "c1 is " << (n?n:"[NULL]") << " " << (n?EST_String(ColourMap.info(c1)):EST_String("[NULL]")) << "\n";
84
85 n = ColourMap.name(c2);
86 cout << "c2 is " << (n?n:"[NULL]") << "\n";
87
88 n = ColourMap.name(c3);
89 cout << "c3 is " << (n?n:"[NULL]") << " " << (n?EST_String(ColourMap.info(c3)):EST_String("[NULL]")) << "\n";
90
91 PrintFn fn;
92
93 cout << "print_3 ";
94 if ((fn = FnColourMap.value(FnColourMap.token(print_3))))
95 (*fn)();
96 else
97 cout << "---\n";
98
99 cout << "print_2 ";
100 if ((fn = FnColourMap.value(FnColourMap.token(print_2))))
101 (*fn)();
102 else
103 cout << "---\n";
104
105 cout << "c1 ";
106 if ((fn = FnColourMap.value(c1)))
107 (*fn)();
108 else
109 cout << "---\n";
110
111 cout << "c2 ";
112 if ((fn = FnColourMap.value(c2)))
113 (*fn)();
114 else
115 cout << "---\n";
116
117 cout << "c_unknown ";
118 if ((fn = FnColourMap.value(c_unknown)))
119 (*fn)();
120 else
121 cout << "---\n";
122
123 exit(0);
124}
125
126
127#if defined(INSTANTIATE_TEMPLATES)
128#include "../base_class/EST_TNamedEnum.cc"
129
130Instantiate_TNamedEnumI(Colour, InfoType)
131
132Instantiate_TValuedEnum(Colour, PrintFn)
133
134
135#endif