本文整理汇总了C++中Q3ValueVector::reserve方法的典型用法代码示例。如果您正苦于以下问题:C++ Q3ValueVector::reserve方法的具体用法?C++ Q3ValueVector::reserve怎么用?C++ Q3ValueVector::reserve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Q3ValueVector
的用法示例。
在下文中一共展示了Q3ValueVector::reserve方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ds
void tst_Q3ValueVector::reserve()
{
QFETCH( QByteArray, ba );
Q3ValueVector<int> vector;
QDataStream ds( &ba, IO_ReadWrite );
ds >> vector;
Q3ValueVector<int>::size_type cap = vector.capacity();
// should do nothing
if( cap > 5 )
vector.reserve( vector.capacity() - 5 );
else
vector.reserve( 0 );
QVERIFY( vector.capacity() == cap );
// should make capacity() grow
vector.reserve( vector.capacity() + 5 );
QVERIFY( cap < vector.capacity() );
}
示例2: formatMessage
QString EQStr::formatMessage(uint32_t formatid,
const char* arguments, size_t argsLen) const
{
QString* formatStringRes = m_messageStrings.find(formatid);
QString tempStr;
if (formatStringRes == NULL)
{
tempStr.sprintf( "Unknown: %04x: ",
formatid);
tempStr += QString::fromUtf8(arguments);
size_t totalArgsLen = strlen(arguments) + 1;
const char* curMsg;
while (totalArgsLen < argsLen)
{
curMsg = arguments + totalArgsLen;
tempStr += QString(", ") + QString::fromUtf8(curMsg);
totalArgsLen += strlen(curMsg) + 1;
}
}
else
{
Q3ValueVector<QString> argList;
argList.reserve(5); // reserve space for 5 elements to handle most common sizes
//
size_t totalArgsLen = 0;
const char* curArg;
while (totalArgsLen < argsLen)
{
curArg = arguments + totalArgsLen;
// insert argument into the argument list
argList.push_back(QString::fromUtf8(curArg));
totalArgsLen += strlen(curArg) + 1;
}
bool ok;
int curPos;
size_t substArg;
int substArgValue;
QString* substFormatStringRes;
QString substFormatString;
////////////////////////////
// replace template (%T) arguments in formatted string
QString formatString = *formatStringRes;
QRegExp rxt("%T(\\d{1,3})", true, false);
// find first template substitution
curPos = rxt.search(formatString, 0);
while (curPos != -1)
{
substFormatStringRes = NULL;
substArg = rxt.cap(1).toInt(&ok);
if (ok && (substArg <= argList.size()))
{
substArgValue = argList[substArg-1].toInt(&ok);
if (ok)
substFormatStringRes = m_messageStrings.find(substArgValue);
}
// replace template argument with subst string
if (substFormatStringRes != NULL)
formatString.replace(curPos, rxt.matchedLength(), *substFormatStringRes);
else
curPos += rxt.matchedLength(); // if no replacement string, skip over
// find next substitution
curPos = rxt.search(formatString, curPos);
}
////////////////////////////
// now replace substitution arguments in formatted string
// NOTE: not using QString::arg() because not all arguments are always used
// and it will do screwy stuff in this situation
QRegExp rx("%(\\d{1,3})", true, false);
// find first template substitution
curPos = rx.search(formatString, 0);
while (curPos != -1)
{
substArg = rx.cap(1).toInt(&ok);
// replace substitution argument with argument from list
if (ok && (substArg <= argList.size()))
formatString.replace(curPos, rx.matchedLength(), argList[substArg-1]);
else
curPos += rx.matchedLength(); // if no such argument, skip over
// find next substitution
curPos = rx.search(formatString, curPos);
}
return formatString;
//.........这里部分代码省略.........