Edinburgh Speech Tools  2.1-release
EST_Featured.h
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 
34 
35 #ifndef __EST_FEATURED_H__
36 #define __EST_FEATURED_H__
37 
38 
39 #include "EST_Features.h"
40 
41 /** A class with the mechanisms needed to give an object features and
42  * access them nicely. Used as a parent class.
43  *
44  * @author Richard Caley <rjc@cstr.ed.ac.uk>
45  * @version $Id: EST_Featured.h,v 1.3 2004/05/04 00:00:16 awb Exp $ */
46 
47 class EST_Featured {
48 private:
49 
50  EST_Features *p_features;
51 
52 protected:
53 
54  EST_Featured(void);
55  EST_Featured(const EST_Featured &f);
56  ~EST_Featured(void);
57 
58  void init_features();
59 
60  void copy_features(const EST_Featured &f);
61 
62  void clear_features();
63 
64  void ensure_features(void)
65  { if (p_features==NULL) p_features= new EST_Features; }
66 
67 public:
68 
69  int f_Int(const char *name, int def) const
70  { return p_features?p_features->I(name, def):def; }
71  int f_Int(const char *name) const
72  { return p_features?p_features->I(name):0; }
73  int f_I(const char *name, int def) const
74  {return f_Int(name, def);}
75  int f_I(const char *name) const
76  {return f_Int(name);}
77  void f_set(const EST_String name, int val)
78  { ensure_features(); p_features->set(name, val); }
79  void f_set_path(const EST_String name, int val)
80  { ensure_features(); p_features->set_path(name, val); }
81 
82 
83  float f_Float(const char *name, float def) const
84  { return p_features?p_features->F(name, def):def; }
85  float f_Float(const char *name) const
86  { return p_features?p_features->F(name):0.0; }
87  float f_F(const char *name, float def) const
88  {return f_Float(name, def);}
89  float f_F(const char *name) const
90  {return f_Float(name);}
91  void f_set(const EST_String name, float val)
92  { ensure_features(); p_features->set(name, val); }
93  void f_set_path(const EST_String name, float val)
94  { ensure_features(); p_features->set_path(name, val); }
95 
96 
97  EST_String f_String(const char *name, const EST_String &def) const
98  { return p_features?p_features->S(name, def):def; }
99  EST_String f_String(const char *name) const
100  { return p_features?p_features->S(name):EST_String::Empty; }
101  EST_String f_S(const char *name, const EST_String &def) const
102  {return f_String(name, def);}
103  EST_String f_S(const char *name) const
104  {return f_String(name);}
105  void f_set(const EST_String name, const char *val)
106  { ensure_features(); p_features->set(name, val); }
107  void f_set_path(const EST_String name, const char *val)
108  { ensure_features(); p_features->set_path(name, val); }
109 
110 
111  const EST_Val &f_Val(const char *name, const EST_Val &def) const;
112  const EST_Val &f_Val(const char *name) const;
113 
114  const EST_Val &f_V(const char *name, const EST_Val &def) const
115  {return f_Val(name, def);}
116  const EST_Val &f_V(const char *name) const
117  {return f_Val(name);}
118  void f_set_val(const EST_String name, EST_Val val)
119  { ensure_features(); p_features->set_val(name, val); }
120  void f_set_path(const EST_String name, EST_Val val)
121  { ensure_features(); p_features->set_path(name, val); }
122 
123  void f_set(const EST_Features &f)
124  { ensure_features(); *p_features = f; }
125 
126  int f_present(const EST_String name) const
127  {return p_features && p_features->present(name); }
128 
129  void f_remove(const EST_String name)
130  { if (p_features) p_features->remove(name); }
131 
132  // iteration
133 
134  protected:
136 // struct IPointer_feat { EST_TRwStructIterator< EST_Features, EST_Features::IPointer, EST_Features::Entry> i; };
137 
138  void point_to_first(IPointer_feat &ip) const
139  { if (p_features) ip.i.begin(*p_features);}
141  { ++(ip.i); }
142  bool points_to_something(const IPointer_feat &ip) const
143  { return ip.i != 0; }
145  { return *(ip.i); }
146 
151 
152 public:
156 
157 
158 
159 };
160 
161 #endif
162 
void set_val(const EST_String &name, const EST_Val &sval)
Definition: EST_Features.h:217
void set(const EST_String &name, int ival)
Definition: EST_Features.h:186
void set_path(const EST_String &name, const EST_Val &sval)
const EST_String S(const EST_String &path) const
Definition: EST_Features.h:158
void begin(Container &over)
Set the iterator ready to run over this container.
Templated Key-Value Item. Serves as the items in the list of the EST_TKVL class.
Definition: EST_TKVL.h:55
void remove(const EST_String &name)
Definition: EST_Features.h:247
NULL
Definition: EST_WFST.cc:55
int present(const EST_String &name) const
f
Definition: EST_item_aux.cc:48
int I(const EST_String &path) const
Definition: EST_Features.h:147
static const EST_String Empty
Constant empty string.
Definition: EST_String.h:110
float F(const EST_String &path) const
Definition: EST_Features.h:136