| Frederic Boisnard | 6cae0ec | 2013-05-23 18:48:58 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * INTEL CONFIDENTIAL |
| 3 | * Copyright © 2013 Intel |
| 4 | * Corporation All Rights Reserved. |
| 5 | * |
| 6 | * The source code contained or described herein and all documents related to |
| 7 | * the source code ("Material") are owned by Intel Corporation or its suppliers |
| 8 | * or licensors. Title to the Material remains with Intel Corporation or its |
| 9 | * suppliers and licensors. The Material contains trade secrets and proprietary |
| 10 | * and confidential information of Intel or its suppliers and licensors. The |
| 11 | * Material is protected by worldwide copyright and trade secret laws and |
| 12 | * treaty provisions. No part of the Material may be used, copied, reproduced, |
| 13 | * modified, published, uploaded, posted, transmitted, distributed, or |
| 14 | * disclosed in any way without Intel’s prior express written permission. |
| 15 | * |
| 16 | * No license under any patent, copyright, trade secret or other intellectual |
| 17 | * property right is granted to or conferred upon you by disclosure or delivery |
| 18 | * of the Materials, either expressly, by implication, inducement, estoppel or |
| 19 | * otherwise. Any license under such intellectual property rights must be |
| 20 | * express and approved by Intel in writing. |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include "FormattedSubsystemObject.h" |
| 25 | #include "InstanceConfigurableElement.h" |
| 26 | #include "MappingContext.h" |
| 27 | #include <assert.h> |
| 28 | |
| 29 | #define base CSubsystemObject |
| 30 | |
| 31 | CFormattedSubsystemObject::CFormattedSubsystemObject( |
| 32 | CInstanceConfigurableElement* pInstanceConfigurableElement) |
| 33 | : base(pInstanceConfigurableElement) |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | CFormattedSubsystemObject::CFormattedSubsystemObject( |
| 38 | CInstanceConfigurableElement* pInstanceConfigurableElement, |
| 39 | const string& strMappingValue) |
| 40 | : base(pInstanceConfigurableElement), _strFormattedMappingValue(strMappingValue) |
| 41 | { |
| 42 | |
| 43 | } |
| 44 | |
| 45 | |
| 46 | CFormattedSubsystemObject::CFormattedSubsystemObject( |
| 47 | CInstanceConfigurableElement* pInstanceConfigurableElement, |
| 48 | const string& strMappingValue, |
| 49 | uint32_t uiFirstAmendKey, |
| 50 | uint32_t uiNbAmendKeys, |
| 51 | const CMappingContext& context) |
| 52 | : base(pInstanceConfigurableElement), _strFormattedMappingValue(strMappingValue) |
| 53 | { |
| 54 | // Cope with quotes in the name |
| 55 | if (strMappingValue[0] == '\'' && strMappingValue.length() >= 2) { |
| 56 | |
| 57 | _strFormattedMappingValue = strMappingValue.substr(1, strMappingValue.length() - 2); |
| 58 | } |
| 59 | _strFormattedMappingValue = formatMappingValue(_strFormattedMappingValue, uiFirstAmendKey, |
| 60 | uiNbAmendKeys, context); |
| 61 | } |
| 62 | |
| 63 | CFormattedSubsystemObject::~CFormattedSubsystemObject() |
| 64 | { |
| 65 | } |
| 66 | |
| 67 | string CFormattedSubsystemObject::getFormattedMappingValue() const |
| 68 | { |
| 69 | return _strFormattedMappingValue; |
| 70 | } |
| 71 | |
| 72 | bool CFormattedSubsystemObject::isAmendKeyValid(uint32_t uiAmendKey) |
| 73 | { |
| 74 | |
| 75 | return (uiAmendKey > 0) && (uiAmendKey <= 9); |
| 76 | } |
| 77 | |
| 78 | string CFormattedSubsystemObject::formatMappingValue(const string& strMappingValue, |
| 79 | uint32_t uiFirstAmendKey, |
| 80 | uint32_t uiNbAmendKeys, |
| 81 | const CMappingContext& context) |
| 82 | { |
| 83 | string strFormattedValue = strMappingValue; |
| 84 | |
| 85 | // Search for amendment (only one supported for now) |
| 86 | size_t uiPercentPos = strFormattedValue.find('%', 0); |
| 87 | |
| 88 | // Amendment limited to one digit (values from 1 to 9) |
| 89 | assert(isAmendKeyValid(uiNbAmendKeys)); |
| 90 | |
| 91 | // Check we found one and that there's room for value |
| 92 | if (uiPercentPos != string::npos && uiPercentPos < strFormattedValue.size() - 1) { |
| 93 | |
| 94 | // Get Amend number |
| 95 | uint32_t uiAmendNumber = strFormattedValue[uiPercentPos + 1] - '0'; |
| 96 | |
| 97 | // Check if current Amend number is Valid |
| 98 | if ((uiAmendNumber > 0) && (uiAmendNumber <= uiNbAmendKeys)) { |
| 99 | |
| 100 | uint32_t uiAmendType = uiFirstAmendKey + uiAmendNumber - 1; |
| 101 | |
| 102 | // Check if current Amend type is Set in the context |
| 103 | if (context.iSet(uiAmendType)) { |
| 104 | |
| 105 | // Make the amendment on the part of the string after the current Amend |
| 106 | string strEndOfLine = strFormattedValue.substr(uiPercentPos + 2, |
| 107 | strFormattedValue.size() |
| 108 | - uiPercentPos - 2); |
| 109 | string strEndOfLineAmended = formatMappingValue(strEndOfLine, uiFirstAmendKey, |
| 110 | uiNbAmendKeys, context); |
| 111 | |
| 112 | // Get current Amend value |
| 113 | string strAmendValue = context.getItem(uiAmendType); |
| 114 | |
| 115 | // Make the amendment |
| 116 | strFormattedValue = strFormattedValue.substr(0, uiPercentPos) + strAmendValue |
| 117 | + strEndOfLineAmended; |
| 118 | |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | return strFormattedValue; |
| 123 | } |