Edinburgh Speech Tools  2.1-release
EST_Item_Content.cc
Go to the documentation of this file.
1 /*************************************************************************/
2 /* */
3 /* Centre for Speech Technology Research */
4 /* University of Edinburgh, UK */
5 /* Copyright (c) 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 : Alan W Black */
34 /* Date : May 1998 */
35 /*-----------------------------------------------------------------------*/
36 /* Content part of a linguistic item, normally only referenced from */
37 /* EST_Item */
38 /* */
39 /*=======================================================================*/
40 
41 #include <cstdlib>
42 #include <cstdio>
43 #include <fstream>
45 #include "ling_class/EST_Item.h"
46 #include "EST_error.h"
47 
48 using namespace std;
49 
50 void EST_Item_Content::copy(const EST_Item_Content &x)
51 {
52  f = x.f;
53  // don't copy the relations as they have relation dependencies
54 }
55 
57 {
58  if (relations.length() != 0)
59  { // Shouldn't get here, but just in case.
60  cerr << "EST_Contents: contents still referenced by Relations" << endl;
61  }
62 }
63 
65 {
66  // Unreference this item from this relation. Returns TRUE
67  // if no one else is referencing it, FALSE otherwise
68  if (this != 0)
69  {
70  if ((relname == "") && (relations.length() == 1))
71  { // sigh, something to with isolated EST_Items and
72  // SunCC causes a problems in exit(), so hit it with
73  // a bigger stick
74  relations.clear();
75  return TRUE;
76  }
77  if (relations.present(relname))
78  relations.remove_item(relname);
79  else
80  printf("failed to find %s in %s at %g\n",
81  (const char *)relname,
82  (const char *)name(),
83  f.F("end",0.0));
84  if (relations.length() == 0)
85  return TRUE;
86  }
87  return FALSE;
88 }
89 
91 {
92  // Unreference from all relations and delete
93  EST_Item *np;
94  EST_Litem *p;
95 
96  for (p=relations.list.head(); p;)
97  {
98  np = ::item(relations.list(p).v);
99  p=p->next();
100  delete np;
101  }
102  // When the last relation is deleted this contents itself will be
103  // delete too, from underneath us.
104  return 0;
105 }
106 
108 {
109  copy(x);
110  return *this;
111 }
112 
113 ostream& operator << (ostream &s, const EST_Item_Content &a)
114 {
115  EST_Litem *p;
116  s << a.name() << " ; ";
117  s << a.f;
118  s << "Relations";
119  for (p=a.relations.list.head(); p; p = p->next())
120  s << " " << a.relations.list(p).k;
121  s << endl;
122  return s;
123 }
124 
ostream & operator<<(ostream &s, const EST_Item_Content &a)
EST_UItem * next()
Definition: EST_UList.h:55
EST_Features f
General features for this item.
EST_TKVL< EST_String, EST_Val > relations
~EST_Item_Content()
destructor
#define VAL_REGISTER_CLASS_NODEL(NAME, CLASS)
Definition: EST_Val_defs.h:133
EST_TList< EST_TKVI< K, V > > list
Linked list of key-val pairs. Don&#39;t use this as it will be made private in the future.
Definition: EST_TKVL.h:94
#define FALSE
Definition: EST_bool.h:119
EST_TVector< T > & copy(EST_TVector< T > a, const EST_TList< T > &in)
f
Definition: EST_item_aux.cc:48
const EST_String name() const
EST_UItem * head() const
Definition: EST_UList.h:97
EST_Item_Content & operator=(const EST_Item_Content &a)
#define TRUE
Definition: EST_bool.h:118
int unref_relation(const EST_String &relname)