AAX SDK  2.4.1
Avid Audio Extensions Development Kit
AAX_CPercentDisplayDelegateDecorator.h
Go to the documentation of this file.
1 /*================================================================================================*/
2 /*
3  *
4  * Copyright 2014-2017, 2019 by Avid Technology, Inc.
5  * All rights reserved.
6  *
7  * CONFIDENTIAL: This document contains confidential information. Do not
8  * read or examine this document unless you are an Avid Technology employee
9  * or have signed a non-disclosure agreement with Avid Technology which protects
10  * the confidentiality of this document. DO NOT DISCLOSE ANY INFORMATION
11  * CONTAINED IN THIS DOCUMENT TO ANY THIRD-PARTY WITHOUT THE PRIOR WRITTEN CONSENT
12  * OF Avid Technology, INC.
13  *
14  */
15 
22 /*================================================================================================*/
23 
24 
25 #pragma once
26 
27 #ifndef AAX_CPERCENTDISPLAYDELEGATEDECORATOR_H
28 #define AAX_CPERCENTDISPLAYDELEGATEDECORATOR_H
29 
31 
32 #include <cmath>
33 
34 
57 template <typename T>
59 {
60 public:
62 
63  //Virtual Overrides
65  bool ValueToString(T value, AAX_CString* valueString) const AAX_OVERRIDE;
66  bool ValueToString(T value, int32_t maxNumChars, AAX_CString* valueString) const AAX_OVERRIDE;
67  bool StringToValue(const AAX_CString& valueString, T* value) const AAX_OVERRIDE;
68 };
69 
70 template <typename T>
72  AAX_IDisplayDelegateDecorator<T>(displayDelegate)
73 {
74 }
75 
76 template <typename T>
78 {
79  return new AAX_CPercentDisplayDelegateDecorator(*this);
80 }
81 
82 template <typename T>
84 {
85  value *= 100;
86  bool succeeded = AAX_IDisplayDelegateDecorator<T>::ValueToString(value, valueString);
87  *valueString += AAX_CString("%");
88  return succeeded;
89 }
90 
91 template <typename T>
92 bool AAX_CPercentDisplayDelegateDecorator<T>::ValueToString(T value, int32_t maxNumChars, AAX_CString* valueString) const
93 {
94  value *= 100;
95  bool succeeded = AAX_IDisplayDelegateDecorator<T>::ValueToString(value, maxNumChars-1, valueString); //<DMT> Make room for percentage symbol.
96  *valueString += AAX_CString("%");
97  return succeeded;
98 }
99 
100 
101 template <typename T>
103 {
104  //Just call through if there is obviously no unit string.
105  if (valueString.Length() <= 2)
106  {
107  bool success = AAX_IDisplayDelegateDecorator<T>::StringToValue(valueString, value);
108  *value /= 100.0f;
109  return success;
110  }
111 
112  //Just call through if the end of this string does not match the unit string.
113  AAX_CString unitSubString;
114  valueString.SubString(valueString.Length() - 1, 1, &unitSubString);
115  if (unitSubString != AAX_CString("%"))
116  {
117  bool success = AAX_IDisplayDelegateDecorator<T>::StringToValue(valueString, value);
118  *value /= 100.0f;
119  return success;
120  }
121 
122  //Call through with the stripped down value string.
123  AAX_CString valueSubString;
124  valueString.SubString(0, valueString.Length() - 1, &valueSubString);
125  bool success = AAX_IDisplayDelegateDecorator<T>::StringToValue(valueSubString, value);
126  *value /= 100.0f;
127  return success;
128 }
129 
130 
131 #endif
132 
#define AAX_OVERRIDE
override keyword macro
Definition: AAX.h:141
The base class for all concrete display delegate decorators.
A percent decorator conforming to AAX_IDisplayDelegateDecorator.
Definition: AAX_CPercentDisplayDelegateDecorator.h:59
bool ValueToString(T value, AAX_CString *valueString) const AAX_OVERRIDE
Converts a real parameter value to a string representation.
Definition: AAX_CPercentDisplayDelegateDecorator.h:83
bool StringToValue(const AAX_CString &valueString, T *value) const AAX_OVERRIDE
Converts a string to a real parameter value.
Definition: AAX_CPercentDisplayDelegateDecorator.h:102
AAX_CPercentDisplayDelegateDecorator(const AAX_IDisplayDelegate< T > &displayDelegate)
Definition: AAX_CPercentDisplayDelegateDecorator.h:71
AAX_CPercentDisplayDelegateDecorator< T > * Clone() const AAX_OVERRIDE
Constructs and returns a copy of the display delegate.
Definition: AAX_CPercentDisplayDelegateDecorator.h:77
A generic AAX string class with similar functionality to std::string
Definition: AAX_CString.h:46
uint32_t Length() const AAX_OVERRIDE
void SubString(uint32_t pos, uint32_t n, AAX_IString *outputStr) const
Classes for parameter value string conversion.
Definition: AAX_IDisplayDelegate.h:69
The base class for all concrete display delegate decorators.
Definition: AAX_IDisplayDelegateDecorator.h:44
bool StringToValue(const AAX_CString &valueString, T *value) const AAX_OVERRIDE
Converts a string to a real parameter value.
Definition: AAX_IDisplayDelegateDecorator.h:197
bool ValueToString(T value, AAX_CString *valueString) const AAX_OVERRIDE
Converts a string to a real parameter value.
Definition: AAX_IDisplayDelegateDecorator.h:185