本文整理汇总了C++中COpcString::SubStr方法的典型用法代码示例。如果您正苦于以下问题:C++ COpcString::SubStr方法的具体用法?C++ COpcString::SubStr怎么用?C++ COpcString::SubStr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类COpcString
的用法示例。
在下文中一共展示了COpcString::SubStr方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Find
// Find
COpcBrowseElement* COpcBrowseElement::Find(const COpcString& cPath)
{
// remove leading separator - if it exists.
COpcString cPrefix = GetSeparator();
COpcString cLocalPath = cPath;
while (cLocalPath.Find(GetSeparator()) == 0)
{
cLocalPath = cLocalPath.SubStr(cPrefix.GetLength());
}
// recursively search children.
OPC_POS pos = m_cChildren.GetHeadPosition();
while (pos != NULL)
{
COpcBrowseElement* pChild = m_cChildren.GetNext(pos);
// check for a child with an exact name match.
if (cLocalPath == pChild->m_cName)
{
return pChild;
}
// check if the path starts with the child name.
COpcString cPrefix = pChild->m_cName + pChild->GetSeparator();
// check for a child with an exact name match plus trailing separator.
if (cLocalPath == cPrefix)
{
return pChild;
}
UINT uIndex = cLocalPath.Find(cPrefix);
// search the child node if there is a match.
if (uIndex == 0)
{
cLocalPath = cLocalPath.SubStr(cPrefix.GetLength());
return pChild->Find(cLocalPath);
}
}
return NULL;
}
示例2: 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;
}
示例3: Insert
// Insert
COpcBrowseElement* COpcBrowseElement::Insert(const COpcString& cPath)
{
COpcString cName = cPath;
COpcString cSubPath = OPC_EMPTY_STRING;
// check if multiple levels have been specified.
do
{
UINT uIndex = cName.Find(GetSeparator());
if (uIndex == -1)
{
break;
}
cSubPath = cName.SubStr(uIndex + GetSeparator().GetLength());
cName = cName.SubStr(0, uIndex);
if (!cName.IsEmpty())
{
break;
}
cName = cSubPath;
}
while (!cSubPath.IsEmpty());
// invalid path specified.
if (cName.IsEmpty())
{
return NULL;
}
// find out if node already exists.
COpcBrowseElement* pNode = NULL;
OPC_POS pos = m_cChildren.GetHeadPosition();
while (pos != NULL)
{
pNode = m_cChildren.GetNext(pos);
if (pNode->m_cName == cName)
{
// return existing node.
if (cSubPath.IsEmpty())
{
return pNode;
}
// insert sub-path into existing node.
return pNode->Insert(cSubPath);
}
}
// create new node.
pNode = CreateInstance();
pNode->m_cName = cName;
OPC_ASSERT(!pNode->m_cName.IsEmpty());
COpcBrowseElement* pChild = pNode;
if (!cSubPath.IsEmpty())
{
pChild = pNode->Insert(cSubPath);
if (pChild == NULL)
{
delete pNode;
return NULL;
}
}
m_cChildren.AddTail(pNode);
return pChild;
}