当前位置: 首页>>代码示例>>C++>>正文


C++ COpcText类代码示例

本文整理汇总了C++中COpcText的典型用法代码示例。如果您正苦于以下问题:C++ COpcText类的具体用法?C++ COpcText怎么用?C++ COpcText使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了COpcText类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ToUnsigned

// 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);
}
开发者ID:AnBesp,项目名称:UA-.NET,代码行数:26,代码来源:OpcXmlType.cpp

示例2: CheckForDelim

// CheckForDelim
bool COpcTextReader::CheckForDelim(COpcText& cToken, UINT uPosition)
{
    // check for new line delim.
    if (cToken.GetNewLineDelim())
    {
        if (m_szBuf[uPosition] == L'\n' || m_szBuf[uPosition] == L'\r')
        {
            cToken.SetNewLine();
            cToken.SetDelimChar(m_szBuf[uPosition]);
            return true;
        }
    }

    // check for one of the delim chars.
    LPCWSTR szDelims = cToken.GetDelims();
    UINT    uCount   = (szDelims != NULL)?wcslen(szDelims):0;

    for (UINT ii = 0; ii < uCount; ii++)
    {
        if (IsEqual(cToken, m_szBuf[uPosition], szDelims[ii]))
        {
            cToken.SetDelimChar(szDelims[ii]);
            return true;
        }
    }

    return false;
}
开发者ID:AymanShawky,项目名称:niko78csharp,代码行数:29,代码来源:COpcTextReader.cpp

示例3: FindDelimited

// FindDelimited
bool COpcTextReader::FindDelimited(COpcText& cToken)
{
    OPC_ASSERT(m_szBuf != NULL);
    OPC_ASSERT(m_uLength != 0);

    // skip leading whitespace
    UINT uPosition = SkipWhitespace(cToken);

    // check if there is still data left to read.
    if (uPosition >= m_uEndOfData)
    {
        return false;
    } 

    // read until a delimiter.
    for (UINT ii = uPosition; ii < m_uEndOfData; ii++)
    {
        // check if search halted.
        if (CheckForHalt(cToken, ii))
        {
            return false;
        }

        // check if delimiter found.
        if (CheckForDelim(cToken, ii))
        {
            // copy token - empty tokens are valid.
            CopyData(cToken, uPosition, ii);
            return true;
        }
    }

    // check for end of data - true if EOF is a delim.
    if (ii >= m_uEndOfData)
    {
        cToken.SetEof();
        
        if (cToken.GetEofDelim())
        {
            CopyData(cToken, uPosition, ii);
            return true;
        }
    }

    return false;
}
开发者ID:AymanShawky,项目名称:niko78csharp,代码行数:47,代码来源:COpcTextReader.cpp

示例4: FindLiteral

// FindLiteral
bool COpcTextReader::FindLiteral(COpcText& cToken)
{
    OPC_ASSERT(m_szBuf != NULL);
    OPC_ASSERT(m_uLength != 0);

    LPCWSTR szText  = cToken.GetText();
    UINT    uLength = (szText != NULL)?wcslen(szText):0; 

    // check for trivial case
    if (uLength == 0)
    {
        return false;
    }

    UINT uPosition = SkipWhitespace(cToken);

    // check if there is enough data.
    if (uLength > (m_uEndOfData - uPosition))
    {
        return false;
    }

    for (UINT ii = uPosition; ii < m_uEndOfData-uLength+1; ii++)
    {
        // check if search halted.
        if (CheckForHalt(cToken, ii))
        {
            return false;
        }

        // compare text at current position.
        if (IsEqual(cToken, m_szBuf+ii, szText, uLength))
        {
            CopyData(cToken, ii, ii+uLength);
            return true;
        }

        // stop search if leading unmatching characters are not ignored.
        if (!cToken.GetSkipLeading())
        {
            break;
        }
    }

    return false;
}
开发者ID:AymanShawky,项目名称:niko78csharp,代码行数:47,代码来源:COpcTextReader.cpp

示例5: ToSigned

// 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;
}
开发者ID:AnBesp,项目名称:UA-.NET,代码行数:46,代码来源:OpcXmlType.cpp

