Home | History | Annotate | Download | only in parameter
      1 /*
      2  * Copyright (c) 2011-2014, 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 "ParameterType.h"
     33 
     34 #include <string>
     35 
     36 class CFixedPointParameterType : public CParameterType
     37 {
     38 public:
     39     CFixedPointParameterType(const std::string& strName);
     40 
     41     // From IXmlSink
     42     virtual bool fromXml(const CXmlElement& xmlElement, CXmlSerializingContext& serializingContext);
     43 
     44     // From IXmlSource
     45     virtual void toXml(CXmlElement& xmlElement, CXmlSerializingContext& serializingContext) const;
     46 
     47     // XML Serialization value space handling
     48     // Value space handling for configuration import
     49     virtual void handleValueSpaceAttribute(CXmlElement& xmlConfigurableElementSettingsElement, CConfigurationAccessContext& configurationAccessContext) const;
     50 
     51     /// Conversion
     52     // String
     53     virtual bool toBlackboard(const std::string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const;
     54     virtual bool fromBlackboard(std::string& strValue, const uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const;
     55     // Double
     56     virtual bool toBlackboard(double dUserValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const;
     57     virtual bool fromBlackboard(double& dUserValue, uint32_t uiValue, CParameterAccessContext& parameterAccessContext) const;
     58 
     59     // Element properties
     60     virtual void showProperties(std::string& strResult) const;
     61 
     62     // CElement
     63     virtual std::string getKind() const;
     64 private:
     65     // Util size
     66     uint32_t getUtilSizeInBits() const;
     67     // Range computation
     68     void getRange(double& dMin, double& dMax) const;
     69 
     70     /**
     71      * Checks if a string has the written representation of an hexadecimal number (Which is
     72      * the prefix "Ox" in C++).
     73      *
     74      * @param[in] strValue Parameter read from the XML file representated as a string.
     75      *
     76      * @return true if the string is written as hexa, false otherwise.
     77      */
     78     bool isHexadecimal(const std::string& strValue) const;
     79 
     80     /**
     81      * Convert a decimal raw represented string into an unsigned long integer.
     82      * In case of a failing conversion or encodability, this function set the error to
     83      * illegal value provided and gives the range allowed for the parameter.
     84      *
     85      * @param[in] strValue Parameter read from the XML file representated as a string in decimal
     86      *                     raw format
     87      * @param[out] uiValue Parameter representated as a long unsigned integer.
     88      * @param[in:out] parameterAccessContext Parameter access context.
     89      *
     90      * @return true if the string was successfully converted, false otherwise.
     91      */
     92     bool convertFromDecimal(const std::string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const;
     93 
     94     /**
     95      * Convert an hexadecimal raw represented string into an unsigned long integer.
     96      * In case of a failing conversion or encodability, this function set the error to
     97      * illegal value provided and gives the range allowed for the parameter.
     98      *
     99      * @param[in] strValue Parameter read from the XML file representated as a string in hexadecimal
    100      *                     raw format
    101      * @param[out] uiValue Parameter representated as a long unsigned integer.
    102      * @param[in:out] parameterAccessContext Parameter access context.
    103      *
    104      * @return true if the string was successfully converted, false otherwise.
    105      */
    106     bool convertFromHexadecimal(const std::string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const;
    107 
    108     /**
    109      * Convert a Qn.m represented string into an unsigned long integer.
    110      * In case of a failing conversion or encodability, this function set the error to
    111      * illegal value provided and gives the range allowed for the parameter.
    112      *
    113      * @param[in] strValue Parameter read from the XML file representated as a string in Qn.m
    114      *                     representation.
    115      * @param[out] uiValue Parameter representated as a long unsigned integer.
    116      * @param[in:out] parameterAccessContext Parameter access context.
    117      *
    118      * @return true if the string was successfully converted, false otherwise.
    119      */
    120     bool convertFromQnm(const std::string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const;
    121 
    122     /**
    123      * Set the out of range error.
    124      * In case of a failing conversion or encodability, this function set the error to
    125      * illegal value provided and gives the range allowed for the parameter.
    126      *
    127      * @param[in] strValue Parameter read from the XML file representated as a string
    128      * @param[in:out] parameterAccessContext Parameter Access Context
    129      */
    130     void setOutOfRangeError(const std::string& strValue, CParameterAccessContext& parameterAccessContext) const;
    131 
    132     // Check if data is encodable
    133     bool checkValueAgainstRange(double dValue) const;
    134 
    135     /**
    136      * Convert a double towards a Qn.m representation which is stored in binary format.
    137      * This value is rounded if the double is not encodable in the corresponding Qn.m format.
    138      *
    139      * @param[in] dValue the double which should be converted.
    140      *
    141      * @return the integer which contains the converted Qn.m number.
    142      */
    143     int32_t doubleToBinaryQnm(double dValue) const;
    144 
    145     /**
    146      * Convert a Qn.m binary number towards its double representation.
    147      *
    148      * @param[in] iValue the integer which contains the Qn.m number which should be converted.
    149      *
    150      * @return the double which contains the double representation of iValue.
    151      */
    152     double binaryQnmToDouble(int32_t iValue) const;
    153 
    154     // Integral part in Q notation
    155     uint32_t _uiIntegral;
    156     // Fractional part in Q notation
    157     uint32_t _uiFractional;
    158 };
    159