AAX SDK 2.8.0
Avid Audio Extensions Development Kit
Loading...
Searching...
No Matches
AAX_CStringDisplayDelegate.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_CSTRINGDISPLAYDELEGATE_H
36#define AAX_CSTRINGDISPLAYDELEGATE_H
37
39#include <sstream>
40#include <map>
41
42
55template <typename T>
57{
58public:
70 AAX_CStringDisplayDelegate(const std::map<T,AAX_CString>& stringMap);
71
72 //Virtual Overrides
74 bool ValueToString(T value, AAX_CString* valueString) const AAX_OVERRIDE;
75 bool ValueToString(T value, int32_t maxNumChars, AAX_CString* valueString) const AAX_OVERRIDE;
76 bool StringToValue(const AAX_CString& valueString, T* value) const AAX_OVERRIDE;
77
78protected:
79 std::map<T, AAX_CString> mStringMap;
80 std::map<AAX_CString, T> mInverseStringMap;
81};
82
83
84
85template <typename T>
86AAX_CStringDisplayDelegate<T>::AAX_CStringDisplayDelegate(const std::map<T,AAX_CString>& stringMap) :
88 mStringMap(stringMap),
89 mInverseStringMap()
90{
91 //Construct an inverse string map from our already copied internal copy of the string map.
92 //This inverse map is used for stringToValue conversion.
93 typename std::map<T,AAX_CString>::iterator valueStringIterator = mStringMap.begin();
94 while ( valueStringIterator != mStringMap.end() )
95 {
96 mInverseStringMap.insert(std::pair<AAX_CString, T>(valueStringIterator->second, valueStringIterator->first));
97 valueStringIterator++;
98 }
99}
100
101template <typename T>
103{
104 return new AAX_CStringDisplayDelegate(*this);
105}
106
107template <typename T>
109{
110 typename std::map<T,AAX_CString>::const_iterator mapPairIterator = mStringMap.find(value);
111 if( mapPairIterator != mStringMap.end() )
112 {
113 *valueString = mapPairIterator->second;
114 return true;
115 }
116 *valueString = AAX_CString("String Not Found");
117 return false;
118}
119
120template <typename T>
121bool AAX_CStringDisplayDelegate<T>::ValueToString(T value, int32_t /*maxNumChars*/, AAX_CString* valueString) const
122{
123 // First, get the full length string.
124 bool result = this->ValueToString(value, valueString);
125
126 //<DMT> TODO: Shorten the string based on the number of characters...
127
128 return result;
129}
130
131template <typename T>
132bool AAX_CStringDisplayDelegate<T>::StringToValue(const AAX_CString& valueString, T* value) const
133{
134 typename std::map<AAX_CString, T>::const_iterator mapPairIterator = mInverseStringMap.find(valueString);
135 if( mapPairIterator != mInverseStringMap.end() )
136 {
137 *value = mapPairIterator->second;
138 return true;
139 }
140 *value = 0;
141 return false;
142}
143
144
145
146
147#endif //AAX_CSTRINGDISPLAYDELEGATE_H
Defines the display behavior for a parameter.
#define AAX_OVERRIDE
override keyword macro
Definition: AAX.h:164
A generic AAX string class with similar functionality to std::string
Definition: AAX_CString.h:57
A string, or list, display format conforming to AAX_IDisplayDelegate.
Definition: AAX_CStringDisplayDelegate.h:57
AAX_CStringDisplayDelegate< T > * Clone() const AAX_OVERRIDE
Constructs and returns a copy of the display delegate.
Definition: AAX_CStringDisplayDelegate.h:102
std::map< AAX_CString, T > mInverseStringMap
Definition: AAX_CStringDisplayDelegate.h:80
bool StringToValue(const AAX_CString &valueString, T *value) const AAX_OVERRIDE
Converts a string to a real parameter value.
Definition: AAX_CStringDisplayDelegate.h:132
AAX_CStringDisplayDelegate(const std::map< T, AAX_CString > &stringMap)
Constructor.
Definition: AAX_CStringDisplayDelegate.h:86
bool ValueToString(T value, AAX_CString *valueString) const AAX_OVERRIDE
Converts a real parameter value to a string representation.
Definition: AAX_CStringDisplayDelegate.h:108
std::map< T, AAX_CString > mStringMap
Definition: AAX_CStringDisplayDelegate.h:79
Definition: AAX_IDisplayDelegate.h:79