示例6: cReader

// Read
template<> bool OpcXml::Read(const COpcString& cString, Decimal& cValue)
{
    bool bResult = true;

    TRY
    {
        COpcText cText;
        COpcTextReader cReader(cString);

        // parse whole integer portion.
        cText.SetType(COpcText::Delimited);
        cText.SetDelims(L".");
        cText.SetEofDelim();

        if (!cReader.GetNext(cText))
        {
            THROW_(bResult, false);
        }

        // convert to signed integer.
        Long nValue = 0;

        if (!ToSigned(cText, nValue, MAX_DECIMAL, MIN_DECIMAL))
        {
            THROW_(bResult, false);
        }

        cValue.int64 = nValue*10000;
        
        if (cText.GetDelimChar() == L'.')
        {
            // parse decimal portion.
            cText.SetType(COpcText::Delimited);
            cText.SetEofDelim();

            if (!cReader.GetNext(cText))
            {
                THROW_(bResult, false);
            }

            // convert to unsigned integer.
            ULong uValue = 0;

            if (!ToUnsigned(cText, uValue, MAX_DEC_FRACTION, 0, 10))
            {
                THROW_(bResult, false);
            }

            cValue.int64 += (Long)uValue;
        }
    }
    CATCH
    {
        cValue.int64 = 0;
    }

    return bResult;
}
开发者ID:AnBesp,项目名称:UA-.NET,代码行数:59,代码来源:OpcXmlType.cpp

示例7: ToReal

// ToReal
static bool ToReal(
    const COpcString& cString, 
    Double&           nValue, 
    Double            nMax, 
    Double            nMin
)
{
    bool bResult = true;

    TRY
    {
        // extract non-whitespace token.
        COpcText cText;
        COpcTextReader cReader(cString);

        cText.SetType(COpcText::NonWhitespace);
        cText.SetSkipLeading();

        if (!cReader.GetNext(cText))
        {
            THROW_(bResult, false);
        }

        // parse double with C runtime function.
        WCHAR* pzEnd = NULL;
        nValue = (Double)wcstod((LPCWSTR)(COpcString&)cText, &pzEnd);

        // check for error - all text must have been parsed.
        if (pzEnd == NULL || wcslen(pzEnd) != 0) 
        {
            THROW_(bResult, false);
        }

        // check limits.
        if (nValue > nMax && nValue < nMin) THROW_(bResult, false);
    }
    CATCH
    {
        nValue = 0;
    }

    return bResult;
}
开发者ID:AnBesp,项目名称:UA-.NET,代码行数:44,代码来源:OpcXmlType.cpp

示例8: FindWhitespace

// FindWhitespace
bool COpcTextReader::FindWhitespace(COpcText& cToken)
{
    OPC_ASSERT(m_szBuf != NULL);
    OPC_ASSERT(m_uLength != 0);

    UINT uPosition = 0;

    // skip leading non-whitespace
    if (cToken.GetSkipLeading())
    {
        for (UINT ii = 0; ii < m_uEndOfData; ii++)
        {
            if (CheckForHalt(cToken, ii))
            {
               return false;
            }

            if (iswspace(m_szBuf[ii]))
            {
               uPosition = ii;
               break;
            }
        }
    }

    // check if there is still data left to read.
    if (uPosition >= m_uEndOfData)
    {
        return false;
    } 

    // read until a non-whitespace.
    for (UINT ii = uPosition; ii < m_uEndOfData; ii++)
    {
        if (CheckForHalt(cToken, ii))
        {
            break;
        }

        if (!iswspace(m_szBuf[ii]))
        {
            break;
        }
    }

    // check for empty token
    if (ii == uPosition)
    {
        return false;
    }

    // copy token.
    CopyData(cToken, uPosition, ii);
    return true;
}
开发者ID:AymanShawky,项目名称:niko78csharp,代码行数:56,代码来源:COpcTextReader.cpp

示例9: IsEqual

