本文整理汇总了C++中XsByteArray::reserve方法的典型用法代码示例。如果您正苦于以下问题:C++ XsByteArray::reserve方法的具体用法?C++ XsByteArray::reserve怎么用?C++ XsByteArray::reserve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XsByteArray
的用法示例。
在下文中一共展示了XsByteArray::reserve方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: waitForData
/*! \brief Wait for data to arrive or a timeout to occur.
\details The function waits until \c maxLength data is available or until a timeout occurs.
The function returns success if data is available or XsResultValue::TIMEOUT if a
timeout occurred. A timeout value of 0 indicates that the default timeout stored
in the class should be used.
\param maxLength The maximum number of bytes to read before returning
\param data The buffer to put the read data in.
\returns XRV_OK if \a maxLength bytes were read, XRV_TIMEOUT if less was read, XRV_TIMEOUTNODATA if nothing was read
*/
XsResultValue SerialInterface::waitForData(XsSize maxLength, XsByteArray& data)
{
data.clear();
data.reserve(maxLength);
//char *data = (char *)&_data[0];
JLTRACE(gJournal, "timeout=" << m_timeout << ", maxLength=" << maxLength);
uint32_t timeout = m_timeout;
uint32_t eTime = XsTime_getTimeOfDay(NULL, NULL) + timeout;
// uint32_t newLength = 0;
while ((data.size() < maxLength) && (XsTime_getTimeOfDay(NULL, NULL) <= eTime))
{
XsByteArray raw;
if (readData(maxLength - data.size(), raw) != XRV_OK)
return m_lastResult;
data.append(raw);
}
JLTRACE(gJournal, "Read " << data.size() << " of " << maxLength << " bytes");
if (data.size() < maxLength)
return (m_lastResult = XRV_TIMEOUT);
else
return (m_lastResult = XRV_OK);
}