1 /* 2 * Copyright (c) 2011-2015, Intel Corporation 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without modification, 6 * are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this 9 * list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation and/or 13 * other materials provided with the distribution. 14 * 15 * 3. Neither the name of the copyright holder nor the names of its contributors 16 * may be used to endorse or promote products derived from this software without 17 * specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 #pragma once 31 32 #include "parameter_export.h" 33 34 #include "SubsystemObject.h" 35 36 class PARAMETER_EXPORT CFormattedSubsystemObject : public CSubsystemObject 37 { 38 public: 39 /** 40 * Builds a new CFormattedSubsystemObject instance, without any mapping information. 41 * 42 * @param[in] pInstanceConfigurableElement Instance of the element linked to the SubsytemObject. 43 * @param[in] logger the logger provided by the client 44 */ 45 CFormattedSubsystemObject(CInstanceConfigurableElement *pInstanceConfigurableElement, 46 core::log::Logger &logger); 47 48 /** 49 * Builds a new CFormattedSubsystemObject instance, using a simple mapping value without Amends. 50 * 51 * @param[in] pInstanceConfigurableElement Instance of the element linked to the SubsytemObject. 52 * @param[in] logger the logger provided by the client 53 * @param[in] strFormattedMapping A std::string corresponding to the mapping of the element. The 54 * std::string does not contain any Amend (%) and does not need to be formatted. 55 */ 56 CFormattedSubsystemObject(CInstanceConfigurableElement *pInstanceConfigurableElement, 57 core::log::Logger &logger, const std::string &strFormattedMapping); 58 59 /** 60 * Builds a new CFormattedSubsystemObject instance, using a mapping value containing Amends. 61 * 62 * @param[in] pInstanceConfigurableElement Instance of the element linked to the SubsytemObject. 63 * @param[in] logger the logger provided by the client 64 * @param[in] strMappingValue A std::string corresponding to the mapping of the element. The 65 * std::string contains Amend (%) and needs to be formatted with information from the context. 66 * @param[in] firstAmendKey Index of the first Amend key 67 * @param[in] nbAmendKeys Number of Amends 68 * @param[in] context Contains values associated to Amend keys 69 */ 70 CFormattedSubsystemObject(CInstanceConfigurableElement *pInstanceConfigurableElement, 71 core::log::Logger &logger, const std::string &strMappingValue, 72 size_t firstAmendKey, size_t nbAmendKeys, 73 const CMappingContext &context); 74 virtual ~CFormattedSubsystemObject() = default; 75 76 /** 77 * Returns the formatted mapping value associated to the element. 78 * 79 * @return A std::string containing the mapping 80 */ 81 virtual std::string getFormattedMappingValue() const; 82 83 private: 84 /** 85 * Check if the index of Amend key is valid. 86 * 87 * @param uiAmendKey Index of the Amend key 88 * 89 * @return true if the index of the Amend key is > 0 and <= 9. 90 */ 91 static bool isAmendKeyValid(size_t uiAmendKey); 92 93 /** 94 * Generic mapping formatting 95 * 96 * Format a std::string from mapping data and its context, replacing amendments by their value 97 * 98 * @param[in] strMappingValue The input mapping std::string containing amendments 99 * @param[in] context firstAmendKey The index of the first Amend key in the key list of the 100 * context 101 * @param[in] nbAmendKeys Number of Amend keys in the context 102 * @param[in] context The context containing Amend values 103 * 104 * @return The formatted std::string, corresponding to the input strMappingValue where %n have 105 * been 106 * replaced by their value 107 */ 108 static std::string formatMappingValue(const std::string &strMappingValue, size_t firstAmendKey, 109 size_t nbAmendKeys, const CMappingContext &context); 110 111 /** 112 * std::string containing the formatted mapping value 113 */ 114 std::string _strFormattedMappingValue; 115 }; 116