コード例 #1
0
ファイル: OpcXmlType.cpp プロジェクト: AnBesp/UA-.NET
// ToUnsigned
static bool ToUnsigned(
    const COpcString& cString, 
    ULong&            nValue,
    ULong             nMax, 
    ULong             nMin
)
{
    // extract base
    COpcText cText;
    COpcTextReader cReader(cString);

    UINT uBase = 10;

    cText.SetType(COpcText::Literal);
    cText.SetText(L"0x");
    cText.SetIgnoreCase();

    if (cReader.GetNext(cText))
    {
        uBase = 16;
    }

    // read unsigned value.
    return ToUnsigned(cReader.GetBuf(), nValue, nMax, nMin, uBase);
}
コード例 #2
0
ファイル: OpcXmlType.cpp プロジェクト: AnBesp/UA-.NET
// ToSigned
static bool ToSigned(
    const COpcString& cString, 
    Long&             nValue,
    Long              nMax, 
    Long              nMin
)
{
    nValue = 0;
     
    // extract plus sign
    bool bSign = true;

    COpcText cText;
    COpcTextReader cReader(cString);

    cText.SetType(COpcText::Literal);
    cText.SetText(L"+");

    if (!cReader.GetNext(cText))
    {
        // extract minus sign
        cText.SetType(COpcText::Literal);
        cText.SetText(L"-");

        bSign = !cReader.GetNext(cText);
    }

    // read unsigned value.
    ULong uValue = 0;
    
    if (!ToUnsigned(cReader.GetBuf(), uValue, (bSign)?nMax:-nMin, 0, 10))
    {
        return false;
    }

    nValue = (Long)uValue;

    // apply sign.
    if (!bSign)
    {
        nValue = -nValue;
    }

    return true;
}