// Value access
bool CEnumParameterType::toBlackboard(int32_t userValue, uint32_t &value,
                                      CParameterAccessContext &parameterAccessContext) const
{
    // Take care of format
    if (parameterAccessContext.valueSpaceIsRaw()) {
        signExtend(userValue);
    }

    if (!checkValueAgainstSpace(userValue)) {

        parameterAccessContext.setError(std::to_string(userValue) +
                                        " is not part of numerical space.");

        return false;
    }

    if (userValue < getMin() or userValue > getMax()) {

        // FIXME: values provided as hexa (either on command line or in a config
        // file will appear in decimal base instead of hexa base...
        parameterAccessContext.setError(
            "Value " + std::to_string(userValue) + " standing out of admitted range [" +
            std::to_string(getMin()) + ", " + std::to_string(getMax()) + "] for " + getKind());
        return false;
    }

    value = static_cast<uint32_t>(userValue);

    return true;
}
bool CEnumParameterType::fromBlackboard(string &userValue, const uint32_t &value,
                                        CParameterAccessContext &ctx) const
{
    // Convert the raw value from the blackboard
    int32_t signedValue = static_cast<int32_t>(value);
    signExtend(signedValue);

    // Take care of format
    if (ctx.valueSpaceIsRaw()) {

        // Format
        std::ostringstream sstream;

        // Numerical format requested
        if (ctx.outputRawFormatIsHex()) {

            // Hexa display with unecessary bits cleared out
            sstream << "0x" << std::hex << std::uppercase
                    << std::setw(static_cast<int>(getSize() * 2)) << std::setfill('0')
                    << makeEncodable(value);

            userValue = sstream.str();
        } else {
            userValue = std::to_string(value);
        }
    } else {
        // Literal display requested (should succeed)
        getLiteral(signedValue, userValue);
    }
    return true;
}
bool CFixedPointParameterType::toBlackboard(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const
{
    bool bValueProvidedAsHexa = isHexadecimal(strValue);

    // Check data integrity
    if (bValueProvidedAsHexa && !parameterAccessContext.valueSpaceIsRaw()) {

        parameterAccessContext.setError("Hexadecimal values are not supported for " + getKind() + " when selected value space is real:");

        return false;
    }

    if (parameterAccessContext.valueSpaceIsRaw()) {

        if (bValueProvidedAsHexa) {

            return convertFromHexadecimal(strValue, uiValue, parameterAccessContext);

        }
        return convertFromDecimal(strValue, uiValue, parameterAccessContext);
    }
    return convertFromQnm(strValue, uiValue, parameterAccessContext);
}
void CFixedPointParameterType::setOutOfRangeError(const string& strValue, CParameterAccessContext& parameterAccessContext) const
{
    std::ostringstream strStream;

    strStream << "Value " << strValue << " standing out of admitted ";

    if (!parameterAccessContext.valueSpaceIsRaw()) {

        // Min/Max computation
        double dMin = 0;
        double dMax = 0;
        getRange(dMin, dMax);

        strStream << std::fixed << std::setprecision(_uiFractional)
                  << "real range [" << dMin << ", " << dMax << "]";
    } else {

        // Min/Max computation
        int32_t iMax = getMaxValue<uint32_t>();
        int32_t iMin = -iMax - 1;

        strStream << "raw range [";

        if (isHexadecimal(strValue)) {

            // Format Min
            strStream << "0x" << std::hex << std::uppercase <<
                      std::setw(getSize() * 2) << std::setfill('0') << makeEncodable(iMin);
            // Format Max
            strStream << ", 0x" << std::hex << std::uppercase <<
                      std::setw(getSize() * 2) << std::setfill('0') << makeEncodable(iMax);

        } else {

            strStream << iMin << ", " << iMax;
        }

        strStream << "]";
    }
    strStream << " for " << getKind();

    parameterAccessContext.setError(strStream.str());
}
bool CEnumParameterType::fromBlackboard(string& strValue, const uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const
{
    // Take care of format
    if (parameterAccessContext.valueSpaceIsRaw()) {

        // Format
	std::ostringstream strStream;

        // Numerical format requested
        if (parameterAccessContext.outputRawFormatIsHex()) {

            // Hexa display with unecessary bits cleared out
            strStream << "0x" << std::hex << std::uppercase << std::setw(getSize()*2) << std::setfill('0') << makeEncodable(uiValue);

            strValue = strStream.str();
        } else {

            // Integer display
            int32_t iValue = uiValue;

            // Sign extend
            signExtend(iValue);

            strStream << iValue;

            strValue = strStream.str();
        }
    } else {

        // Integer display
        int32_t iValue = uiValue;

        // Sign extend
        signExtend(iValue);

        // Literal display requested (should succeed)
        getLiteral(iValue, strValue);
    }
    return true;
}
bool CFixedPointParameterType::fromBlackboard(string& strValue, const uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const
{
    int32_t iData = uiValue;

    // Check encodability
    assert(isEncodable((uint32_t)iData, false));

    // Format
    std::ostringstream strStream;

    // Raw formatting?
    if (parameterAccessContext.valueSpaceIsRaw()) {

        // Hexa formatting?
        if (parameterAccessContext.outputRawFormatIsHex()) {

            strStream << "0x" << std::hex << std::uppercase << std::setw(getSize()*2) << std::setfill('0') << (uint32_t)iData;
        } else {

            // Sign extend
            signExtend(iData);

            strStream << iData;
        }
    } else {

        // Sign extend
        signExtend(iData);

        // Conversion
        double dData = binaryQnmToDouble(iData);

        strStream << std::fixed << std::setprecision(_uiFractional) << dData;
    }

    strValue = strStream.str();

    return true;
}