| AAX SDK 2.8.0 Avid Audio Extensions Development Kit

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

- File List
- File Members

Loading...
Searching...
No Matches
AAX_CBinaryDisplayDelegate.h
Go to the documentation of this file.
1/*================================================================================================*/
2/*
3 *
4 * Copyright 2013-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_CBINARYDISPLAYDELEGATE_H
36#define AAX_CBINARYDISPLAYDELEGATE_H
37
38#include "AAX_IDisplayDelegate.h"
39#include "AAX_CString.h"
40
41
42#include <vector>
43#ifdef WINDOWS_VERSION
44#include <algorithm>
45#endif
46
47#include <algorithm>
48
49
59 template <typename T>
60 class AAX_CBinaryDisplayDelegate : public AAX_IDisplayDelegate<T>
61{
62 public:
71 AAX_CBinaryDisplayDelegate(const char* falseString, const char* trueString);
72 AAX_CBinaryDisplayDelegate(const AAX_CBinaryDisplayDelegate& other);
73
74 //Virtual Overrides
75 AAX_IDisplayDelegate<T>* Clone() const AAX_OVERRIDE;
76 bool ValueToString(T value, AAX_CString* valueString) const AAX_OVERRIDE;
77 bool ValueToString(T value, int32_t maxNumChars, AAX_CString* valueString) const AAX_OVERRIDE;
78 bool StringToValue(const AAX_CString& valueString, T* value) const AAX_OVERRIDE;
79
80 // AAX_CBinaryDisplayDelegate
81 virtual void AddShortenedStrings(const char* falseString, const char* trueString, int iStrLength);
82
83 private:
84 AAX_CBinaryDisplayDelegate(); //private contructor to prevent its use externally.
85
86 const AAX_CString mFalseString;
87 const AAX_CString mTrueString;
88 uint32_t mMaxStrLength;
89
90 struct StringTable
91 {
92 int mStrLength;
93 AAX_CString mFalseString;
94 AAX_CString mTrueString;
95 };
96 static bool StringTableSortFunc(struct StringTable i, struct StringTable j)
97 {
98 return (i.mStrLength < j.mStrLength);
99 }
100
101 std::vector<struct StringTable> mShortenedStrings;
102};
103
104
105 template <typename T>
106 AAX_CBinaryDisplayDelegate<T>::AAX_CBinaryDisplayDelegate(const char* falseString, const char* trueString) :
107 mFalseString(falseString),
108 mTrueString(trueString),
109 mMaxStrLength(0)
110{
111 mMaxStrLength = (std::max)(mMaxStrLength, mFalseString.Length());
112 mMaxStrLength = (std::max)(mMaxStrLength, mTrueString.Length());
113}
114
115 template <typename T>
116 AAX_CBinaryDisplayDelegate<T>::AAX_CBinaryDisplayDelegate(const AAX_CBinaryDisplayDelegate& other) :
117 mFalseString(other.mFalseString),
118 mTrueString(other.mTrueString),
119 mMaxStrLength(other.mMaxStrLength)
120{
121 if ( other.mShortenedStrings.size() > 0 )
122 {
123 for ( size_t i = 0; i < other.mShortenedStrings.size(); i++ )
124 mShortenedStrings.push_back( other.mShortenedStrings.at(i) );
125 }
126}
127
128 template <typename T>
129 void AAX_CBinaryDisplayDelegate<T>::AddShortenedStrings(const char* falseString, const char* trueString, int iStrLength)
130{
131 struct StringTable shortendTable;
132 shortendTable.mStrLength = iStrLength;
133 shortendTable.mFalseString = AAX_CString(falseString);
134 shortendTable.mTrueString = AAX_CString(trueString);
135 mShortenedStrings.push_back(shortendTable);
136
137 // keep structure sorted by str lengths
138 std::sort(mShortenedStrings.begin(), mShortenedStrings.end(), AAX_CBinaryDisplayDelegate::StringTableSortFunc );
139}
140
141
142 template <typename T>
143 AAX_IDisplayDelegate<T>* AAX_CBinaryDisplayDelegate<T>::Clone() const
144{
145 return new AAX_CBinaryDisplayDelegate(*this);
146}
147
148 template <typename T>
149 bool AAX_CBinaryDisplayDelegate<T>::ValueToString(T value, AAX_CString* valueString) const
150{
151 if (value)
152 *valueString = mTrueString;
153 else
154 *valueString = mFalseString;
155 return true;
156}
157
158 template <typename T>
159 bool AAX_CBinaryDisplayDelegate<T>::ValueToString(T value, int32_t maxNumChars, AAX_CString* valueString) const
160{
161 // if we don't ahve any shortened strings, just return the full length version
162 if ( mShortenedStrings.size() == 0 )
163 return this->ValueToString(value, valueString);
164
165 // first see if requested length is longer than normal strings
166 const uint32_t maxNumCharsUnsigned = (0 <= maxNumChars) ? static_cast<uint32_t>(maxNumChars) : 0;
167 if ( maxNumCharsUnsigned >= mMaxStrLength )
168 {
169 if (value)
170 *valueString = mTrueString;
171 else
172 *valueString = mFalseString;
173 return true;
174 }
175
176 // iterate through shortened strings from longest to shortest
177 // taking the first set that is short enough
178 for ( int i = static_cast<int>(mShortenedStrings.size())-1; i >= 0; i-- )
179 {
180 struct StringTable shortStrings = mShortenedStrings.at(static_cast<unsigned int>(i));
181 if ( shortStrings.mStrLength <= maxNumChars )
182 {
183 if (value)
184 *valueString = shortStrings.mTrueString;
185 else
186 *valueString = shortStrings.mFalseString;
187 return true;
188 }
189 }
190
191 // if we can't find one short enough, just use the shortest version we can find
192 struct StringTable shortestStrings = mShortenedStrings.at(0);
193 if (value)
194 *valueString = shortestStrings.mTrueString;
195 else
196 *valueString = shortestStrings.mFalseString;
197
198 return true;
199}
200
201 template <typename T>
202 bool AAX_CBinaryDisplayDelegate<T>::StringToValue(const AAX_CString& valueString, T* value) const
203{
204 if (valueString == mTrueString)
205 {
206 *value = (T)(true);
207 return true;
208 }
209 if (valueString == mFalseString)
210 {
211 *value = (T)(false);
212 return true;
213 }
214 *value = (T)(false);
215 return false;
216}
217
218
219
220
221#endif //AAX_CBINARYDISPLAYDELEGATE_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:164
AAX_CBinaryDisplayDelegate
A binary display format conforming to AAX_IDisplayDelegate.
Definition: AAX_CBinaryDisplayDelegate.h:61
AAX_CBinaryDisplayDelegate::ValueToString
bool ValueToString(T value, AAX_CString *valueString) const AAX_OVERRIDE
Converts a real parameter value to a string representation.
Definition: AAX_CBinaryDisplayDelegate.h:149
AAX_CBinaryDisplayDelegate::AddShortenedStrings
virtual void AddShortenedStrings(const char *falseString, const char *trueString, int iStrLength)
Definition: AAX_CBinaryDisplayDelegate.h:129
AAX_CBinaryDisplayDelegate::Clone
AAX_IDisplayDelegate< T > * Clone() const AAX_OVERRIDE
Constructs and returns a copy of the display delegate.
Definition: AAX_CBinaryDisplayDelegate.h:143
AAX_CBinaryDisplayDelegate::StringToValue
bool StringToValue(const AAX_CString &valueString, T *value) const AAX_OVERRIDE
Converts a string to a real parameter value.
Definition: AAX_CBinaryDisplayDelegate.h:202
AAX_CString
A generic AAX string class with similar functionality to std::string
Definition: AAX_CString.h:57
AAX_CString::Length
uint32_t Length() const AAX_OVERRIDE
AAX_IDisplayDelegate
Definition: AAX_IDisplayDelegate.h:79