blob: 261597856d3d049a9e2a414d40deeac4a92c124b [file] [log] [blame]
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02001/*
David Wagnerb76c9d62014-02-05 18:30:24 +01002 * Copyright (c) 2011-2014, Intel Corporation
3 * All rights reserved.
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02004 *
David Wagnerb76c9d62014-02-05 18:30:24 +01005 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +02007 *
David Wagnerb76c9d62014-02-05 18:30:24 +01008 * 1. Redistributions of source code must retain the above copyright notice, this
9 * list of conditions and the following disclaimer.
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +020010 *
David Wagnerb76c9d62014-02-05 18:30:24 +010011 * 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.
Frederic Boisnard6cae0ec2013-05-23 18:48:58 +020029 */
30#pragma once
31
32#include "SubsystemObject.h"
33
34class CFormattedSubsystemObject : public CSubsystemObject
35{
36public:
37 /**
38 * Builds a new CFormattedSubsystemObject instance, without any mapping information.
39 *
40 * @param[in] pInstanceConfigurableElement Instance of the element linked to the SubsytemObject.
41 */
42 CFormattedSubsystemObject(CInstanceConfigurableElement* pInstanceConfigurableElement);
43
44 /**
45 * Builds a new CFormattedSubsystemObject instance, using a simple mapping value without Amends.
46 *
47 * @param[in] pInstanceConfigurableElement Instance of the element linked to the SubsytemObject.
48 * @param[in] strFormattedMapping A string corresponding to the mapping of the element. The
49 * string does not contain any Amend (%) and does not need to be formatted.
50 */
51 CFormattedSubsystemObject(CInstanceConfigurableElement* pInstanceConfigurableElement,
52 const string& strFormattedMapping);
53
54 /**
55 * Builds a new CFormattedSubsystemObject instance, using a mapping value containing Amends.
56 *
57 * @param[in] pInstanceConfigurableElement Instance of the element linked to the SubsytemObject.
58 * @param[in] strMappingValue A string corresponding to the mapping of the element. The
59 * string contains Amend (%) and needs to be formatted with information from the context.
60 * @param[in] uiFirstAmendKey Index of the first Amend key
61 * @param[in] uiNbAmendKeys Number of Amends
62 * @param[in] context Contains values associated to Amend keys
63 */
64 CFormattedSubsystemObject(CInstanceConfigurableElement* pInstanceConfigurableElement,
65 const string& strMappingValue,
66 uint32_t uiFirstAmendKey,
67 uint32_t uiNbAmendKeys,
68 const CMappingContext& context);
69 virtual ~CFormattedSubsystemObject();
70
71 /**
72 * Returns the formatted mapping value associated to the element.
73 *
74 * @return A string containing the mapping
75 */
76 virtual string getFormattedMappingValue() const;
77
78private:
79
80 /**
81 * Check if the index of Amend key is valid.
82 *
83 * @param uiAmendKey Index of the Amend key
84 *
85 * @return true if the index of the Amend key is > 0 and <= 9.
86 */
87 static bool isAmendKeyValid(uint32_t uiAmendKey);
88
89 /**
90 * Generic mapping formatting
91 *
92 * Format a string from mapping data and its context, replacing amendments by their value
93 *
94 * @param[in] strMappingValue The input mapping string containing amendments
95 * @param[in] context uiFirstAmendKey The index of the first Amend key in the key list of the
96 * context
97 * @param[in] uiNbAmendKeys Number of Amend keys in the context
98 * @param[in] context The context containing Amend values
99 *
100 * @return The formatted string, corresponding to the input strMappingValue where %n have been
101 * replaced by their value
102 */
103 static string formatMappingValue(const string& strMappingValue,
104 uint32_t uiFirstAmendKey,
105 uint32_t uiNbAmendKeys,
106 const CMappingContext& context);
107
108 /**
109 * string containing the formatted mapping value
110 */
111 string _strFormattedMappingValue;
112};