Edinburgh Speech Tools  2.1-release
EST_Option.h
Go to the documentation of this file.
1 /*************************************************************************/
2 /* */
3 /* Centre for Speech Technology Research */
4 /* University of Edinburgh, UK */
5 /* Copyright (c) 1994,1995,1996 */
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 : Paul Taylor */
34 /* Date : September 1994 */
35 /*-----------------------------------------------------------------------*/
36 /* EST_Option Class header file */
37 /* */
38 /*=======================================================================*/
39 
40 #ifndef __EST_OPTION_H__
41 #define __EST_OPTION_H__
42 
43 #include "EST_String.h"
44 #include "EST_TKVL.h"
45 #include "EST_rw_status.h"
46 
47 /** Provide a high level interface for String String key value lists.
48 */
49 
50 class EST_Option: public EST_TKVL<EST_String, EST_String> {
51 public:
52  /// add prefix to every key
53  void add_prefix(EST_String prefix);
54  /// remove prefix from every key
55  void remove_prefix(EST_String prefix);
56 
57  /** read keyval list from file. The file type is an ascii file
58  with each line representing one key value pair. The first entry in
59  the line defines the key, and the rest, which may contain
60  whitespaces, defins the value. Lines starting with the comment
61  character are ignored.
62  @return returns EST_read_status errors, @see */
63  EST_read_status load(const EST_String &filename, const EST_String &comment = ";");
64 
65  /// add to end of list or overwrite. If rval is empty, do nothing
66  int override_val(const EST_String rkey, const EST_String rval);
67  /// add to end of list or overwrite. If rval is empty, do nothing
68  int override_fval(const EST_String rkey, const float rval);
69  /// add to end of list or overwrite. If rval is empty, do nothing
70  int override_ival(const EST_String rkey, const int rval);
71 
72  /** return value of type int relating to key. By default,
73  an error occurs if the key is not present. Use m=0 if
74  to get a dummy value returned if key is not present */
75  int ival(const EST_String &rkey, int m=1) const;
76 
77  /** return value of type float relating to key. By default,
78  an error occurs if the key is not present. Use m=0 if
79  to get a dummy value returned if key is not present */
80  double dval(const EST_String &rkey, int m=1) const;
81 
82  /** return value of type float relating to key. By default,
83  an error occurs if the key is not present. Use m=0 if
84  to get a dummy value returned if key is not present */
85  float fval(const EST_String &rkey, int m=1) const;
86 
87  /** return value of type String relating to key. By default,
88  an error occurs if the key is not present. Use m=0 if
89  to get a dummy value returned if key is not present */
90  const EST_String &sval(const EST_String &rkey, int m=1) const;
91 
92  /** return value of type String relating to key. By default,
93  an error occurs if the key is not present. Use m=0 if
94  to get a dummy value returned if key is not present */
95 // const EST_String &val(const EST_String &rkey, int m=1) const
96 // { return sval(rkey,m); }
97 
98  int add_iitem(const EST_String &rkey, const int &rval);
99  int add_fitem(const EST_String &rkey, const float &rval);
100 
101  /// print options
102  friend ostream& operator << (ostream& s, const EST_Option &kv);
103 };
104 
105 #endif // __EST_OPTION_H__
void remove_prefix(EST_String prefix)
remove prefix from every key
Definition: EST_Option.cc:184
friend ostream & operator<<(ostream &s, const EST_Option &kv)
print options
Definition: EST_Option.cc:189
int add_iitem(const EST_String &rkey, const int &rval)
Definition: EST_Option.cc:126
int override_ival(const EST_String rkey, const int rval)
add to end of list or overwrite. If rval is empty, do nothing
Definition: EST_Option.cc:72
int override_val(const EST_String rkey, const EST_String rval)
add to end of list or overwrite. If rval is empty, do nothing
Definition: EST_Option.cc:54
int ival(const EST_String &rkey, int m=1) const
Definition: EST_Option.cc:82
int override_fval(const EST_String rkey, const float rval)
add to end of list or overwrite. If rval is empty, do nothing
Definition: EST_Option.cc:62
double dval(const EST_String &rkey, int m=1) const
Definition: EST_Option.cc:115
float fval(const EST_String &rkey, int m=1) const
Definition: EST_Option.cc:104
int add_fitem(const EST_String &rkey, const float &rval)
Definition: EST_Option.cc:133
const EST_String & sval(const EST_String &rkey, int m=1) const
Definition: EST_Option.cc:93
EST_read_status load(const EST_String &filename, const EST_String &comment=";")
Definition: EST_Option.cc:144
Templated Key-Value list. Objects of type EST_TKVL contain lists which are accessed by a key of type ...
Definition: EST_TKVL.h:73
void add_prefix(EST_String prefix)
add prefix to every key
Definition: EST_Option.cc:176
EST_read_status