AAX SDK 2.8.0
Avid Audio Extensions Development Kit
Loading...
Searching...
No Matches
AAX_CStateDisplayDelegate.h
Go to the documentation of this file.
1/*================================================================================================*/
2/*
3 *
4 * Copyright 2014-2017, 2019, 2023-2024 Avid Technology, Inc.
5 * All rights reserved.
6 *
7 * This file is part of the Avid AAX SDK.
8 *
9 * The AAX SDK is subject to commercial or open-source licensing.
10 *
11 * By using the AAX SDK, you agree to the terms of both the Avid AAX SDK License
12 * Agreement and Avid Privacy Policy.
13 *
14 * AAX SDK License: https://developer.avid.com/aax
15 * Privacy Policy: https://www.avid.com/legal/privacy-policy-statement
16 *
17 * Or: You may also use this code under the terms of the GPL v3 (see
18 * www.gnu.org/licenses).
19 *
20 * THE AAX SDK IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21 * EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22 * DISCLAIMED.
23 *
24 */
25
32/*================================================================================================*/
33
34
35#ifndef AAX_CSTATEDISPLAYDELEGATE_H
36#define AAX_CSTATEDISPLAYDELEGATE_H
37
39#include "AAX_CString.h"
40
41#include <vector>
42#if defined(WINDOWS_VERSION) || defined(LINUX_VERSION)
43#include <algorithm>
44#endif
45
46
47
57template <typename T>
59{
60public:
68 explicit AAX_CStateDisplayDelegate( const char * iStateStrings[], T iMinState = 0 );
69
78 explicit AAX_CStateDisplayDelegate( int32_t inNumStates, const char * iStateStrings[], T iMinState = 0 );
79
85 explicit AAX_CStateDisplayDelegate( const std::vector<AAX_IString*>& iStateStrings, T iMinState = 0 );
86
88
89 //Virtual Overrides
91 bool ValueToString(T value, AAX_CString* valueString) const AAX_OVERRIDE;
92 bool ValueToString(T value, int32_t maxNumChars, AAX_CString* valueString) const AAX_OVERRIDE;
93 bool StringToValue(const AAX_CString& valueString, T* value) const AAX_OVERRIDE;
94
95 //AAX_CStateDisplayDelegate
96 void AddShortenedStrings( const char * iStateStrings[], int iLength );
97 bool Compare( const AAX_CString& valueString, const AAX_CString& stateString ) const;
98
99private:
100 AAX_CStateDisplayDelegate(); //private contructor to prevent its use externally.
101
102 T mMinState;
103 std::vector<AAX_CString> mStateStrings;
104
105 struct StringTable
106 {
107 int mStrLength;
108 std::vector<AAX_CString> mStateStrings;
109 };
110 static bool StringTableSortFunc(struct StringTable i, struct StringTable j)
111 {
112 return (i.mStrLength < j.mStrLength);
113 }
114
115 std::vector<struct StringTable> mShortenedStrings;
116};
117
118template <typename T>
119AAX_CStateDisplayDelegate<T>::AAX_CStateDisplayDelegate( const char * iStateStrings[], T iMinState /* = 0 */ )
120{
121 mMinState = iMinState;
122 for ( int index = 0; iStateStrings[ index ] != 0; ++index )
123 mStateStrings.push_back( AAX_CString( iStateStrings[ index ] ) );
124}
125
126template <typename T>
127AAX_CStateDisplayDelegate<T>::AAX_CStateDisplayDelegate( int32_t inNumStates, const char * iStateStrings[], T iMinState /* = 0 */ )
128{
129 mMinState = iMinState;
130 for ( int index = 0; (index < inNumStates) && (iStateStrings[ index ] != 0); ++index )
131 mStateStrings.push_back( AAX_CString( iStateStrings[ index ] ) );
132}
133
134template <typename T>
135AAX_CStateDisplayDelegate<T>::AAX_CStateDisplayDelegate( const std::vector<AAX_IString*>& iStateStrings, T iMinState /* = 0 */ )
136{
137 mMinState = iMinState;
138 for ( std::vector<AAX_IString*>::const_iterator iter = iStateStrings.begin(); iter != iStateStrings.end(); ++iter )
139 {
140 if (*iter)
141 {
142 mStateStrings.push_back( *(*iter) );
143 }
144 }
145}
146
147template <typename T>
149{
150 mMinState = iOther.mMinState;
151
152 std::vector<AAX_CString>::const_iterator iter = iOther.mStateStrings.begin();
153 for ( ; iter != iOther.mStateStrings.end(); ++iter )
154 mStateStrings.push_back( AAX_CString( *iter ) );
155
156 if ( iOther.mShortenedStrings.size() > 0 )
157 {
158 for ( int i = 0; i < (int)iOther.mShortenedStrings.size(); i++ )
159 mShortenedStrings.push_back( iOther.mShortenedStrings.at(i) );
160 }
161}
162
163template <typename T>
164void AAX_CStateDisplayDelegate<T>::AddShortenedStrings( const char * iStateStrings[], int iStrLength )
165{
166 struct StringTable shortendTable;
167 shortendTable.mStrLength = iStrLength;
168 for ( int index = 0; iStateStrings[ index ] != 0; ++index )
169 shortendTable.mStateStrings.push_back( AAX_CString( iStateStrings[ index ] ) );
170 mShortenedStrings.push_back(shortendTable);
171
172 // keep structure sorted by str lengths
173 std::sort(mShortenedStrings.begin(), mShortenedStrings.end(), AAX_CStateDisplayDelegate::StringTableSortFunc );
174}
175
176template <typename T>
178{
179 return new AAX_CStateDisplayDelegate(*this);
180}
181
182template <typename T>
184{
185 T index = value - mMinState;
186 if ( index >= (T) 0 && index < (T) mStateStrings.size() )
187 {
188 *valueString = mStateStrings[ index ];
189 return true;
190 }
191
192 return false;
193}
194
195template <typename T>
196bool AAX_CStateDisplayDelegate<T>::ValueToString(T value, int32_t maxNumChars, AAX_CString* valueString) const
197{
198 // if we don't ahve any shortened strings, just return the full length version
199 if ( mShortenedStrings.size() == 0 )
200 return this->ValueToString(value, valueString);
201
202 // iterate through shortened strings from longest to shortest
203 // taking the first set that is short enough
204 T index = value - mMinState;
205
206 if ( index < (T) 0 || index >= (T) mStateStrings.size() )
207 return true;
208
209 // first see if the normal string is short enough
210 if ( mStateStrings[ index ].Length() < uint32_t(maxNumChars) )
211 {
212 *valueString = mStateStrings[ index ];
213 return true;
214 }
215
216 for ( int i = (int)mShortenedStrings.size()-1; i >= 0; i-- )
217 {
218 struct StringTable shortStrings = mShortenedStrings.at(i);
219 if ( shortStrings.mStrLength <= maxNumChars )
220 {
221 if ( index >= (T) 0 && index < (T) shortStrings.mStateStrings.size() )
222 {
223 *valueString = shortStrings.mStateStrings[ index ];
224 return true;
225 }
226 }
227 }
228
229 // if we can't find one short enough, just use the shortest version we can find
230 struct StringTable shortestStrings = mShortenedStrings.at(0);
231 if ( index >= (T) 0 && index < (T) shortestStrings.mStateStrings.size() )
232 {
233 *valueString = shortestStrings.mStateStrings[ index ];
234 return true;
235 }
236
237 return false;
238}
239
240template <typename T>
241bool AAX_CStateDisplayDelegate<T>::StringToValue(const AAX_CString& valueString, T* value) const
242{
243 std::vector<AAX_CString>::const_iterator iter = mStateStrings.begin();
244 for ( T index = 0; iter != mStateStrings.end(); ++index, ++iter )
245 {
246 if (Compare(valueString,*iter))
247 {
248 *value = index + mMinState;
249 return true;
250 }
251 }
252
253 *value = mMinState;
254 return false;
255}
256
257template <typename T>
258bool AAX_CStateDisplayDelegate<T>::Compare( const AAX_CString& valueString, const AAX_CString& stateString ) const
259{
260 return valueString==stateString;
261}
262
263
264
265
266
267#endif //AAX_CSTATEDISPLAYDELEGATE_H
A generic AAX string class with similar functionality to std::string.
Defines the display behavior for a parameter.
#define AAX_OVERRIDE
override keyword macro
Definition: AAX.h:164
A generic display format conforming to AAX_IDisplayDelegate.
Definition: AAX_CStateDisplayDelegate.h:59
void AddShortenedStrings(const char *iStateStrings[], int iLength)
Definition: AAX_CStateDisplayDelegate.h:164
bool StringToValue(const AAX_CString &valueString, T *value) const AAX_OVERRIDE
Converts a string to a real parameter value.
Definition: AAX_CStateDisplayDelegate.h:241
bool Compare(const AAX_CString &valueString, const AAX_CString &stateString) const
Definition: AAX_CStateDisplayDelegate.h:258
bool ValueToString(T value, AAX_CString *valueString) const AAX_OVERRIDE
Converts a real parameter value to a string representation.
Definition: AAX_CStateDisplayDelegate.h:183
AAX_IDisplayDelegate< T > * Clone() const AAX_OVERRIDE
Constructs and returns a copy of the display delegate.
Definition: AAX_CStateDisplayDelegate.h:177
A generic AAX string class with similar functionality to std::string
Definition: AAX_CString.h:57
Definition: AAX_IDisplayDelegate.h:79