Edinburgh Speech Tools  2.4-release
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends Pages
EST_FeatureFunctionPackage.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  /* */
34  /* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
35  /* -------------------------------------------------------------------- */
36  /* Represents a set of feature functions. */
37  /* */
38  /*************************************************************************/
39 
40 #include "ling_class/EST_Item.h"
41 #include "ling_class/EST_FeatureFunctionPackage.h"
42 
43 
44 static EST_Val Dummy_Func(EST_Item *) { return EST_Val(); }
45 static struct EST_FeatureFunctionPackage::Entry Dummy_Entry = { Dummy_Func };
46 template <> EST_String
50 
51 
52 ostream &operator << (ostream &s,
54 {
55  (void)e;
56  return s << "<<EST_FeatureFunctionPackage::Entry>>";
57 }
58 
59 #if defined(INSTANTIATE_TEMPLATES)
60 
61 #include "../base_class/EST_THash.cc"
62 
63 Instantiate_TStringHash_T(EST_FeatureFunctionPackage::Entry, EST_FeatureFunctionPackage_Entry)
64 
65 #endif
66 
67 int operator == (const EST_FeatureFunctionPackage::Entry &e1,
69 {
70 return e1.func == e2.func;
71 }
72 
73 
74 EST_FeatureFunctionPackage::EST_FeatureFunctionPackage(const EST_String name, int n)
75  : p_name(name), p_entries(n)
76 {
77 #ifdef EST_DEBUGGING
78  cerr << "initialise functionon package " << p_name << "\n";
79 #endif
80 }
81 
82 EST_FeatureFunctionPackage::EST_FeatureFunctionPackage(const char *name, int n)
83  : p_name(name), p_entries(n)
84 {
85 }
86 
87 void EST_FeatureFunctionPackage::register_func(const EST_String &name,
88  const EST_Item_featfunc func)
89 {
90 #ifdef EST_DEBUGGING
91  cerr << "register " << p_name << "::" << name << "\n";
92 #endif
93  if (p_entries.present(name))
94  EST_warning("Feature function %s::%s redefined",
95  (const char *)p_name,
96  (const char *)name);
97 
98  Entry e;
99  e.func=func;
100  p_entries.add_item(name, e);
101 }
102 
103 const EST_FeatureFunctionPackage::Entry &EST_FeatureFunctionPackage::lookup(const EST_String &name, int &found) const
104 {
105  found=0;
106  return p_entries.val(name, found);
107 }
108 
109 const EST_String EST_FeatureFunctionPackage::lookup(const EST_Item_featfunc func, int &found) const
110 {
112 
113  for(p.begin(p_entries); p; ++p)
114  if (p->v.func == func)
115  {
116  found=1;
117  return p->k;
118  }
119  found=0;
120  return "";
121 }