Edinburgh Speech Tools  2.4-release
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends Pages
EST_TrackMap.h
1  /************************************************************************/
2  /* */
3  /* Centre for Speech Technology Research */
4  /* University of Edinburgh, UK */
5  /* Copyright (c) 1996,1997 */
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 
34 #ifndef __EST_TRACKMAP_H__
35 #define __EST_TRACKMAP_H__
36 
37 #include <climits>
38 using namespace std;
39 
40 #include "EST_TNamedEnum.h"
41 #include "EST_ChannelType.h"
42 #include "EST_Handleable.h"
43 #include "EST_THandle.h"
44 
45 /** Track maps provide a mapping from symbolic track names to the
46  * actual position of the information within a track frame. The
47  * symbolic names are defined by the EST_ChannelType enumerated type.
48  *
49  * Track maps can be declared statically by code which always uses
50  * tracks of a given style, or they can be built at run time as
51  * is done by lpc_analysis to record whichinformation the
52  * user has requested. Finally they can be constructed by the Track
53  * itself from the names of the channels, for instance when a track has
54  * just been read in from a file.
55  *
56  * @see EST_Track
57  * @see EST_ChannelType
58  * @see EST_TrackMap:example
59  * @author Richard Caley <rjc@cstr.ed.ac.uk>
60  * @version $Id: EST_TrackMap.h,v 1.4 2004/09/29 08:24:17 robert Exp $
61  */
63 {
64 
65 public:
66  /**@name ChannelMapping
67  * An auxiliary type used just to define static EST_TrackMaps.
68  * Defining one of these and then converting it to an EST_TrackMap
69  * is, unfortunately, the only way C++ allows us to define
70  * a constant EST_TrackMap.
71  */
72  //@{
73  /// structure for the table.
75  EST_ChannelType type;
76  unsigned short channel;
77  };
78  /// Table of type to position pairs.
79 // typedef struct ChannelMappingElement ChannelMapping[];
80  //@}
81 
83 
84 public:
85 
86  /// Returned if we ask for a channel not in the map.
87 # define NO_SUCH_CHANNEL (-1)
88 
89 private:
90 
91  /// The map itself.
92  short p_map[num_channel_types];
93 
94  /// Parent is looked at if this map doesn't define the position.
95  EST_TrackMap::P p_parent;
96  /// Subtracted from the values in the parent.
97  int p_offset;
98 
99  /// No copy constructor. Don't copy these things.
100  EST_TrackMap(EST_TrackMap &from);
101 
102 protected:
103  /// Pass to creation function to turn on refcounting.
104 #define EST_TM_REFCOUNTED (1)
105 
106  /// Creation function used by friends to create refcounted maps.
107  EST_TrackMap(int refcount);
108 
109  /// Creation function used by friends to create sub-track maps.
110  EST_TrackMap(const EST_TrackMap *parent, int offset, int refcount);
111 
112  /// copy an exiting map.
113  void copy(EST_TrackMap &from);
114  /// Initialise the map.
115  void init(void);
116 
117  short get_parent(EST_ChannelType type) const ;
118 
119 public:
120  /// Default constructor.
121  EST_TrackMap(void);
122  /// Copy the mapping.
123  EST_TrackMap(EST_TrackMap &from, int refcount);
124  /// Create from static table.
125  EST_TrackMap(struct ChannelMappingElement map[]);
126 
127 
128  ~EST_TrackMap();
129 
130  /// Empty the map.
131  void clear(void);
132  /// Record the position of a channel.
133  void set(EST_ChannelType type, short pos)
134  { p_map[(int)type] = pos; }
135 
136  /// Get the position of a channel.
137  short get(EST_ChannelType type) const
138  { short c = p_map[(int)type];
139  return c!=NO_SUCH_CHANNEL?c:get_parent(type); }
140  /// Get the position of a channel.
141  short operator() (EST_ChannelType type) const
142  { return get(type); }
143 
144  /// Does the mapping contain a position for this channel?
145  bool has_channel(EST_ChannelType type) const
146  { return p_map[(int)type] != NO_SUCH_CHANNEL
147  || ( p_parent!=0 && p_parent->has_channel(type) ); }
148 
149  /// Returns the index of the last known channel.
150  short last_channel(void) const;
151 
152  /// Returns the type of the channel at the given position.
153  EST_ChannelType channel_type(unsigned short channel) const;
154 
155  EST_TrackMap * object_ptr() { return this; }
156  const EST_TrackMap * object_ptr() const { return this; }
157 
158  friend class EST_Track;
159  friend ostream& operator << (ostream &st, const EST_TrackMap &m);
160 };
161 
162 /** Channel name maps map textual names for track channels to symbolic
163  * names, they are just a special case of named enums.
164  */
166 
167 /** Table type used to create EST_ChannelNameMaps.
168  */
170  EST_ChannelNameTable[];
171 
172 /// Definition of standard names we use for channels.
173 extern EST_ChannelNameMap EST_default_channel_names;
174 /// Definition of the names ESPS programs use for channels.
175 extern EST_ChannelNameMap esps_channel_names;
176 
177 extern ostream& operator << (ostream &st, const EST_TrackMap &m);
178 #endif