Edinburgh Speech Tools  2.1-release
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 ostream &operator << (ostream &s,
53 {
54  (void)e;
55  return s << "<<EST_FeatureFunctionPackage::Entry>>";
56 }
57 
58 #if defined(INSTANTIATE_TEMPLATES)
59 
60 #include "../base_class/EST_THash.cc"
61 
62 Instantiate_TStringHash_T(EST_FeatureFunctionPackage::Entry, EST_FeatureFunctionPackage_Entry)
63 
64 #endif
65 
66 int operator == (const EST_FeatureFunctionPackage::Entry &e1,
68 {
69 return e1.func == e2.func;
70 }
71 
72 EST_FeatureFunctionPackage::EST_FeatureFunctionPackage(const EST_String name, int n)
73  : p_name(name), p_entries(n)
74 {
75 #ifdef EST_DEBUGGING
76  cerr << "initialise functionon package " << p_name << "\n";
77 #endif
78 }
79 
80 EST_FeatureFunctionPackage::EST_FeatureFunctionPackage(const char *name, int n)
81  : p_name(name), p_entries(n)
82 {
83 }
84 
85 void EST_FeatureFunctionPackage::register_func(const EST_String &name,
86  const EST_Item_featfunc func)
87 {
88 #ifdef EST_DEBUGGING
89  cerr << "register " << p_name << "::" << name << "\n";
90 #endif
91  if (p_entries.present(name))
92  EST_warning("Feature function %s::%s redefined",
93  (const char *)p_name,
94  (const char *)name);
95 
96  Entry e;
97  e.func=func;
98  p_entries.add_item(name, e);
99 }
100 
101 const EST_FeatureFunctionPackage::Entry &EST_FeatureFunctionPackage::lookup(const EST_String &name, int &found) const
102 {
103  found=0;
104  return p_entries.val(name, found);
105 }
106 
107 const EST_String EST_FeatureFunctionPackage::lookup(const EST_Item_featfunc func, int &found) const
108 {
110 
111  for(p.begin(p_entries); p; ++p)
112  if (p->v.func == func)
113  {
114  found=1;
115  return p->k;
116  }
117  found=0;
118  return "";
119 }
void begin(const Container &over)
Set the iterator ready to run over this container.
An open hash table. The number of buckets should be set to allow enough space that there are relative...
Definition: EST_THash.h:71