AAX SDK 2.8.0
Avid Audio Extensions Development Kit
Loading...
Searching...
No Matches
AAX_CUnitPrefixDisplayDelegateDecorator.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_CUNITPREFIXDISPLAYDELEGATEDECORATOR_H
36#define AAX_CUNITPREFIXDISPLAYDELEGATEDECORATOR_H
37
39
40
71template <typename T>
73{
74public:
76
77 //Virtual overrides
79 bool ValueToString(T value, AAX_CString* valueString) const AAX_OVERRIDE;
80 bool ValueToString(T value, int32_t maxNumChars, AAX_CString* valueString) const AAX_OVERRIDE;
81 bool StringToValue(const AAX_CString& valueString, T* value) const AAX_OVERRIDE;
82};
83
84
85
86template <typename T>
88 AAX_IDisplayDelegateDecorator<T>(displayDelegate)
89{
90
91}
92
93
94template <typename T>
96{
98}
99
100template <typename T>
102{
103 //Find the proper unit prefix.
104 T absValue = fabsf(float(value)); //If you fail to compile on this line, you're trying to use this class with an integer type, which is not supported.
105 if (absValue >= 1000000.0)
106 {
107 value = value / ((T) 1000000.0);
108 bool succeeded = AAX_IDisplayDelegateDecorator<T>::ValueToString(value, valueString);
109 *valueString += AAX_CString("M");
110 return succeeded;
111 }
112 if (absValue >= ((T) 1000.0))
113 {
114 value = value / ((T) 1000.0);
115 bool succeeded = AAX_IDisplayDelegateDecorator<T>::ValueToString(value, valueString);
116 *valueString += AAX_CString("k");
117 return succeeded;
118 }
119 if (absValue >= ((T) 1.0))
120 {
121 return AAX_IDisplayDelegateDecorator<T>::ValueToString(value, valueString);
122 }
123 if (absValue >= ((T) 0.001))
124 {
125 value = value / ((T) 0.001);
126 bool succeeded = AAX_IDisplayDelegateDecorator<T>::ValueToString(value, valueString);
127 *valueString += AAX_CString("m");
128 return succeeded;
129 }
130 if (absValue >= ((T) 0.000001))
131 {
132 value = value / ((T) 0.000001);
133 bool succeeded = AAX_IDisplayDelegateDecorator<T>::ValueToString(value, valueString);
134 *valueString += AAX_CString("u");
135 return succeeded;
136 }
137 return AAX_IDisplayDelegateDecorator<T>::ValueToString(value, valueString);
138}
139
140template <typename T>
141bool AAX_CUnitPrefixDisplayDelegateDecorator<T>::ValueToString(T value, int32_t maxNumChars, AAX_CString* valueString) const
142{
143 //Find the proper unit prefix.
144 //<DMT> The maxNumChars is decremented by 1 in case of the unit modifier being required as this is more important than precision.
145
146 T absValue = fabsf(float(value)); //If you fail to compile on this line, you're trying to use this class with an integer type, which is not supported.
147 if (absValue >= 1000000.0)
148 {
149 value = value / ((T) 1000000.0);
150 bool succeeded = AAX_IDisplayDelegateDecorator<T>::ValueToString(value, maxNumChars-1, valueString);
151 *valueString += AAX_CString("M");
152 return succeeded;
153 }
154 if (absValue >= ((T) 1000.0))
155 {
156 value = value / ((T) 1000.0);
157 bool succeeded = AAX_IDisplayDelegateDecorator<T>::ValueToString(value, maxNumChars-1, valueString);
158 *valueString += AAX_CString("k");
159 return succeeded;
160 }
161 if (absValue >= ((T) 1.0))
162 {
163 return AAX_IDisplayDelegateDecorator<T>::ValueToString(value, maxNumChars, valueString);
164 }
165 if (absValue >= ((T) 0.001))
166 {
167 value = value / ((T) 0.001);
168 bool succeeded = AAX_IDisplayDelegateDecorator<T>::ValueToString(value, maxNumChars-1, valueString);
169 *valueString += AAX_CString("m");
170 return succeeded;
171 }
172 if (absValue >= ((T) 0.000001))
173 {
174 value = value / ((T) 0.000001);
175 bool succeeded = AAX_IDisplayDelegateDecorator<T>::ValueToString(value, maxNumChars-1, valueString);
176 *valueString += AAX_CString("u");
177 return succeeded;
178 }
179 return AAX_IDisplayDelegateDecorator<T>::ValueToString(value, maxNumChars, valueString);
180}
181
182
183template <typename T>
185{
186 //Just call through if there is obviously no unit string.
187 if (valueString.Length() <= 1)
188 return AAX_IDisplayDelegateDecorator<T>::StringToValue(valueString, value);
189
190 //Just call through if the end of this string does not match the unit string.
191 AAX_CString valueStringCopy(valueString);
192 T valueScalar = 1;
193 T valueDivScalar = 1;
194 switch(valueString[valueString.Length()-1])
195 {
196 case 'M':
197 valueScalar = ((T) 1000000.0);
198 valueStringCopy.Erase(valueString.Length()-1, 1);
199 break;
200 case 'k':
201 valueScalar = ((T) 1000.0);
202 valueStringCopy.Erase(valueString.Length()-1, 1);
203 break;
204 case 'm':
205 valueScalar = ((T) 0.001);
206 valueStringCopy.Erase(valueString.Length()-1, 1);
207 break;
208 case 'u':
209 // Rounding errors occur when trying to use 0.000001 so went to a div scalar instead.
210 // See bug https://audio-jira.avid.com/browse/PTSW-149426.
211 valueDivScalar = ((T) 1000000.0);
212 valueStringCopy.Erase(valueString.Length()-1, 1);
213 break;
214 }
215
216 bool success = AAX_IDisplayDelegateDecorator<T>::StringToValue(valueStringCopy, value);
217 *value = valueScalar * (*value);
218 *value = (*value) / valueDivScalar;
219 return success;
220}
221
222
223
224#endif //AAX_CUNITPREFIXDISPLAYDELEGATEDECORATOR
#define AAX_OVERRIDE
override keyword macro
Definition: AAX.h:164
The base class for all concrete display delegate decorators.
A generic AAX string class with similar functionality to std::string
Definition: AAX_CString.h:57
uint32_t Length() const AAX_OVERRIDE
AAX_CString & Erase(uint32_t pos, uint32_t n)
A unit prefix decorator conforming to AAX_IDisplayDelegateDecorator.
Definition: AAX_CUnitPrefixDisplayDelegateDecorator.h:73
AAX_CUnitPrefixDisplayDelegateDecorator(const AAX_IDisplayDelegate< T > &displayDelegate)
Definition: AAX_CUnitPrefixDisplayDelegateDecorator.h:87
bool StringToValue(const AAX_CString &valueString, T *value) const AAX_OVERRIDE
Converts a string to a real parameter value.
Definition: AAX_CUnitPrefixDisplayDelegateDecorator.h:184
bool ValueToString(T value, AAX_CString *valueString) const AAX_OVERRIDE
Converts a real parameter value to a string representation.
Definition: AAX_CUnitPrefixDisplayDelegateDecorator.h:101
AAX_CUnitPrefixDisplayDelegateDecorator< T > * Clone() const AAX_OVERRIDE
Constructs and returns a copy of the display delegate.
Definition: AAX_CUnitPrefixDisplayDelegateDecorator.h:95
Definition: AAX_IDisplayDelegate.h:79
The base class for all concrete display delegate decorators.
Definition: AAX_IDisplayDelegateDecorator.h:54
bool StringToValue(const AAX_CString &valueString, T *value) const AAX_OVERRIDE
Converts a string to a real parameter value.
Definition: AAX_IDisplayDelegateDecorator.h:207
bool ValueToString(T value, AAX_CString *valueString) const AAX_OVERRIDE
Converts a string to a real parameter value.
Definition: AAX_IDisplayDelegateDecorator.h:195