blob: 063eeaaca934fe117ef4fcf851eb27e12ee49115 [file] [log] [blame]
Patrick Benavoliee65e6d2011-11-20 18:52:24 +01001/* <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 "LinearParameterAdaptation.h"
32
33#define base CParameterAdaptation
34
35CLinearParameterAdaptation::CLinearParameterAdaptation() : base("Linear"), _dSlopeNumerator(1), _dSlopeDenominator(1)
36{
37}
38
39// Element properties
40void CLinearParameterAdaptation::showProperties(string& strResult) const
41{
42 base::showProperties(strResult);
43
44 // SlopeNumerator
45 strResult += " - SlopeNumerator: ";
46 strResult += toString(_dSlopeNumerator);
47 strResult += "\n";
48
49 // SlopeDenominator
50 strResult += " - SlopeDenominator: ";
51 strResult += toString(_dSlopeDenominator);
52 strResult += "\n";
53}
54
55// From IXmlSink
56bool CLinearParameterAdaptation::fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext)
57{
58 // Get SlopeNumerator
59 if (xmlElement.hasAttribute("SlopeNumerator")) {
60
61 _dSlopeNumerator = xmlElement.getAttributeDouble("SlopeNumerator");
62
63 } else {
64 // Default
65 _dSlopeNumerator = 1;
66 }
67 // Get SlopeDenominator
68 if (xmlElement.hasAttribute("SlopeDenominator")) {
69
70 _dSlopeDenominator = xmlElement.getAttributeDouble("SlopeDenominator");
71
72 // Avoid by 0 division errors
73 if (_dSlopeDenominator == 0) {
74
75 serializingContext.setError("SlopeDenominator attribute can't be 0 on element" + xmlElement.getPath());
76
77 return false;
78 }
79
80 } else {
81 // Default
82 _dSlopeDenominator = 1;
83 }
84
85 // Base
86 return base::fromXml(xmlElement, serializingContext);
87}
88
89// Conversions
90int64_t CLinearParameterAdaptation::fromUserValue(double dValue) const
91{
92 return base::fromUserValue(dValue * _dSlopeNumerator / _dSlopeDenominator);
93}
94
95double CLinearParameterAdaptation::toUserValue(int64_t iValue) const
96{
97 return base::toUserValue(iValue) * _dSlopeDenominator / _dSlopeNumerator;
98}