Edinburgh Speech Tools 2.4-release
 
Loading...
Searching...
No Matches
kvl_regression.cc
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/**@name key_value_example
47 *
48 * some stuff about lists
49 *
50 * @see EST_KVL
51 * @see EST_KVI
52 * @see EST_Option
53 */
54//@{
55
56
57int main(void)
58{
59 EST_StrStr_KVL kvl; // decl
60
61 /**@name Addition
62 */
63 //@{
64
65 // add item simply appends key value pairs onto the end of the list.
66 // This function is useful for the initial building of a list.
67 kvl.add_item("street", "South Bbridge");
68 kvl.add_item("city", "Edinburgh");
69 kvl.add_item("post code", "EH1 1HN");
70 kvl.add_item("country", "United Kingdom");
71
72 // by default, if a new entry has the same key name as an existing key,
73 // it will not overwrite this, leaving 2 items with the same key.
74 // The first will be the one accessed.
75 // You can overwrite existing keys by adding a flag to this function.
76 // Note that this is much slower as all the existing keys must
77 // be checked.
78 kvl.add_item("country", "Scotland", 1);
79
80 // This is equivalent to the change_item function, which is
81 // used to overwrite existing entries:
82
83 kvl.add_item("country", "Caledonia", 1);
84
85 // Items are accessed by the val function, indexed by the key:
86 // This prints the value associated with the key "country".
87 cout << kvl.val("country") << endl;
88
89 // An error is given if the key doesn't exist:
90 cout << kvl.val("state") << endl;
91
92 // This can be turned off by use of a flag. In this case the default
93 // value is returned.
94
95 cout << kvl.val("state", 0) << endl;
96
97 // A on-the fly default value can be specified by putting using the
98 // val_def function:
99
100 cout << kvl.val_def("state", "unknown") << endl;
101
102 // present() returns true of the key exists:
103 if (kvl.present("state"))
104 cout << kvl.val("state") << endl;
105
106 //@}
107
108}
109
int add_item(const K &rkey, const V &rval, int no_search=0)
add key-val pair to list
Definition EST_TKVL.cc:248
const V & val(const K &rkey, bool m=0) const
return value according to key (const)
Definition EST_TKVL.cc:145
const int present(const K &rkey) const
Returns true if key is present.
Definition EST_TKVL.cc:222
const V & val_def(const K &rkey, const V &def) const
value or default
Definition EST_TKVL.cc:151