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