|
32 | 32 | #include "ParameterAccessContext.h" |
33 | 33 | #include "convert.hpp" |
34 | 34 |
|
| 35 | +#include <iomanip> |
| 36 | + |
35 | 37 | #define base CParameterType |
36 | 38 |
|
37 | 39 | using std::string; |
@@ -129,20 +131,46 @@ int32_t CEnumParameterType::getMax() const |
129 | 131 | } |
130 | 132 |
|
131 | 133 | bool CEnumParameterType::fromBlackboard(string &userValue, const uint32_t &value, |
132 | | - CParameterAccessContext & /*ctx*/) const |
| 134 | + CParameterAccessContext &ctx) const |
133 | 135 | { |
134 | 136 | // Convert the raw value from the blackboard |
135 | 137 | int32_t signedValue = static_cast<int32_t>(value); |
136 | 138 | signExtend(signedValue); |
137 | 139 |
|
138 | | - // Convert from numerical space to literal space |
139 | | - return getLiteral(signedValue, userValue); |
| 140 | + // Take care of format |
| 141 | + if (ctx.valueSpaceIsRaw()) { |
| 142 | + |
| 143 | + // Format |
| 144 | + std::ostringstream sstream; |
| 145 | + |
| 146 | + // Numerical format requested |
| 147 | + if (ctx.outputRawFormatIsHex()) { |
| 148 | + |
| 149 | + // Hexa display with unecessary bits cleared out |
| 150 | + sstream << "0x" << std::hex << std::uppercase |
| 151 | + << std::setw(static_cast<int>(getSize() * 2)) << std::setfill('0') |
| 152 | + << makeEncodable(value); |
| 153 | + |
| 154 | + userValue = sstream.str(); |
| 155 | + } else { |
| 156 | + userValue = std::to_string(value); |
| 157 | + } |
| 158 | + } else { |
| 159 | + // Literal display requested (should succeed) |
| 160 | + getLiteral(signedValue, userValue); |
| 161 | + } |
| 162 | + return true; |
140 | 163 | } |
141 | 164 |
|
142 | 165 | // Value access |
143 | 166 | bool CEnumParameterType::toBlackboard(int32_t userValue, uint32_t &value, |
144 | 167 | CParameterAccessContext ¶meterAccessContext) const |
145 | 168 | { |
| 169 | + // Take care of format |
| 170 | + if (parameterAccessContext.valueSpaceIsRaw()) { |
| 171 | + signExtend(userValue); |
| 172 | + } |
| 173 | + |
146 | 174 | if (!checkValueAgainstSpace(userValue)) { |
147 | 175 |
|
148 | 176 | parameterAccessContext.setError(std::to_string(userValue) + |
|
0 commit comments