| 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_CNumberDisplayDelegate.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_CNUMBERDISPLAYDELEGATE_H
23#define AAX_CNUMBERDISPLAYDELEGATE_H
24
25#include "AAX_IDisplayDelegate.h"
26#include "AAX_CString.h"
27
28
38 template <typename T, uint32_t Precision=2, uint32_t SpaceAfter=0>
39 class AAX_CNumberDisplayDelegate : public AAX_IDisplayDelegate<T>
40{
41 public:
42 //Virtual Overrides
43 AAX_CNumberDisplayDelegate* Clone() const AAX_OVERRIDE;
44 bool ValueToString(T value, AAX_CString* valueString) const AAX_OVERRIDE;
45 bool ValueToString(T value, int32_t maxNumChars, AAX_CString* valueString) const AAX_OVERRIDE;
46 bool StringToValue(const AAX_CString& valueString, T* value) const AAX_OVERRIDE;
47};
48
49
50
51
52 template <typename T, uint32_t Precision, uint32_t SpaceAfter>
53 AAX_CNumberDisplayDelegate<T,Precision,SpaceAfter>* AAX_CNumberDisplayDelegate<T,Precision,SpaceAfter>::Clone() const
54{
55 return new AAX_CNumberDisplayDelegate(*this);
56}
57
58 template <typename T, uint32_t Precision, uint32_t SpaceAfter>
59 bool AAX_CNumberDisplayDelegate<T,Precision,SpaceAfter>::ValueToString(T value, AAX_CString* valueString) const
60{
61 valueString->Clear();
62 valueString->AppendNumber(value, Precision);
63 if (SpaceAfter != 0)
64 valueString->Append(" "); //Added a space after the number for easier display of units.
65 return true;
66}
67
68 template <typename T, uint32_t Precision, uint32_t SpaceAfter>
69 bool AAX_CNumberDisplayDelegate<T,Precision,SpaceAfter>::ValueToString(T value, int32_t maxNumChars, AAX_CString* valueString) const
70{
71 valueString->Clear();
72 valueString->AppendNumber(value, Precision);
73 uint32_t strlen = valueString->Length();
74 const uint32_t maxNumCharsUnsigned = (0 <= maxNumChars) ? static_cast<uint32_t>(maxNumChars) : 0;
75 if (strlen > maxNumCharsUnsigned)
76 {
77 valueString->Erase(maxNumCharsUnsigned, strlen-maxNumCharsUnsigned);
78 strlen = valueString->Length();
79 }
80
81 if ( 0 < maxNumCharsUnsigned && strlen == maxNumCharsUnsigned && (*valueString)[maxNumCharsUnsigned-1] == '.') //<DMT> Edge case when the decimal point is the last character, we probably shouldn't show it.
82 {
83 valueString->Erase(maxNumCharsUnsigned-1, 1);
84 strlen = valueString->Length();
85 }
86
87 if ((SpaceAfter != 0) && (maxNumCharsUnsigned > strlen) && (maxNumCharsUnsigned-strlen > 2)) //<DMT> Kind of a random threshold for dropping the space after, but seems reasonable for our control surfaces. (allows dB and Unit prefixes)
88 valueString->Append(" "); //Added a space after the number for easier display of units.
89 return true;
90}
91
92 template <typename T, uint32_t Precision, uint32_t SpaceAfter>
93 bool AAX_CNumberDisplayDelegate<T,Precision,SpaceAfter>::StringToValue(const AAX_CString& valueString, T* value) const
94{
95 double dValue;
96 if (valueString.ToDouble(&dValue))
97 {
98 *value = static_cast<T> (dValue);
99 return true;
100 }
101 *value = 0;
102 return false;
103}
104
105
106
107
108#endif //AAX_CNUMBERDISPLAYDELEGATE_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_CNumberDisplayDelegate
A numeric display format conforming to AAX_IDisplayDelegate.
Definition: AAX_CNumberDisplayDelegate.h:40
AAX_CNumberDisplayDelegate::ValueToString
bool ValueToString(T value, AAX_CString *valueString) const AAX_OVERRIDE
Converts a real parameter value to a string representation.
Definition: AAX_CNumberDisplayDelegate.h:59
AAX_CNumberDisplayDelegate::Clone
AAX_CNumberDisplayDelegate * Clone() const AAX_OVERRIDE
Constructs and returns a copy of the display delegate.
Definition: AAX_CNumberDisplayDelegate.h:53
AAX_CNumberDisplayDelegate::StringToValue
bool StringToValue(const AAX_CString &valueString, T *value) const AAX_OVERRIDE
Converts a string to a real parameter value.
Definition: AAX_CNumberDisplayDelegate.h:93
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::ToDouble
bool ToDouble(double *oValue) const
AAX_CString::Clear
void Clear()
AAX_CString::Erase
AAX_CString & Erase(uint32_t pos, uint32_t n)
AAX_CString::Append
AAX_CString & Append(const AAX_CString &str)
AAX_CString::AppendNumber
AAX_CString & AppendNumber(double number, int32_t precision)
AAX_IDisplayDelegate
Definition: AAX_IDisplayDelegate.h:66