Edinburgh Speech Tools  2.1-release
kvl_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  /* Permission is hereby granted, free of charge, to use and distribute */
8  /* this software and its documentation without restriction, including */
9  /* without limitation the rights to use, copy, modify, merge, publish, */
10  /* distribute, sublicense, and/or sell copies of this work, and to */
11  /* permit persons to whom this work is furnished to do so, subject to */
12  /* the following conditions: */
13  /* 1. The code must retain the above copyright notice, this list of */
14  /* conditions and the following disclaimer. */
15  /* 2. Any modifications must be clearly marked as such. */
16  /* 3. Original authors' names are not deleted. */
17  /* 4. The authors' names are not used to endorse or promote products */
18  /* derived from this software without specific prior written */
19  /* permission. */
20  /* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
21  /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
22  /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
23  /* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
24  /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
25  /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
26  /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
27  /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
28  /* THIS SOFTWARE. */
29  /* */
30  /*************************************************************************/
31  /* */
32  /* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
33  /* Date: Tue Jul 22 1997 */
34  /* --------------------------------------------------------------------- */
35  /* Example of list class use. */
36  /* */
37  /*************************************************************************/
38 
39 #include <cstdlib>
40 #include <iostream>
41 #include "EST_TKVL.h"
42 #include "EST_Option.h"
43 #include "EST_util_class.h"
44 #include "EST_types.h"
45 
46 using namespace std;
47 
48 
49 /**@name key_value_example
50  *
51  * some stuff about lists
52  *
53  * @see EST_KVL
54  * @see EST_KVI
55  * @see EST_Option
56  */
57 //@{
58 
59 
60 int main(void)
61 {
62  EST_StrStr_KVL kvl; // decl
63 
64  /**@name Addition
65  */
66  //@{
67 
68  // add item simply appends key value pairs onto the end of the list.
69  // This function is useful for the initial building of a list.
70  kvl.add_item("street", "South Bbridge");
71  kvl.add_item("city", "Edinburgh");
72  kvl.add_item("post code", "EH1 1HN");
73  kvl.add_item("country", "United Kingdom");
74 
75  // by default, if a new entry has the same key name as an existing key,
76  // it will not overwrite this, leaving 2 items with the same key.
77  // The first will be the one accessed.
78  // You can overwrite existing keys by adding a flag to this function.
79  // Note that this is much slower as all the existing keys must
80  // be checked.
81  kvl.add_item("country", "Scotland", 1);
82 
83  // This is equivalent to the change_item function, which is
84  // used to overwrite existing entries:
85 
86  kvl.add_item("country", "Caledonia", 1);
87 
88  // Items are accessed by the val function, indexed by the key:
89  // This prints the value associated with the key "country".
90  cout << kvl.val("country") << endl;
91 
92  // An error is given if the key doesn't exist:
93  cout << kvl.val("state") << endl;
94 
95  // This can be turned off by use of a flag. In this case the default
96  // value is returned.
97 
98  cout << kvl.val("state", 0) << endl;
99 
100  // A on-the fly default value can be specified by putting using the
101  // val_def function:
102 
103  cout << kvl.val_def("state", "unknown") << endl;
104 
105  // present() returns true of the key exists:
106  if (kvl.present("state"))
107  cout << kvl.val("state") << endl;
108 
109  //@}
110 
111 }
112 
int main(int argc, char **argv)
Definition: align_main.cc:69
const V & val_def(const K &rkey, const V &def) const
value or default
Definition: EST_TKVL.cc:151
const V & val(const K &rkey, bool m=0) const
return value according to key (const)
Definition: EST_TKVL.cc:145
int add_item(const K &rkey, const V &rval, int no_search=0)
add key-val pair to list
Definition: EST_TKVL.cc:248
int present(const K &rkey) const
Returns true if key is present.
Definition: EST_TKVL.cc:222