Edinburgh Speech Tools  2.1-release
EST_Contents.h
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 1996 */
35 /*-----------------------------------------------------------------------*/
36 /* A class for representing ints floats and strings */
37 /* */
38 /*=======================================================================*/
39 #ifndef __EST_CONTENTS_H__
40 #define __EST_CONTENTS_H__
41 
42 /** \class EST_Content_Data
43  \brief A class for containing some other (arbitrary) class.
44 Not general enough to call itself a run-time type system
45 Is designed to solve the problem of holding user
46 specified information.
47 Keeps reference count to know when to delete contents
48 
49  This is done on two levels EST_Contents and Contents_Data
50 */
52  private:
53  int refs;
54  void *data;
55  void (*free_func)(void *data);
56  public:
57  EST_Content_Data(void *d,void (*f)(void *d)) {free_func=f; data=d; refs=1;}
58  ~EST_Content_Data() { free_func(data); }
59  ///
60  int unref() { return --refs; }
61  ///
62  int ref() { return ++refs; }
63  ///
64  int the_refs() { return refs; }
65  void *contents() { return data; }
67  {refs = c.refs; data = c.data; free_func = c.free_func; return *this;}
68 };
69 
70 /** More contents */
71 
73 private:
74  EST_Content_Data *content_data;
75  void unref_contents(void)
76  { if ((content_data != 0) &&
77  (content_data->unref() == 0))
78  delete content_data;}
79 public:
80  EST_Contents() { content_data = 0; }
81  EST_Contents(void *p,void (*free_func)(void *p))
82  { content_data = new EST_Content_Data(p,free_func); }
83  ~EST_Contents() { unref_contents(); }
84  void set_contents(void *p,void (*free_func)(void *p))
85  { unref_contents(); content_data = new EST_Content_Data(p,free_func);}
86  void *get_contents() const
87  {return (content_data ? content_data->contents() : 0);}
88  ///
89  int refs() const { return ((content_data == 0) ? 0 :
90  content_data->the_refs());}
92  { unref_contents();
93  content_data = c.content_data;
94  if (content_data != 0) content_data->ref();
95  return *this; }
96 };
97 
98 #endif
99 
A class for containing some other (arbitrary) class. Not general enough to call itself a run-time typ...
Definition: EST_Contents.h:51
void * contents()
Definition: EST_Contents.h:65
EST_Contents(void *p, void(*free_func)(void *p))
Definition: EST_Contents.h:81
EST_Content_Data(void *d, void(*f)(void *d))
Definition: EST_Contents.h:57
void * get_contents() const
Definition: EST_Contents.h:86
f
Definition: EST_item_aux.cc:48
EST_Contents & operator=(const EST_Contents &c)
Definition: EST_Contents.h:91
int refs() const
Definition: EST_Contents.h:89
EST_Content_Data & operator=(const EST_Content_Data &c)
Definition: EST_Contents.h:66
void set_contents(void *p, void(*free_func)(void *p))
Definition: EST_Contents.h:84