Edinburgh Speech Tools  2.4-release
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends Pages
EST_Item_Content.cc
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>
44 #include "ling_class/EST_Item_Content.h"
45 #include "ling_class/EST_Item.h"
46 #include "EST_error.h"
47 
48 void EST_Item_Content::copy(const EST_Item_Content &x)
49 {
50  f = x.f;
51  // don't copy the relations as they have relation dependencies
52 }
53 
55 {
56  if (relations.length() != 0)
57  { // Shouldn't get here, but just in case.
58  cerr << "EST_Contents: contents still referenced by Relations" << endl;
59  }
60 }
61 
62 int EST_Item_Content::unref_relation(const EST_String &relname)
63 {
64  // Unreference this item from this relation. Returns TRUE
65  // if no one else is referencing it, FALSE otherwise
66  if (this != 0)
67  {
68  if ((relname == "") && (relations.length() == 1))
69  { // sigh, something to with isolated EST_Items and
70  // SunCC causes a problems in exit(), so hit it with
71  // a bigger stick
72  relations.clear();
73  return TRUE;
74  }
75  if (relations.present(relname))
76  relations.remove_item(relname);
77  else
78  printf("failed to find %s in %s at %g\n",
79  (const char *)relname,
80  (const char *)name(),
81  f.F("end",0.0));
82  if (relations.length() == 0)
83  return TRUE;
84  }
85  return FALSE;
86 }
87 
88 int EST_Item_Content::unref_and_delete()
89 {
90  // Unreference from all relations and delete
91  EST_Item *np;
92  EST_Litem *p;
93 
94  for (p=relations.list.head(); p;)
95  {
96  np = ::item(relations.list(p).v);
97  p=p->next();
98  delete np;
99  }
100  // When the last relation is deleted this contents itself will be
101  // delete too, from underneath us.
102  return 0;
103 }
104 
105 EST_Item_Content &EST_Item_Content::operator=(const EST_Item_Content &x)
106 {
107  copy(x);
108  return *this;
109 }
110 
111 ostream& operator << (ostream &s, const EST_Item_Content &a)
112 {
113  EST_Litem *p;
114  s << a.name() << " ; ";
115  s << a.f;
116  s << "Relations";
117  for (p=a.relations.list.head(); p; p = p->next())
118  s << " " << a.relations.list(p).k;
119  s << endl;
120  return s;
121 }
122 
123 VAL_REGISTER_CLASS_NODEL(icontent,EST_Item_Content)