AAX SDK  2.4.1
Avid Audio Extensions Development Kit
AAX_CUnitDisplayDelegateDecorator.h
Go to the documentation of this file.
1 /*================================================================================================*/
2 /*
3  *
4  * Copyright 2013-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 #ifndef AAX_CUNITDISPLAYDELEGATEDECORATOR_H
26 #define AAX_CUNITDISPLAYDELEGATEDECORATOR_H
27 
29 
30 
45 template <typename T>
47 {
48 public:
57  AAX_CUnitDisplayDelegateDecorator(const AAX_IDisplayDelegate<T>& displayDelegate, const AAX_CString& unitString);
58 
59  //Virtual Overrides
61  bool ValueToString(T value, AAX_CString* valueString) const AAX_OVERRIDE;
62  bool ValueToString(T value, int32_t maxNumChars, AAX_CString* valueString) const AAX_OVERRIDE;
63  bool StringToValue(const AAX_CString& valueString, T* value) const AAX_OVERRIDE;
64 
65 protected:
67 };
68 
69 
70 
71 
72 template <typename T>
74  AAX_IDisplayDelegateDecorator<T>(displayDelegate),
75  mUnitString(unitString)
76 {
77 
78 }
79 
80 template <typename T>
82 {
83  return new AAX_CUnitDisplayDelegateDecorator(*this);
84 }
85 
86 template <typename T>
88 {
89  bool succeeded = AAX_IDisplayDelegateDecorator<T>::ValueToString(value, valueString);
90  *valueString += mUnitString;
91  return succeeded;
92 }
93 
94 template <typename T>
95 bool AAX_CUnitDisplayDelegateDecorator<T>::ValueToString(T value, int32_t maxNumChars, AAX_CString* valueString) const
96 {
97  bool succeeded = AAX_IDisplayDelegateDecorator<T>::ValueToString(value, maxNumChars, valueString);
98  uint32_t strlen = valueString->Length();
99  const uint32_t maxNumCharsUnsigned = (0 <= maxNumChars) ? static_cast<uint32_t>(maxNumChars) : 0;
100  if (maxNumCharsUnsigned > strlen && (maxNumCharsUnsigned-strlen >= mUnitString.Length()))
101  *valueString += mUnitString;
102  return succeeded;
103 }
104 
105 
106 template <typename T>
107 bool AAX_CUnitDisplayDelegateDecorator<T>::StringToValue(const AAX_CString& valueString, T* value) const
108 {
109  //Just call through if there is obviously no unit string.
110  if (valueString.Length() <= mUnitString.Length())
111  return AAX_IDisplayDelegateDecorator<T>::StringToValue(valueString, value);
112 
113  //Just call through if the end of this string does not match the unit string.
114  AAX_CString unitSubString;
115  valueString.SubString(valueString.Length() - mUnitString.Length(), mUnitString.Length(), &unitSubString);
116  if (unitSubString != mUnitString)
117  return AAX_IDisplayDelegateDecorator<T>::StringToValue(valueString, value);
118 
119  //Call through with the stripped down value string.
120  AAX_CString valueSubString;
121  valueString.SubString(0, valueString.Length() - mUnitString.Length(), &valueSubString);
122  return AAX_IDisplayDelegateDecorator<T>::StringToValue(valueSubString, value);
123 }
124 
125 
126 
127 
128 
129 #endif //AAX_CUNITDISPLAYDELEGATEDECORATOR_H
#define AAX_OVERRIDE
override keyword macro
Definition: AAX.h:141
The base class for all concrete display delegate decorators.
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
A unit type decorator conforming to AAX_IDisplayDelegateDecorator.
Definition: AAX_CUnitDisplayDelegateDecorator.h:47
bool StringToValue(const AAX_CString &valueString, T *value) const AAX_OVERRIDE
Converts a string to a real parameter value.
Definition: AAX_CUnitDisplayDelegateDecorator.h:107
const AAX_CString mUnitString
Definition: AAX_CUnitDisplayDelegateDecorator.h:66
bool ValueToString(T value, AAX_CString *valueString) const AAX_OVERRIDE
Converts a real parameter value to a string representation.
Definition: AAX_CUnitDisplayDelegateDecorator.h:87
AAX_CUnitDisplayDelegateDecorator(const AAX_IDisplayDelegate< T > &displayDelegate, const AAX_CString &unitString)
Constructor.
Definition: AAX_CUnitDisplayDelegateDecorator.h:73
AAX_CUnitDisplayDelegateDecorator< T > * Clone() const AAX_OVERRIDE
Constructs and returns a copy of the display delegate.
Definition: AAX_CUnitDisplayDelegateDecorator.h:81
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