| 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_CUnitPrefixDisplayDelegateDecorator.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_CUNITPREFIXDISPLAYDELEGATEDECORATOR_H
23#define AAX_CUNITPREFIXDISPLAYDELEGATEDECORATOR_H
24
25#include "AAX_IDisplayDelegateDecorator.h"
26
27
58 template <typename T>
59 class AAX_CUnitPrefixDisplayDelegateDecorator : public AAX_IDisplayDelegateDecorator<T>
60{
61 public:
62 AAX_CUnitPrefixDisplayDelegateDecorator(const AAX_IDisplayDelegate<T>& displayDelegate);
63
64 //Virtual overrides
65 AAX_CUnitPrefixDisplayDelegateDecorator<T>* Clone() const AAX_OVERRIDE;
66 bool ValueToString(T value, AAX_CString* valueString) const AAX_OVERRIDE;
67 bool ValueToString(T value, int32_t maxNumChars, AAX_CString* valueString) const AAX_OVERRIDE;
68 bool StringToValue(const AAX_CString& valueString, T* value) const AAX_OVERRIDE;
69};
70
71
72
73 template <typename T>
74 AAX_CUnitPrefixDisplayDelegateDecorator<T>::AAX_CUnitPrefixDisplayDelegateDecorator(const AAX_IDisplayDelegate<T>& displayDelegate) :
75 AAX_IDisplayDelegateDecorator<T>(displayDelegate)
76{
77
78}
79
80
81 template <typename T>
82 AAX_CUnitPrefixDisplayDelegateDecorator<T>* AAX_CUnitPrefixDisplayDelegateDecorator<T>::Clone() const
83{
84 return new AAX_CUnitPrefixDisplayDelegateDecorator(*this);
85}
86
87 template <typename T>
88 bool AAX_CUnitPrefixDisplayDelegateDecorator<T>::ValueToString(T value, AAX_CString* valueString) const
89{
90 //Find the proper unit prefix.
91 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.
92 if (absValue >= 1000000.0)
93 {
94 value = value / ((T) 1000000.0);
95 bool succeeded = AAX_IDisplayDelegateDecorator<T>::ValueToString(value, valueString);
96 *valueString += AAX_CString("M");
97 return succeeded;
98 }
99 if (absValue >= ((T) 1000.0))
100 {
101 value = value / ((T) 1000.0);
102 bool succeeded = AAX_IDisplayDelegateDecorator<T>::ValueToString(value, valueString);
103 *valueString += AAX_CString("k");
104 return succeeded;
105 }
106 if (absValue >= ((T) 1.0))
107 {
108 return AAX_IDisplayDelegateDecorator<T>::ValueToString(value, valueString);
109 }
110 if (absValue >= ((T) 0.001))
111 {
112 value = value / ((T) 0.001);
113 bool succeeded = AAX_IDisplayDelegateDecorator<T>::ValueToString(value, valueString);
114 *valueString += AAX_CString("m");
115 return succeeded;
116 }
117 if (absValue >= ((T) 0.000001))
118 {
119 value = value / ((T) 0.000001);
120 bool succeeded = AAX_IDisplayDelegateDecorator<T>::ValueToString(value, valueString);
121 *valueString += AAX_CString("u");
122 return succeeded;
123 }
124 return AAX_IDisplayDelegateDecorator<T>::ValueToString(value, valueString);
125}
126
127 template <typename T>
128 bool AAX_CUnitPrefixDisplayDelegateDecorator<T>::ValueToString(T value, int32_t maxNumChars, AAX_CString* valueString) const
129{
130 //Find the proper unit prefix.
131 //<DMT> The maxNumChars is decremented by 1 in case of the unit modifier being required as this is more important than precision.
132
133 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.
134 if (absValue >= 1000000.0)
135 {
136 value = value / ((T) 1000000.0);
137 bool succeeded = AAX_IDisplayDelegateDecorator<T>::ValueToString(value, maxNumChars-1, valueString);
138 *valueString += AAX_CString("M");
139 return succeeded;
140 }
141 if (absValue >= ((T) 1000.0))
142 {
143 value = value / ((T) 1000.0);
144 bool succeeded = AAX_IDisplayDelegateDecorator<T>::ValueToString(value, maxNumChars-1, valueString);
145 *valueString += AAX_CString("k");
146 return succeeded;
147 }
148 if (absValue >= ((T) 1.0))
149 {
150 return AAX_IDisplayDelegateDecorator<T>::ValueToString(value, maxNumChars, valueString);
151 }
152 if (absValue >= ((T) 0.001))
153 {
154 value = value / ((T) 0.001);
155 bool succeeded = AAX_IDisplayDelegateDecorator<T>::ValueToString(value, maxNumChars-1, valueString);
156 *valueString += AAX_CString("m");
157 return succeeded;
158 }
159 if (absValue >= ((T) 0.000001))
160 {
161 value = value / ((T) 0.000001);
162 bool succeeded = AAX_IDisplayDelegateDecorator<T>::ValueToString(value, maxNumChars-1, valueString);
163 *valueString += AAX_CString("u");
164 return succeeded;
165 }
166 return AAX_IDisplayDelegateDecorator<T>::ValueToString(value, maxNumChars, valueString);
167}
168
169
170 template <typename T>
171 bool AAX_CUnitPrefixDisplayDelegateDecorator<T>::StringToValue(const AAX_CString& valueString, T* value) const
172{
173 //Just call through if there is obviously no unit string.
174 if (valueString.Length() <= 1)
175 return AAX_IDisplayDelegateDecorator<T>::StringToValue(valueString, value);
176
177 //Just call through if the end of this string does not match the unit string.
178 AAX_CString valueStringCopy(valueString);
179 T valueScalar = 1;
180 T valueDivScalar = 1;
181 switch(valueString[valueString.Length()-1])
182 {
183 case 'M':
184 valueScalar = ((T) 1000000.0);
185 valueStringCopy.Erase(valueString.Length()-1, 1);
186 break;
187 case 'k':
188 valueScalar = ((T) 1000.0);
189 valueStringCopy.Erase(valueString.Length()-1, 1);
190 break;
191 case 'm':
192 valueScalar = ((T) 0.001);
193 valueStringCopy.Erase(valueString.Length()-1, 1);
194 break;
195 case 'u':
196 // Rounding errors occur when trying to use 0.000001 so went to a div scalar instead.
197 // See bug https://audio-jira.avid.com/browse/PTSW-149426.
198 valueDivScalar = ((T) 1000000.0);
199 valueStringCopy.Erase(valueString.Length()-1, 1);
200 break;
201 }
202
203 bool success = AAX_IDisplayDelegateDecorator<T>::StringToValue(valueStringCopy, value);
204 *value = valueScalar * (*value);
205 *value = (*value) / valueDivScalar;
206 return success;
207}
208
209
210
211#endif //AAX_CUNITPREFIXDISPLAYDELEGATEDECORATOR
AAX_OVERRIDE
#define AAX_OVERRIDE
override keyword macro
Definition: AAX.h:151
AAX_IDisplayDelegateDecorator.h
The base class for all concrete display delegate decorators.
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_CString::Erase
AAX_CString & Erase(uint32_t pos, uint32_t n)
AAX_CUnitPrefixDisplayDelegateDecorator
A unit prefix decorator conforming to AAX_IDisplayDelegateDecorator.
Definition: AAX_CUnitPrefixDisplayDelegateDecorator.h:60
AAX_CUnitPrefixDisplayDelegateDecorator::AAX_CUnitPrefixDisplayDelegateDecorator
AAX_CUnitPrefixDisplayDelegateDecorator(const AAX_IDisplayDelegate< T > &displayDelegate)
Definition: AAX_CUnitPrefixDisplayDelegateDecorator.h:74
AAX_CUnitPrefixDisplayDelegateDecorator::StringToValue
bool StringToValue(const AAX_CString &valueString, T *value) const AAX_OVERRIDE
Converts a string to a real parameter value.
Definition: AAX_CUnitPrefixDisplayDelegateDecorator.h:171
AAX_CUnitPrefixDisplayDelegateDecorator::ValueToString
bool ValueToString(T value, AAX_CString *valueString) const AAX_OVERRIDE
Converts a real parameter value to a string representation.
Definition: AAX_CUnitPrefixDisplayDelegateDecorator.h:88
AAX_CUnitPrefixDisplayDelegateDecorator::Clone
AAX_CUnitPrefixDisplayDelegateDecorator< T > * Clone() const AAX_OVERRIDE
Constructs and returns a copy of the display delegate.
Definition: AAX_CUnitPrefixDisplayDelegateDecorator.h:82
AAX_IDisplayDelegate
Definition: AAX_IDisplayDelegate.h:66
AAX_IDisplayDelegateDecorator
The base class for all concrete display delegate decorators.
Definition: AAX_IDisplayDelegateDecorator.h:41
AAX_IDisplayDelegateDecorator::StringToValue
bool StringToValue(const AAX_CString &valueString, T *value) const AAX_OVERRIDE
Converts a string to a real parameter value.
Definition: AAX_IDisplayDelegateDecorator.h:194
AAX_IDisplayDelegateDecorator::ValueToString
bool ValueToString(T value, AAX_CString *valueString) const AAX_OVERRIDE
Converts a string to a real parameter value.
Definition: AAX_IDisplayDelegateDecorator.h:182