| AAX SDK 2.6.1 Avid Audio Extensions Development Kit

- Welcome
- Manual
- Classes
- Files
- Lists
- Support

- File List
- File Members

Loading...
Searching...
No Matches
AAX_CStateDisplayDelegate.h
Go to the documentation of this file.
1/*================================================================================================*/
2/*
3 *
4 * Copyright 2014-2017, 2019, 2023 Avid Technology, Inc.
5 * All rights reserved.
6 *
7 * CONFIDENTIAL: this document contains confidential information of Avid. Do
8 * not disclose to any third party. Use of the information contained in this
9 * document is subject to an Avid SDK license.
10 *
11 */
12
19/*================================================================================================*/
20
21
22#ifndef AAX_CSTATEDISPLAYDELEGATE_H
23#define AAX_CSTATEDISPLAYDELEGATE_H
24
25#include "AAX_IDisplayDelegate.h"
26#include "AAX_CString.h"
27
28#include <vector>
29#if defined(WINDOWS_VERSION) || defined(LINUX_VERSION)
30#include <algorithm>
31#endif
32
33
34
44 template <typename T>
45 class AAX_CStateDisplayDelegate : public AAX_IDisplayDelegate<T>
46{
47 public:
55 explicit AAX_CStateDisplayDelegate( const char * iStateStrings[], T iMinState = 0 );
56
65 explicit AAX_CStateDisplayDelegate( int32_t inNumStates, const char * iStateStrings[], T iMinState = 0 );
66
72 explicit AAX_CStateDisplayDelegate( const std::vector<AAX_IString*>& iStateStrings, T iMinState = 0 );
73
74 AAX_CStateDisplayDelegate(const AAX_CStateDisplayDelegate& other);
75
76 //Virtual Overrides
77 AAX_IDisplayDelegate<T>* Clone() const AAX_OVERRIDE;
78 bool ValueToString(T value, AAX_CString* valueString) const AAX_OVERRIDE;
79 bool ValueToString(T value, int32_t maxNumChars, AAX_CString* valueString) const AAX_OVERRIDE;
80 bool StringToValue(const AAX_CString& valueString, T* value) const AAX_OVERRIDE;
81
82 //AAX_CStateDisplayDelegate
83 void AddShortenedStrings( const char * iStateStrings[], int iLength );
84 bool Compare( const AAX_CString& valueString, const AAX_CString& stateString ) const;
85
86 private:
87 AAX_CStateDisplayDelegate(); //private contructor to prevent its use externally.
88
89 T mMinState;
90 std::vector<AAX_CString> mStateStrings;
91
92 struct StringTable
93 {
94 int mStrLength;
95 std::vector<AAX_CString> mStateStrings;
96 };
97 static bool StringTableSortFunc(struct StringTable i, struct StringTable j)
98 {
99 return (i.mStrLength < j.mStrLength);
100 }
101
102 std::vector<struct StringTable> mShortenedStrings;
103};
104
105 template <typename T>
106 AAX_CStateDisplayDelegate<T>::AAX_CStateDisplayDelegate( const char * iStateStrings[], T iMinState /* = 0 */ )
107{
108 mMinState = iMinState;
109 for ( int index = 0; iStateStrings[ index ] != 0; ++index )
110 mStateStrings.push_back( AAX_CString( iStateStrings[ index ] ) );
111}
112
113 template <typename T>
114 AAX_CStateDisplayDelegate<T>::AAX_CStateDisplayDelegate( int32_t inNumStates, const char * iStateStrings[], T iMinState /* = 0 */ )
115{
116 mMinState = iMinState;
117 for ( int index = 0; (index < inNumStates) && (iStateStrings[ index ] != 0); ++index )
118 mStateStrings.push_back( AAX_CString( iStateStrings[ index ] ) );
119}
120
121 template <typename T>
122 AAX_CStateDisplayDelegate<T>::AAX_CStateDisplayDelegate( const std::vector<AAX_IString*>& iStateStrings, T iMinState /* = 0 */ )
123{
124 mMinState = iMinState;
125 for ( std::vector<AAX_IString*>::const_iterator iter = iStateStrings.begin(); iter != iStateStrings.end(); ++iter )
126 {
127 if (*iter)
128 {
129 mStateStrings.push_back( *(*iter) );
130 }
131 }
132}
133
134 template <typename T>
135 AAX_CStateDisplayDelegate<T>::AAX_CStateDisplayDelegate( const AAX_CStateDisplayDelegate & iOther )
136{
137 mMinState = iOther.mMinState;
138
139 std::vector<AAX_CString>::const_iterator iter = iOther.mStateStrings.begin();
140 for ( ; iter != iOther.mStateStrings.end(); ++iter )
141 mStateStrings.push_back( AAX_CString( *iter ) );
142
143 if ( iOther.mShortenedStrings.size() > 0 )
144 {
145 for ( int i = 0; i < (int)iOther.mShortenedStrings.size(); i++ )
146 mShortenedStrings.push_back( iOther.mShortenedStrings.at(i) );
147 }
148}
149
150 template <typename T>
151 void AAX_CStateDisplayDelegate<T>::AddShortenedStrings( const char * iStateStrings[], int iStrLength )
152{
153 struct StringTable shortendTable;
154 shortendTable.mStrLength = iStrLength;
155 for ( int index = 0; iStateStrings[ index ] != 0; ++index )
156 shortendTable.mStateStrings.push_back( AAX_CString( iStateStrings[ index ] ) );
157 mShortenedStrings.push_back(shortendTable);
158
159 // keep structure sorted by str lengths
160 std::sort(mShortenedStrings.begin(), mShortenedStrings.end(), AAX_CStateDisplayDelegate::StringTableSortFunc );
161}
162
163 template <typename T>
164 AAX_IDisplayDelegate<T>* AAX_CStateDisplayDelegate<T>::Clone() const
165{
166 return new AAX_CStateDisplayDelegate(*this);
167}
168
169 template <typename T>
170 bool AAX_CStateDisplayDelegate<T>::ValueToString(T value, AAX_CString* valueString) const
171{
172 T index = value - mMinState;
173 if ( index >= (T) 0 && index < (T) mStateStrings.size() )
174 {
175 *valueString = mStateStrings[ index ];
176 return true;
177 }
178
179 return false;
180}
181
182 template <typename T>
183 bool AAX_CStateDisplayDelegate<T>::ValueToString(T value, int32_t maxNumChars, AAX_CString* valueString) const
184{
185 // if we don't ahve any shortened strings, just return the full length version
186 if ( mShortenedStrings.size() == 0 )
187 return this->ValueToString(value, valueString);
188
189 // iterate through shortened strings from longest to shortest
190 // taking the first set that is short enough
191 T index = value - mMinState;
192
193 if ( index < (T) 0 || index >= (T) mStateStrings.size() )
194 return true;
195
196 // first see if the normal string is short enough
197 if ( mStateStrings[ index ].Length() < uint32_t(maxNumChars) )
198 {
199 *valueString = mStateStrings[ index ];
200 return true;
201 }
202
203 for ( int i = (int)mShortenedStrings.size()-1; i >= 0; i-- )
204 {
205 struct StringTable shortStrings = mShortenedStrings.at(i);
206 if ( shortStrings.mStrLength <= maxNumChars )
207 {
208 if ( index >= (T) 0 && index < (T) shortStrings.mStateStrings.size() )
209 {
210 *valueString = shortStrings.mStateStrings[ index ];
211 return true;
212 }
213 }
214 }
215
216 // if we can't find one short enough, just use the shortest version we can find
217 struct StringTable shortestStrings = mShortenedStrings.at(0);
218 if ( index >= (T) 0 && index < (T) shortestStrings.mStateStrings.size() )
219 {
220 *valueString = shortestStrings.mStateStrings[ index ];
221 return true;
222 }
223
224 return false;
225}
226
227 template <typename T>
228 bool AAX_CStateDisplayDelegate<T>::StringToValue(const AAX_CString& valueString, T* value) const
229{
230 std::vector<AAX_CString>::const_iterator iter = mStateStrings.begin();
231 for ( T index = 0; iter != mStateStrings.end(); ++index, ++iter )
232 {
233 if (Compare(valueString,*iter))
234 {
235 *value = index + mMinState;
236 return true;
237 }
238 }
239
240 *value = mMinState;
241 return false;
242}
243
244 template <typename T>
245 bool AAX_CStateDisplayDelegate<T>::Compare( const AAX_CString& valueString, const AAX_CString& stateString ) const
246{
247 return valueString==stateString;
248}
249
250
251
252
253
254#endif //AAX_CSTATEDISPLAYDELEGATE_H
AAX_CString.h
A generic AAX string class with similar functionality to std::string.
AAX_IDisplayDelegate.h
Defines the display behavior for a parameter.
AAX_OVERRIDE
#define AAX_OVERRIDE
override keyword macro
Definition: AAX.h:151
AAX_CStateDisplayDelegate
A generic display format conforming to AAX_IDisplayDelegate.
Definition: AAX_CStateDisplayDelegate.h:46
AAX_CStateDisplayDelegate::AddShortenedStrings
void AddShortenedStrings(const char *iStateStrings[], int iLength)
Definition: AAX_CStateDisplayDelegate.h:151
AAX_CStateDisplayDelegate::StringToValue
bool StringToValue(const AAX_CString &valueString, T *value) const AAX_OVERRIDE
Converts a string to a real parameter value.
Definition: AAX_CStateDisplayDelegate.h:228
AAX_CStateDisplayDelegate::Compare
bool Compare(const AAX_CString &valueString, const AAX_CString &stateString) const
Definition: AAX_CStateDisplayDelegate.h:245
AAX_CStateDisplayDelegate::ValueToString
bool ValueToString(T value, AAX_CString *valueString) const AAX_OVERRIDE
Converts a real parameter value to a string representation.
Definition: AAX_CStateDisplayDelegate.h:170
AAX_CStateDisplayDelegate::Clone
AAX_IDisplayDelegate< T > * Clone() const AAX_OVERRIDE
Constructs and returns a copy of the display delegate.
Definition: AAX_CStateDisplayDelegate.h:164
AAX_CString
A generic AAX string class with similar functionality to std::string
Definition: AAX_CString.h:44
AAX_IDisplayDelegate
Definition: AAX_IDisplayDelegate.h:66