| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 1 | /* <auto_header> |
| 2 | * <FILENAME> |
| 3 | * |
| 4 | * INTEL CONFIDENTIAL |
| 5 | * Copyright © 2011 Intel |
| 6 | * Corporation All Rights Reserved. |
| 7 | * |
| 8 | * The source code contained or described herein and all documents related to |
| 9 | * the source code ("Material") are owned by Intel Corporation or its suppliers |
| 10 | * or licensors. Title to the Material remains with Intel Corporation or its |
| 11 | * suppliers and licensors. The Material contains trade secrets and proprietary |
| 12 | * and confidential information of Intel or its suppliers and licensors. The |
| 13 | * Material is protected by worldwide copyright and trade secret laws and |
| 14 | * treaty provisions. No part of the Material may be used, copied, reproduced, |
| 15 | * modified, published, uploaded, posted, transmitted, distributed, or |
| 16 | * disclosed in any way without Intel’s prior express written permission. |
| 17 | * |
| 18 | * No license under any patent, copyright, trade secret or other intellectual |
| 19 | * property right is granted to or conferred upon you by disclosure or delivery |
| 20 | * of the Materials, either expressly, by implication, inducement, estoppel or |
| 21 | * otherwise. Any license under such intellectual property rights must be |
| 22 | * express and approved by Intel in writing. |
| 23 | * |
| 24 | * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com) |
| 25 | * CREATED: 2011-06-01 |
| 26 | * UPDATED: 2011-07-27 |
| 27 | * |
| 28 | * |
| 29 | * </auto_header> |
| 30 | */ |
| 31 | #include "ArrayParameter.h" |
| 32 | #include <sstream> // for istringstream |
| 33 | #include "Tokenizer.h" |
| 34 | #include "ParameterType.h" |
| 35 | #include "ParameterAccessContext.h" |
| 36 | #include "ConfigurationAccessContext.h" |
| 37 | #include "ParameterBlackboard.h" |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame^] | 38 | #include <assert.h> |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 39 | |
| 40 | #define base CParameter |
| 41 | |
| Patrick Benavoli | 2ecf900 | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 42 | CArrayParameter::CArrayParameter(const string& strName, const CTypeElement* pTypeElement) : base(strName, pTypeElement) |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 43 | { |
| 44 | } |
| 45 | |
| 46 | uint32_t CArrayParameter::getFootPrint() const |
| 47 | { |
| Patrick Benavoli | 2ecf900 | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 48 | return getSize() * getArrayLength(); |
| 49 | } |
| 50 | |
| 51 | // Array length |
| 52 | uint32_t CArrayParameter::getArrayLength() const |
| 53 | { |
| 54 | return getTypeElement()->getArrayLength(); |
| 55 | } |
| 56 | |
| 57 | // Element properties |
| 58 | void CArrayParameter::showProperties(string& strResult) const |
| 59 | { |
| 60 | base::showProperties(strResult); |
| 61 | |
| 62 | // Array length |
| 63 | strResult += "Array length: "; |
| 64 | strResult += toString(getArrayLength()); |
| 65 | strResult += "\n"; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | // XML configuration settings parsing |
| Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 69 | bool CArrayParameter::serializeXmlSettings(CXmlElement& xmlConfigurationSettingsElementContent, CConfigurationAccessContext& configurationAccessContext) const |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 70 | { |
| 71 | // Check for value space |
| Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 72 | handleValueSpaceAttribute(xmlConfigurationSettingsElementContent, configurationAccessContext); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 73 | |
| 74 | // Handle access |
| 75 | if (!configurationAccessContext.serializeOut()) { |
| 76 | |
| 77 | // Actually set values to blackboard |
| Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 78 | if (!setValues(0, configurationAccessContext.getBaseOffset(), xmlConfigurationSettingsElementContent.getTextContent(), configurationAccessContext)) { |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 79 | |
| 80 | return false; |
| 81 | } |
| 82 | } else { |
| 83 | |
| 84 | // Get string value |
| 85 | string strValue; |
| 86 | |
| 87 | // Whole array requested |
| 88 | getValues(configurationAccessContext.getBaseOffset(), strValue, configurationAccessContext); |
| 89 | |
| 90 | // Populate value into xml text node |
| Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 91 | xmlConfigurationSettingsElementContent.setTextContent(strValue); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | // Done |
| 95 | return true; |
| 96 | } |
| 97 | |
| 98 | // User set/get |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame^] | 99 | bool CArrayParameter::accessValue(CPathNavigator& pathNavigator, string& strValue, bool bSet, CParameterAccessContext& parameterAccessContext) const |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 100 | { |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 101 | uint32_t uiIndex; |
| 102 | |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame^] | 103 | if (!getIndex(pathNavigator, uiIndex, parameterAccessContext)) { |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 104 | |
| 105 | return false; |
| 106 | } |
| Patrick Benavoli | 4bed921 | 2011-10-27 14:18:00 +0200 | [diff] [blame] | 107 | |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame^] | 108 | if (bSet) { |
| 109 | // Set |
| 110 | if (uiIndex == (uint32_t)-1) { |
| Patrick Benavoli | 4bed921 | 2011-10-27 14:18:00 +0200 | [diff] [blame] | 111 | |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame^] | 112 | // No index provided, start with 0 |
| 113 | uiIndex = 0; |
| 114 | } |
| Patrick Benavoli | 4bed921 | 2011-10-27 14:18:00 +0200 | [diff] [blame] | 115 | |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame^] | 116 | // Actually set values |
| 117 | if (!setValues(uiIndex, 0, strValue, parameterAccessContext)) { |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 118 | |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame^] | 119 | return false; |
| 120 | } |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 121 | |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame^] | 122 | // Synchronize |
| 123 | if (parameterAccessContext.getAutoSync() && !sync(parameterAccessContext)) { |
| 124 | |
| 125 | // Append parameter path to error |
| 126 | parameterAccessContext.appendToError(" " + getPath()); |
| 127 | |
| 128 | return false; |
| 129 | } |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 130 | } else { |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame^] | 131 | // Get |
| 132 | if (uiIndex == (uint32_t)-1) { |
| 133 | |
| 134 | // Whole array requested |
| 135 | getValues(0, strValue, parameterAccessContext); |
| 136 | |
| 137 | } else { |
| 138 | // Scalar requested |
| 139 | doGetValue(strValue, getOffset() + uiIndex * getSize(), parameterAccessContext); |
| 140 | } |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | return true; |
| 144 | } |
| 145 | |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame^] | 146 | // Boolean |
| 147 | bool CArrayParameter::accessAsBooleanArray(vector<bool>& abValues, bool bSet, CParameterAccessContext& parameterAccessContext) const |
| 148 | { |
| 149 | return accessValues(abValues, bSet, parameterAccessContext); |
| 150 | } |
| 151 | |
| 152 | // Integer |
| 153 | bool CArrayParameter::accessAsIntegerArray(vector<uint32_t>& auiValues, bool bSet, CParameterAccessContext& parameterAccessContext) const |
| 154 | { |
| 155 | return accessValues(auiValues, bSet, parameterAccessContext); |
| 156 | } |
| 157 | |
| 158 | // Signed Integer Access |
| 159 | bool CArrayParameter::accessAsSignedIntegerArray(vector<int32_t>& aiValues, bool bSet, CParameterAccessContext& parameterAccessContext) const |
| 160 | { |
| 161 | return accessValues(aiValues, bSet, parameterAccessContext); |
| 162 | } |
| 163 | |
| 164 | // Double Access |
| 165 | bool CArrayParameter::accessAsDoubleArray(vector<double>& adValues, bool bSet, CParameterAccessContext& parameterAccessContext) const |
| 166 | { |
| 167 | return accessValues(adValues, bSet, parameterAccessContext); |
| 168 | } |
| 169 | |
| 170 | // String Access |
| 171 | bool CArrayParameter::accessAsStringArray(vector<string>& astrValues, bool bSet, CParameterAccessContext& parameterAccessContext) const |
| 172 | { |
| 173 | return accessValues(astrValues, bSet, parameterAccessContext); |
| 174 | } |
| 175 | |
| 176 | // Dump |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 177 | void CArrayParameter::logValue(string& strValue, CErrorContext& errorContext) const |
| 178 | { |
| Patrick Benavoli | 2ecf900 | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 179 | // Parameter context |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame^] | 180 | CParameterAccessContext& parameterAccessContext = static_cast<CParameterAccessContext&>(errorContext); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 181 | |
| 182 | // Dump values |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame^] | 183 | getValues(0, strValue, parameterAccessContext); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 184 | } |
| 185 | |
| Patrick Benavoli | 6ccab9d | 2011-11-10 23:21:01 +0100 | [diff] [blame] | 186 | // Used for simulation and virtual subsystems |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 187 | void CArrayParameter::setDefaultValues(CParameterAccessContext& parameterAccessContext) const |
| 188 | { |
| 189 | // Get default value from type |
| 190 | uint32_t uiDefaultValue = static_cast<const CParameterType*>(getTypeElement())->getDefaultValue(); |
| 191 | |
| 192 | // Write blackboard |
| 193 | CParameterBlackboard* pBlackboard = parameterAccessContext.getParameterBlackboard(); |
| 194 | |
| 195 | // Process |
| 196 | uint32_t uiValueIndex; |
| 197 | uint32_t uiSize = getSize(); |
| 198 | uint32_t uiOffset = getOffset(); |
| 199 | bool bSubsystemIsBigEndian = parameterAccessContext.isBigEndianSubsystem(); |
| Patrick Benavoli | 2ecf900 | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 200 | uint32_t uiArrayLength = getArrayLength(); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 201 | |
| Patrick Benavoli | 2ecf900 | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 202 | for (uiValueIndex = 0; uiValueIndex < uiArrayLength; uiValueIndex++) { |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 203 | |
| 204 | // Beware this code works on little endian architectures only! |
| Patrick Benavoli | 1352ae5 | 2011-10-21 16:48:04 +0200 | [diff] [blame] | 205 | pBlackboard->writeInteger(&uiDefaultValue, uiSize, uiOffset, bSubsystemIsBigEndian); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 206 | |
| 207 | uiOffset += uiSize; |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | // Index from path |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame^] | 212 | bool CArrayParameter::getIndex(CPathNavigator& pathNavigator, uint32_t& uiIndex, CParameterAccessContext& parameterAccessContext) const |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 213 | { |
| 214 | uiIndex = (uint32_t)-1; |
| 215 | |
| 216 | string* pStrChildName = pathNavigator.next(); |
| 217 | |
| 218 | if (pStrChildName) { |
| 219 | |
| 220 | // Check index is numeric |
| 221 | istringstream iss(*pStrChildName); |
| 222 | |
| 223 | iss >> uiIndex; |
| 224 | |
| 225 | if (!iss) { |
| 226 | |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame^] | 227 | parameterAccessContext.setError("Expected numerical expression as last item in " + pathNavigator.getCurrentPath()); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 228 | |
| 229 | return false; |
| 230 | } |
| 231 | |
| Patrick Benavoli | 2ecf900 | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 232 | if (uiIndex >= getArrayLength()) { |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 233 | ostringstream oss; |
| 234 | |
| Patrick Benavoli | 2ecf900 | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 235 | oss << "Provided index out of range (max is " << getArrayLength() - 1 << ")"; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 236 | |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame^] | 237 | parameterAccessContext.setError(oss.str()); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 238 | |
| 239 | return false; |
| 240 | } |
| 241 | |
| 242 | // Check no other item provided in path |
| 243 | pStrChildName = pathNavigator.next(); |
| 244 | |
| 245 | if (pStrChildName) { |
| 246 | |
| 247 | // Should be leaf element |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame^] | 248 | parameterAccessContext.setError("Path not found: " + pathNavigator.getCurrentPath()); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 249 | |
| 250 | return false; |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | return true; |
| 255 | } |
| 256 | |
| 257 | // Common set value processing |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame^] | 258 | bool CArrayParameter::setValues(uint32_t uiStartIndex, uint32_t uiBaseOffset, const string& strValue, CParameterAccessContext& parameterAccessContext) const |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 259 | { |
| 260 | // Deal with value(s) |
| Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 261 | Tokenizer tok(strValue, DEFAULT_DELIMITER + ","); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 262 | |
| 263 | vector<string> astrValues = tok.split(); |
| 264 | uint32_t uiNbValues = astrValues.size(); |
| 265 | |
| 266 | // Check number of provided values |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame^] | 267 | if (uiNbValues + uiStartIndex > getArrayLength()) { |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 268 | |
| 269 | // Out of bounds |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame^] | 270 | parameterAccessContext.setError("Too many values provided"); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 271 | |
| 272 | return false; |
| 273 | } |
| 274 | |
| 275 | // Process |
| 276 | uint32_t uiValueIndex; |
| 277 | uint32_t uiSize = getSize(); |
| 278 | uint32_t uiOffset = getOffset() + uiStartIndex * uiSize - uiBaseOffset; |
| 279 | |
| 280 | for (uiValueIndex = 0; uiValueIndex < uiNbValues; uiValueIndex++) { |
| 281 | |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame^] | 282 | if (!doSetValue(astrValues[uiValueIndex], uiOffset, parameterAccessContext)) { |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 283 | |
| 284 | // Append parameter path to error |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame^] | 285 | parameterAccessContext.appendToError(" " + getPath() + "/" + toString(uiValueIndex + uiStartIndex)); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 286 | |
| 287 | return false; |
| 288 | } |
| 289 | |
| 290 | uiOffset += uiSize; |
| 291 | } |
| 292 | return true; |
| 293 | } |
| 294 | |
| 295 | // Common get value processing |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame^] | 296 | void CArrayParameter::getValues(uint32_t uiBaseOffset, string& strValues, CParameterAccessContext& parameterAccessContext) const |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 297 | { |
| 298 | uint32_t uiValueIndex; |
| 299 | uint32_t uiSize = getSize(); |
| 300 | uint32_t uiOffset = getOffset() - uiBaseOffset; |
| Patrick Benavoli | 2ecf900 | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 301 | uint32_t uiArrayLength = getArrayLength(); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 302 | |
| Patrick Benavoli | 4bed921 | 2011-10-27 14:18:00 +0200 | [diff] [blame] | 303 | strValues.clear(); |
| 304 | |
| Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 305 | bool bFirst = true; |
| 306 | |
| Patrick Benavoli | 2ecf900 | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 307 | for (uiValueIndex = 0; uiValueIndex < uiArrayLength; uiValueIndex++) { |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 308 | string strReadValue; |
| 309 | |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame^] | 310 | doGetValue(strReadValue, uiOffset, parameterAccessContext); |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 311 | |
| Patrick Benavoli | 6ba361d | 2011-08-31 11:23:24 +0200 | [diff] [blame] | 312 | if (!bFirst) { |
| 313 | |
| 314 | strValues += " "; |
| 315 | } else { |
| 316 | |
| 317 | bFirst = false; |
| 318 | } |
| 319 | |
| 320 | strValues += strReadValue; |
| Patrick Benavoli | 68a9128 | 2011-08-31 11:23:23 +0200 | [diff] [blame] | 321 | |
| 322 | uiOffset += uiSize; |
| 323 | } |
| 324 | } |
| Patrick Benavoli | 065264a | 2011-11-20 15:46:41 +0100 | [diff] [blame^] | 325 | |
| 326 | // Generic Access |
| 327 | template <typename type> |
| 328 | bool CArrayParameter::accessValues(vector<type>& values, bool bSet, CParameterAccessContext& parameterAccessContext) const |
| 329 | { |
| 330 | bool bSuccess; |
| 331 | |
| 332 | if (bSet) { |
| 333 | |
| 334 | if (setValues(values, parameterAccessContext)) { |
| 335 | |
| 336 | // Synchronize |
| 337 | bSuccess = sync(parameterAccessContext); |
| 338 | } else { |
| 339 | |
| 340 | bSuccess = false; |
| 341 | } |
| 342 | } else { |
| 343 | |
| 344 | bSuccess = getValues(values, parameterAccessContext); |
| 345 | } |
| 346 | if (!bSuccess) { |
| 347 | |
| 348 | // Append parameter path to error |
| 349 | parameterAccessContext.appendToError(" " + getPath()); |
| 350 | } |
| 351 | return bSuccess; |
| 352 | } |
| 353 | |
| 354 | template <typename type> |
| 355 | bool CArrayParameter::setValues(const vector<type>& values, CParameterAccessContext& parameterAccessContext) const |
| 356 | { |
| 357 | uint32_t uiNbValues = getArrayLength(); |
| 358 | uint32_t uiValueIndex; |
| 359 | uint32_t uiSize = getSize(); |
| 360 | uint32_t uiOffset = getOffset(); |
| 361 | |
| 362 | assert(values.size() == uiNbValues); |
| 363 | |
| 364 | // Process |
| 365 | for (uiValueIndex = 0; uiValueIndex < uiNbValues; uiValueIndex++) { |
| 366 | |
| 367 | if (!doSet(values[uiValueIndex], uiOffset, parameterAccessContext)) { |
| 368 | |
| 369 | return false; |
| 370 | } |
| 371 | |
| 372 | uiOffset += uiSize; |
| 373 | } |
| 374 | |
| 375 | return true; |
| 376 | } |
| 377 | |
| 378 | template <typename type> |
| 379 | bool CArrayParameter::getValues(vector<type>& values, CParameterAccessContext& parameterAccessContext) const |
| 380 | { |
| 381 | uint32_t uiNbValues = getArrayLength(); |
| 382 | uint32_t uiValueIndex; |
| 383 | uint32_t uiSize = getSize(); |
| 384 | uint32_t uiOffset = getOffset(); |
| 385 | |
| 386 | values.clear(); |
| 387 | |
| 388 | for (uiValueIndex = 0; uiValueIndex < uiNbValues; uiValueIndex++) { |
| 389 | type readValue; |
| 390 | |
| 391 | if (!doGet(readValue, uiOffset, parameterAccessContext)) { |
| 392 | |
| 393 | return false; |
| 394 | } |
| 395 | |
| 396 | values.push_back(readValue); |
| 397 | |
| 398 | uiOffset += uiSize; |
| 399 | } |
| 400 | return true; |
| 401 | } |
| 402 | |
| 403 | template <typename type> |
| 404 | bool CArrayParameter::doSet(type value, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const |
| 405 | { |
| 406 | uint32_t uiData; |
| 407 | |
| 408 | if (!static_cast<const CParameterType*>(getTypeElement())->toBlackboard(value, uiData, parameterAccessContext)) { |
| 409 | |
| 410 | return false; |
| 411 | } |
| 412 | // Write blackboard |
| 413 | CParameterBlackboard* pBlackboard = parameterAccessContext.getParameterBlackboard(); |
| 414 | |
| 415 | // Beware this code works on little endian architectures only! |
| 416 | pBlackboard->writeInteger(&uiData, getSize(), uiOffset, parameterAccessContext.isBigEndianSubsystem()); |
| 417 | |
| 418 | return true; |
| 419 | } |
| 420 | |
| 421 | template <typename type> |
| 422 | bool CArrayParameter::doGet(type& value, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const |
| 423 | { |
| 424 | uint32_t uiData = 0; |
| 425 | |
| 426 | // Read blackboard |
| 427 | const CParameterBlackboard* pBlackboard = parameterAccessContext.getParameterBlackboard(); |
| 428 | |
| 429 | // Beware this code works on little endian architectures only! |
| 430 | pBlackboard->readInteger(&uiData, getSize(), uiOffset, parameterAccessContext.isBigEndianSubsystem()); |
| 431 | |
| 432 | return static_cast<const CParameterType*>(getTypeElement())->fromBlackboard(value, uiData, parameterAccessContext); |
| 433 | } |
| 434 | |