Edinburgh Speech Tools
2.1-release
named_enum_regression.cc
Go to the documentation of this file.
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
using namespace
std
;
46
47
#define InfoType const char *
48
49
typedef
enum
{
c_red
=1,
c_blue
=2,
c_green
=3,
c_unknown
=666}
Colour
;
50
51
Start_TNamedEnumI
(
Colour
,
InfoType
,
ColourMap
)
52
{
c_unknown
, {
"grey"
},
"Xenon"
},
53
{
c_red
, {
"red"
,
"scarlet"
},
"Mercury"
},
54
{
c_blue
, {
"blue"
,
"navy"
,
"sad"
},
"Steel"
},
55
{
c_unknown
, {
"UNKNOWN COLOUR"
},
"x"
}
56
End_TNamedEnumI
(
Colour
,
InfoType
,
ColourMap
)
57
58
typedef
void (*PrintFn)(void);
59
60
void
print_q
(
void
) { cout <<
"???\n"
; }
61
void
print_1
(
void
) { cout <<
"111\n"
; }
62
void
print_2
(
void
) { cout <<
"222\n"
; }
63
void
print_3
(
void
) { cout <<
"333\n"
; }
64
65
66
Start_TValuedEnum
(
Colour
, PrintFn, FnColourMap)
67
{
c_unknown
, {
print_q
},0},
68
{
c_red
, {
print_1
,
print_3
},0},
69
{
c_blue
, {
print_2
},0},
70
{
c_unknown
, {
NULL
},0}
71
End_TValuedEnum
(
Colour
, PrintFn, FnColourMap)
72
73
int
main
(
void
)
74
{
75
Colour
c1 =
c_red
;
76
Colour
c2 =
c_green
;
77
Colour
c3 =
c_blue
;
78
const
char
*n;
79
80
n =
ColourMap
.name(c1);
81
cout <<
"c1 is "
<< (n?n:
"[NULL]"
) <<
" "
<< (n?
EST_String
(
ColourMap
.info(c1)):
EST_String
(
"[NULL]"
)) <<
"\n"
;
82
83
n =
ColourMap
.name(c2);
84
cout <<
"c2 is "
<< (n?n:
"[NULL]"
) <<
"\n"
;
85
86
n =
ColourMap
.name(c3);
87
cout <<
"c3 is "
<< (n?n:
"[NULL]"
) <<
" "
<< (n?
EST_String
(
ColourMap
.info(c3)):
EST_String
(
"[NULL]"
)) <<
"\n"
;
88
89
PrintFn fn;
90
91
cout <<
"print_3 "
;
92
if
((fn = FnColourMap.value(FnColourMap.token(
print_3
))))
93
(*fn)();
94
else
95
cout <<
"---\n"
;
96
97
cout <<
"print_2 "
;
98
if
((fn = FnColourMap.value(FnColourMap.token(
print_2
))))
99
(*fn)();
100
else
101
cout <<
"---\n"
;
102
103
cout <<
"c1 "
;
104
if
((fn = FnColourMap.value(c1)))
105
(*fn)();
106
else
107
cout <<
"---\n"
;
108
109
cout <<
"c2 "
;
110
if
((fn = FnColourMap.value(c2)))
111
(*fn)();
112
else
113
cout <<
"---\n"
;
114
115
cout <<
"c_unknown "
;
116
if
((fn = FnColourMap.value(
c_unknown
)))
117
(*fn)();
118
else
119
cout <<
"---\n"
;
120
121
exit(0);
122
}
123
124
125
#if defined(INSTANTIATE_TEMPLATES)
126
#include "../base_class/EST_TNamedEnum.cc"
127
128
Instantiate_TNamedEnumI
(
Colour
,
InfoType
)
129
130
Instantiate_TValuedEnum
(
Colour
, PrintFn)
131
132
133
#endif
Instantiate_TValuedEnum
#define Instantiate_TValuedEnum(ENUM, VAL)
Definition:
EST_TNamedEnumI.h:67
c_red
Definition:
named_enum_regression.cc:49
print_1
void print_1(void)
Definition:
named_enum_regression.cc:61
c_green
Definition:
named_enum_regression.cc:49
std
End_TNamedEnumI
#define End_TNamedEnumI(ENUM, INFO, NAME)
Definition:
EST_TNamedEnumI.h:132
EST_TNamedEnum.h
main
int main(int argc, char **argv)
Definition:
align_main.cc:69
c_blue
Definition:
named_enum_regression.cc:49
c_unknown
Definition:
named_enum_regression.cc:49
print_2
void print_2(void)
Definition:
named_enum_regression.cc:62
NULL
NULL
Definition:
EST_WFST.cc:55
Instantiate_TNamedEnumI
#define Instantiate_TNamedEnumI(ENUM, INFO)
Definition:
EST_TNamedEnumI.h:72
EST_String.h
print_q
void print_q(void)
Definition:
named_enum_regression.cc:60
End_TValuedEnum
#define End_TValuedEnum(ENUM, VAL, NAME)
Definition:
EST_TNamedEnumI.h:149
Start_TValuedEnum
Start_TValuedEnum(Colour, PrintFn, FnColourMap)
Definition:
named_enum_regression.cc:66
Colour
Colour
Definition:
named_enum_regression.cc:49
InfoType
#define InfoType
Definition:
named_enum_regression.cc:47
EST_String
EST_String
Definition:
EST_features_aux.cc:50
ColourMap
EST_TNamedEnum< Colour > ColourMap
Colour
Colour
Definition:
named_enum_example.cc:69
Start_TNamedEnumI
Start_TNamedEnumI(Colour, InfoType, ColourMap)
Definition:
named_enum_regression.cc:51
print_3
void print_3(void)
Definition:
named_enum_regression.cc:63
testsuite
named_enum_regression.cc
Generated on Fri Oct 6 2017 18:25:29 for Edinburgh Speech Tools by
1.8.11