// IsEqual
static bool IsEqual(COpcText& cToken, WCHAR zValue1, WCHAR zValue2)
{
    if (cToken.GetIgnoreCase())
    {
        WCHAR z1 = (iswlower(zValue1))?towupper(zValue1):zValue1;
        WCHAR z2 = (iswlower(zValue2))?towupper(zValue2):zValue2;

        return (z1 == z2);
    }

    return (zValue1 == zValue2);
}
开发者ID:AymanShawky,项目名称:niko78csharp,代码行数:13,代码来源:COpcTextReader.cpp

示例10: OPC_ASSERT

// FindToken
bool COpcTextReader::FindToken(COpcText& cToken)
{
    OPC_ASSERT(m_szBuf != NULL);
    OPC_ASSERT(m_uLength != 0);

    switch (cToken.GetType())
    {
        case COpcText::Literal:       return FindLiteral(cToken);
        case COpcText::NonWhitespace: return FindNonWhitespace(cToken);
        case COpcText::Whitespace:    return FindWhitespace(cToken);
        case COpcText::Delimited:     return FindDelimited(cToken);
    }

    return false;
}
开发者ID:AymanShawky,项目名称:niko78csharp,代码行数:16,代码来源:COpcTextReader.cpp

示例11: ToDate

// ToDate
static bool ToDate(
    const COpcString& cString, 
    WORD&             wYear,
    WORD&             wMonth,
    WORD&             wDay
)
{
    bool bResult = true;

    TRY
    {
        COpcText cText;
        COpcTextReader cReader(cString);

        ULong uValue = 0;

        // parse year field.
        cText.SetType(COpcText::Delimited);
        cText.SetDelims(L"-");

        if (!cReader.GetNext(cText)) THROW_(bResult, false);
        if (!ToUnsigned(cText, uValue, MAX_YEAR, MIN_YEAR, 10)) THROW_(bResult, false);
        wYear = (WORD)uValue;

        // parse month field.
        cText.SetType(COpcText::Delimited);
        cText.SetDelims(L"-");

        if (!cReader.GetNext(cText)) THROW_(bResult, false);
        if (!ToUnsigned(cText, uValue, MAX_MONTH, MIN_MONTH, 10)) THROW_(bResult, false);
        wMonth = (WORD)uValue;

        // parse day field.
        cText.SetType(COpcText::Delimited);
        cText.SetEofDelim();

        if (!cReader.GetNext(cText)) THROW_(bResult, false);
        if (!ToUnsigned(cText, uValue, MAX_DAY, MIN_DAY, 10)) THROW_(bResult, false);
        wDay = (WORD)uValue;
    }
    CATCH
    {
        wYear  = 0;
        wMonth = 0;
        wDay   = 0;
    }

    return bResult;
}
开发者ID:AnBesp,项目名称:UA-.NET,代码行数:50,代码来源:OpcXmlType.cpp

示例12: SkipWhitespace

// SkipWhitespace 
UINT COpcTextReader::SkipWhitespace(COpcText& cToken)
{
    if (!cToken.GetSkipWhitespace())
    {
        return 0;
    }

    for (UINT ii = 0; ii < m_uEndOfData; ii++)
    {
        if (CheckForHalt(cToken, ii) || !iswspace(m_szBuf[ii]))
        {
            return ii;
        }
    }

    return m_uEndOfData;
}
开发者ID:AymanShawky,项目名称:niko78csharp,代码行数:18,代码来源:COpcTextReader.cpp

示例13: ToOffset

// ToOffset
static bool ToOffset(
    const COpcString& cString, 
	bool              bNegative,
    SHORT&            sMinutes
)
{
    bool bResult = true;

    TRY
    {
        COpcText cText;
        COpcTextReader cReader(cString);

        ULong uValue = 0;

        // parse hour field.
        cText.SetType(COpcText::Delimited);
        cText.SetDelims(L":");

        if (!cReader.GetNext(cText)) THROW_(bResult, false);
        if (!ToUnsigned(cText, uValue, MAX_HOUR, MIN_HOUR, 10)) THROW_(bResult, false);
      
		sMinutes = (SHORT)uValue*60;

        // parse minute field.
        cText.SetType(COpcText::Delimited);
        cText.SetDelims(L".");
        cText.SetEofDelim();

        if (!cReader.GetNext(cText)) THROW_(bResult, false);
        if (!ToUnsigned(cText, uValue, MAX_MINUTE, MIN_MINUTE, 10)) THROW_(bResult, false);
        
		sMinutes += (SHORT)uValue;

		// add sign.
		if (bNegative)
		{
			sMinutes = -sMinutes;
		}
    }
    CATCH
    {
        sMinutes = 0;
    }

    return bResult;
}
开发者ID:AnBesp,项目名称:UA-.NET,代码行数:48,代码来源:OpcXmlType.cpp

