1b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner/*
2b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * Copyright (c) 2011-2014, Intel Corporation
3b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * All rights reserved.
4b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner *
5b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * Redistribution and use in source and binary forms, with or without modification,
6b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * are permitted provided that the following conditions are met:
7b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner *
8b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * 1. Redistributions of source code must retain the above copyright notice, this
9b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * list of conditions and the following disclaimer.
10b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner *
11b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * 2. Redistributions in binary form must reproduce the above copyright notice,
12b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * this list of conditions and the following disclaimer in the documentation and/or
13b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * other materials provided with the distribution.
14b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner *
15b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * 3. Neither the name of the copyright holder nor the names of its contributors
16b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * may be used to endorse or promote products derived from this software without
17b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * specific prior written permission.
18b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner *
19b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28b76c9d6de717a9a1cfd94e7a8eca7ee4a2035cd7David Wagner * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2968a912857707864bbaaff9808717813105072a6ePatrick Benavoli */
3068a912857707864bbaaff9808717813105072a6ePatrick Benavoli#pragma once
3168a912857707864bbaaff9808717813105072a6ePatrick Benavoli
3268a912857707864bbaaff9808717813105072a6ePatrick Benavoli#include "ParameterType.h"
3368a912857707864bbaaff9808717813105072a6ePatrick Benavoli
34d9526499d6ab53b7d13d1434f748f6f2161c2e0aSebastien Gonzalve#include <string>
35d9526499d6ab53b7d13d1434f748f6f2161c2e0aSebastien Gonzalve
3668a912857707864bbaaff9808717813105072a6ePatrick Benavoliclass CFixedPointParameterType : public CParameterType
3768a912857707864bbaaff9808717813105072a6ePatrick Benavoli{
3868a912857707864bbaaff9808717813105072a6ePatrick Benavolipublic:
399368eea42a1afb01dd44110582f997115b50e742François Gaffie    CFixedPointParameterType(const std::string &strName);
4068a912857707864bbaaff9808717813105072a6ePatrick Benavoli
4168a912857707864bbaaff9808717813105072a6ePatrick Benavoli    // From IXmlSink
429368eea42a1afb01dd44110582f997115b50e742François Gaffie    virtual bool fromXml(const CXmlElement &xmlElement, CXmlSerializingContext &serializingContext);
4368a912857707864bbaaff9808717813105072a6ePatrick Benavoli
44326a31df0dd401283de6170ed09bcf605f61ef7dGeorges-Henri Baron    // From IXmlSource
459368eea42a1afb01dd44110582f997115b50e742François Gaffie    virtual void toXml(CXmlElement &xmlElement, CXmlSerializingContext &serializingContext) const;
46326a31df0dd401283de6170ed09bcf605f61ef7dGeorges-Henri Baron
4768a912857707864bbaaff9808717813105072a6ePatrick Benavoli    // XML Serialization value space handling
4868a912857707864bbaaff9808717813105072a6ePatrick Benavoli    // Value space handling for configuration import
499368eea42a1afb01dd44110582f997115b50e742François Gaffie    virtual void handleValueSpaceAttribute(
509368eea42a1afb01dd44110582f997115b50e742François Gaffie        CXmlElement &xmlConfigurableElementSettingsElement,
519368eea42a1afb01dd44110582f997115b50e742François Gaffie        CConfigurationAccessContext &configurationAccessContext) const;
5268a912857707864bbaaff9808717813105072a6ePatrick Benavoli
53065264a93ce9c63b6a5c95e985188ee33ba587d3Patrick Benavoli    /// Conversion
54065264a93ce9c63b6a5c95e985188ee33ba587d3Patrick Benavoli    // String
559368eea42a1afb01dd44110582f997115b50e742François Gaffie    virtual bool toBlackboard(const std::string &strValue, uint32_t &uiValue,
569368eea42a1afb01dd44110582f997115b50e742François Gaffie                              CParameterAccessContext &parameterAccessContext) const;
579368eea42a1afb01dd44110582f997115b50e742François Gaffie    virtual bool fromBlackboard(std::string &strValue, const uint32_t &uiValue,
589368eea42a1afb01dd44110582f997115b50e742François Gaffie                                CParameterAccessContext &parameterAccessContext) const;
59065264a93ce9c63b6a5c95e985188ee33ba587d3Patrick Benavoli    // Double
609368eea42a1afb01dd44110582f997115b50e742François Gaffie    virtual bool toBlackboard(double dUserValue, uint32_t &uiValue,
619368eea42a1afb01dd44110582f997115b50e742François Gaffie                              CParameterAccessContext &parameterAccessContext) const;
629368eea42a1afb01dd44110582f997115b50e742François Gaffie    virtual bool fromBlackboard(double &dUserValue, uint32_t uiValue,
639368eea42a1afb01dd44110582f997115b50e742François Gaffie                                CParameterAccessContext &parameterAccessContext) const;
6468a912857707864bbaaff9808717813105072a6ePatrick Benavoli
652ecf900ad8c30ce9f8e81f57977a1a80a6f6d8afPatrick Benavoli    // Element properties
669368eea42a1afb01dd44110582f997115b50e742François Gaffie    virtual void showProperties(std::string &strResult) const;
672ecf900ad8c30ce9f8e81f57977a1a80a6f6d8afPatrick Benavoli
6868a912857707864bbaaff9808717813105072a6ePatrick Benavoli    // CElement
69d9526499d6ab53b7d13d1434f748f6f2161c2e0aSebastien Gonzalve    virtual std::string getKind() const;
709368eea42a1afb01dd44110582f997115b50e742François Gaffie
7168a912857707864bbaaff9808717813105072a6ePatrick Benavoliprivate:
7268a912857707864bbaaff9808717813105072a6ePatrick Benavoli    // Util size
739368eea42a1afb01dd44110582f997115b50e742François Gaffie    size_t getUtilSizeInBits() const;
748b01852701d50869318663f568270f977d93dbdfFrederic Boisnard    // Range computation
759368eea42a1afb01dd44110582f997115b50e742François Gaffie    void getRange(double &dMin, double &dMax) const;
76a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie
77a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie    /**
78a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     * Convert a decimal raw represented string into an unsigned long integer.
79a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     * In case of a failing conversion or encodability, this function set the error to
80a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     * illegal value provided and gives the range allowed for the parameter.
81a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     *
82a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     * @param[in] strValue Parameter read from the XML file representated as a string in decimal
83a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     *                     raw format
84a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     * @param[out] uiValue Parameter representated as a long unsigned integer.
859368eea42a1afb01dd44110582f997115b50e742François Gaffie     * @param[in,out] parameterAccessContext Parameter access context.
86a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     *
87a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     * @return true if the string was successfully converted, false otherwise.
88a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     */
899368eea42a1afb01dd44110582f997115b50e742François Gaffie    bool convertFromDecimal(const std::string &strValue, uint32_t &uiValue,
909368eea42a1afb01dd44110582f997115b50e742François Gaffie                            CParameterAccessContext &parameterAccessContext) const;
91a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie
92a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie    /**
93a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     * Convert an hexadecimal raw represented string into an unsigned long integer.
94a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     * In case of a failing conversion or encodability, this function set the error to
95a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     * illegal value provided and gives the range allowed for the parameter.
96a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     *
97a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     * @param[in] strValue Parameter read from the XML file representated as a string in hexadecimal
98a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     *                     raw format
99a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     * @param[out] uiValue Parameter representated as a long unsigned integer.
1009368eea42a1afb01dd44110582f997115b50e742François Gaffie     * @param[in,out] parameterAccessContext Parameter access context.
101a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     *
102a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     * @return true if the string was successfully converted, false otherwise.
103a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     */
1049368eea42a1afb01dd44110582f997115b50e742François Gaffie    bool convertFromHexadecimal(const std::string &strValue, uint32_t &uiValue,
1059368eea42a1afb01dd44110582f997115b50e742François Gaffie                                CParameterAccessContext &parameterAccessContext) const;
106a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie
107a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie    /**
108a24e61fddaf09d2989fff25785e329454c842d7fMattijs Korpershoek     * Convert a Qn.m represented string into an unsigned long integer.
109a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     * In case of a failing conversion or encodability, this function set the error to
110a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     * illegal value provided and gives the range allowed for the parameter.
111a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     *
112a24e61fddaf09d2989fff25785e329454c842d7fMattijs Korpershoek     * @param[in] strValue Parameter read from the XML file representated as a string in Qn.m
113a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     *                     representation.
114a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     * @param[out] uiValue Parameter representated as a long unsigned integer.
1159368eea42a1afb01dd44110582f997115b50e742François Gaffie     * @param[in,out] parameterAccessContext Parameter access context.
116a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     *
117a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     * @return true if the string was successfully converted, false otherwise.
118a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     */
1199368eea42a1afb01dd44110582f997115b50e742François Gaffie    bool convertFromQnm(const std::string &strValue, uint32_t &uiValue,
1209368eea42a1afb01dd44110582f997115b50e742François Gaffie                        CParameterAccessContext &parameterAccessContext) const;
121a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie
122a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie    /**
123a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     * Set the out of range error.
124a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     * In case of a failing conversion or encodability, this function set the error to
125a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     * illegal value provided and gives the range allowed for the parameter.
126a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     *
127a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     * @param[in] strValue Parameter read from the XML file representated as a string
1289368eea42a1afb01dd44110582f997115b50e742François Gaffie     * @param[in,out] parameterAccessContext Parameter Access Context
129a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie     */
1309368eea42a1afb01dd44110582f997115b50e742François Gaffie    void setOutOfRangeError(const std::string &strValue,
1319368eea42a1afb01dd44110582f997115b50e742François Gaffie                            CParameterAccessContext &parameterAccessContext) const;
132a17d5a584a9b681e2eb48465815d275eb5fccb8fFrancois Gaffie
1338b01852701d50869318663f568270f977d93dbdfFrederic Boisnard    // Check if data is encodable
1348b01852701d50869318663f568270f977d93dbdfFrederic Boisnard    bool checkValueAgainstRange(double dValue) const;
135a24e61fddaf09d2989fff25785e329454c842d7fMattijs Korpershoek
136a24e61fddaf09d2989fff25785e329454c842d7fMattijs Korpershoek    /**
137a24e61fddaf09d2989fff25785e329454c842d7fMattijs Korpershoek     * Convert a double towards a Qn.m representation which is stored in binary format.
138a24e61fddaf09d2989fff25785e329454c842d7fMattijs Korpershoek     * This value is rounded if the double is not encodable in the corresponding Qn.m format.
139a24e61fddaf09d2989fff25785e329454c842d7fMattijs Korpershoek     *
140a24e61fddaf09d2989fff25785e329454c842d7fMattijs Korpershoek     * @param[in] dValue the double which should be converted.
141a24e61fddaf09d2989fff25785e329454c842d7fMattijs Korpershoek     *
142a24e61fddaf09d2989fff25785e329454c842d7fMattijs Korpershoek     * @return the integer which contains the converted Qn.m number.
143a24e61fddaf09d2989fff25785e329454c842d7fMattijs Korpershoek     */
144a24e61fddaf09d2989fff25785e329454c842d7fMattijs Korpershoek    int32_t doubleToBinaryQnm(double dValue) const;
145a24e61fddaf09d2989fff25785e329454c842d7fMattijs Korpershoek
146a24e61fddaf09d2989fff25785e329454c842d7fMattijs Korpershoek    /**
147a24e61fddaf09d2989fff25785e329454c842d7fMattijs Korpershoek     * Convert a Qn.m binary number towards its double representation.
148a24e61fddaf09d2989fff25785e329454c842d7fMattijs Korpershoek     *
149a24e61fddaf09d2989fff25785e329454c842d7fMattijs Korpershoek     * @param[in] iValue the integer which contains the Qn.m number which should be converted.
150a24e61fddaf09d2989fff25785e329454c842d7fMattijs Korpershoek     *
151a24e61fddaf09d2989fff25785e329454c842d7fMattijs Korpershoek     * @return the double which contains the double representation of iValue.
152a24e61fddaf09d2989fff25785e329454c842d7fMattijs Korpershoek     */
153a24e61fddaf09d2989fff25785e329454c842d7fMattijs Korpershoek    double binaryQnmToDouble(int32_t iValue) const;
15468a912857707864bbaaff9808717813105072a6ePatrick Benavoli
15568a912857707864bbaaff9808717813105072a6ePatrick Benavoli    // Integral part in Q notation
1569368eea42a1afb01dd44110582f997115b50e742François Gaffie    uint32_t _uiIntegral{0};
15768a912857707864bbaaff9808717813105072a6ePatrick Benavoli    // Fractional part in Q notation
1589368eea42a1afb01dd44110582f997115b50e742François Gaffie    uint32_t _uiFractional{0};
15968a912857707864bbaaff9808717813105072a6ePatrick Benavoli};
160