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