示例14: CheckForHalt

// CheckForHalt
bool COpcTextReader::CheckForHalt(COpcText& cToken, UINT uPosition)
{
    // check if max chars exceeded.
    if (cToken.GetMaxChars() > 0)
    {
        if (cToken.GetMaxChars() <= uPosition)
        {
            return false;
        }
    }

    // check for end of data - halts if EOF is not a delim.
    if (uPosition >= m_uEndOfData)
    {
        cToken.SetEof();
        return !cToken.GetEofDelim();
    }

    // check for one of halt characters.
    LPCWSTR szHaltChars = cToken.GetHaltChars();

    if (szHaltChars == NULL)
    {
        return false;
    }

    UINT uCount = wcslen(szHaltChars);

    for (UINT ii = 0; ii < uCount; ii++)
    {
        if (IsEqual(cToken, m_szBuf[uPosition], szHaltChars[ii]))
        {
            cToken.SetHaltChar(szHaltChars[ii]);
            return true;
        }
    }

    return false;
}
开发者ID:AymanShawky,项目名称:niko78csharp,代码行数:40,代码来源:COpcTextReader.cpp

示例15: ToTime

// ToTime
static bool ToTime(
    const COpcString& cString, 
    WORD&             wHour,
    WORD&             wMinute,
    WORD&             wSeconds,
    WORD&             wFraction
)
{
    bool bResult = true;

    TRY
    {
        COpcText cText;
        COpcTextReader cReader(cString);

        ULong uValue = 0;

        // parse hour field.
        cText.SetType(COpcText::Delimited);
        cText.SetDelims(L":");

        if (!cReader.GetNext(cText)) THROW_(bResult, false);
        if (!ToUnsigned(cText, uValue, MAX_HOUR, MIN_HOUR, 10)) THROW_(bResult, false);
        wHour = (WORD)uValue;

        // parse month field.
        cText.SetType(COpcText::Delimited);
        cText.SetDelims(L":");

        if (!cReader.GetNext(cText)) THROW_(bResult, false);
        if (!ToUnsigned(cText, uValue, MAX_MINUTE, MIN_MINUTE, 10)) THROW_(bResult, false);
        wMinute = (WORD)uValue;

        // parse seconds field.
        cText.SetType(COpcText::Delimited);
        cText.SetDelims(L".");
        cText.SetEofDelim();

        if (!cReader.GetNext(cText)) THROW_(bResult, false);
        if (!ToUnsigned(cText, uValue, MAX_SECOND, MIN_SECOND, 10)) THROW_(bResult, false);
        wSeconds = (WORD)uValue;

        // parse seconds fraction field.
        wFraction = 0;

        if (cText.GetDelimChar() == L'.')
        {
            cText.SetType(COpcText::Delimited);
            cText.SetEofDelim();

            if (!cReader.GetNext(cText)) THROW_(bResult, false);

            // preprocess text.
            COpcString cFraction = cText;

            // add trailing zeros.
            while (cFraction.GetLength() < 3) cFraction += _T("0");

            // truncate extra digits.
            if (cFraction.GetLength() > 3) cFraction = cFraction.SubStr(0,3);

            if (!ToUnsigned(cFraction, uValue, MAX_ULONG, 0, 10))
            {
                THROW_(bResult, false);
            }

            // result is in milliseconds.
            wFraction = (WORD)uValue;
        }
    }
    CATCH
    {
        wHour     = 0;
        wMinute   = 0;
        wSeconds  = 0;
        wFraction = 0;
    }

    return bResult;
}
开发者ID:AnBesp,项目名称:UA-.NET,代码行数:81,代码来源:OpcXmlType.cpp


注:本文中的COpcText类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。