本文整理汇总了C++中QValueVector::reserve方法的典型用法代码示例。如果您正苦于以下问题:C++ QValueVector::reserve方法的具体用法?C++ QValueVector::reserve怎么用?C++ QValueVector::reserve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QValueVector
的用法示例。
在下文中一共展示了QValueVector::reserve方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
QValueVector<KornMailSubject> * KKioDrop::doReadSubjects(bool * )
{
_subjects->doReadSubjects( this );
/*
* A empty QValueVector is made here.
* After that, the size is expanded to the expected number of subjects.
* This way, reallocation of memmory is minimized, and thus more efficient.
*/
QValueVector<KornMailSubject> *vector = new QValueVector<KornMailSubject>( );
vector->reserve( _mailurls->count() );
return vector;
}
示例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)
{
uint32_t arg_len;
unsigned char *cp;
tempStr.sprintf( "Unknown: %04x:", formatid);
cp = (unsigned char *) arguments;
while (cp < ((unsigned char *) &arguments[argsLen])) {
arg_len = (cp[0] << 0) | (cp[1] << 8) | (cp[2] << 16) | (cp[3] << 24);
cp += 4;
if (arg_len == 0)
break;
tempStr += " ";
tempStr += QString::fromUtf8((const char *) cp, arg_len);
cp += arg_len;
}
return tempStr;
}
else
{
QValueVector<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);
}
//.........这里部分代码省略.........
示例3: load
/*!
Parses and loads multi definitions
*/
void cMultiCache::load( const QString &basePath )
{
QFile indexFile( basePath + "multi.idx" );
if( !indexFile.open( IO_ReadOnly ) )
throw wpException( QString( "Error opening file %1 for reading." ).arg( basePath + "multi.idx" ) );
QDataStream indexStream( &indexFile );
indexStream.setByteOrder( QDataStream::LittleEndian );
QFile multiFile( basePath + "multi.mul" );
if ( !multiFile.open( IO_ReadOnly ) )
throw wpException( QString( "Error opening file %1 for reading." ).arg( basePath + "multi.mul" ) );
struct
{
Q_INT32 start;
Q_INT32 length;
Q_INT32 unknown;
} indexData;
ushort currentID = 0;
while ( !indexStream.atEnd() )
{
indexFile.at( currentID * 12 );
indexStream >> indexData.start;
indexStream >> indexData.length;
indexStream >> indexData.unknown;
if ( indexData.start == -1 ) // empty record?
{
++currentID;
continue;
}
QValueVector<multiItem_st> items;
items.reserve( indexData.length / 12 );
uint i = 0;
multiFile.at( indexData.start );
QDataStream multiStream( &multiFile );
multiStream.setByteOrder( QDataStream::LittleEndian );
for (; i < indexData.length / 12; ++i )
{
multiItem_st item;
multiStream >> item.tile;
multiStream >> item.x;
multiStream >> item.y;
multiStream >> item.z;
Q_UINT8 empty;
multiStream >> empty; // ????
Q_UINT32 isVisible = 0;
multiStream >> isVisible;
item.visible = isVisible > 0 ? true : false;
if ( item.visible ) // we ignore invisible items (?)
items.push_back(item);
}
MultiDefinition* multi = new MultiDefinition;
multi->setItems( items );
multis.insert( currentID++, multi );
}
}