本文整理汇总了C++中StringVector::reserve方法的典型用法代码示例。如果您正苦于以下问题:C++ StringVector::reserve方法的具体用法?C++ StringVector::reserve怎么用?C++ StringVector::reserve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringVector
的用法示例。
在下文中一共展示了StringVector::reserve方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: split
//-----------------------------------------------------------------------
StringVector StringUtil::split( const String& str, const String& delims, unsigned int maxSplits, bool preserveDelims)
{
StringVector ret;
// Pre-allocate some space for performance
ret.reserve(maxSplits ? maxSplits+1 : 10); // 10 is guessed capacity for most case
unsigned int numSplits = 0;
// Use STL methods
size_t start, pos;
start = 0;
do
{
pos = str.find_first_of(delims, start);
if (pos == start)
{
// Do nothing
start = pos + 1;
}
else if (pos == String::npos || (maxSplits && numSplits == maxSplits))
{
// Copy the rest of the string
ret.push_back( str.substr(start) );
break;
}
else
{
// Copy up to delimiter
ret.push_back( str.substr(start, pos - start) );
if(preserveDelims)
{
// Sometimes there could be more than one delimiter in a row.
// Loop until we don't find any more delims
size_t delimStart = pos, delimPos;
delimPos = str.find_first_not_of(delims, delimStart);
if (delimPos == String::npos)
{
// Copy the rest of the string
ret.push_back( str.substr(delimStart) );
}
else
{
ret.push_back( str.substr(delimStart, delimPos - delimStart) );
}
}
start = pos + 1;
}
// parse up to next real data
start = str.find_first_not_of(delims, start);
++numSplits;
} while (pos != String::npos);
return ret;
}
示例2: convertStringVectorOutput
StringVector convertStringVectorOutput(CFSVar& data) {
CFSVar text = data["text"];
StringVector words;
words.reserve(text.GetSize());
for (int idx=0 ; idx<text.GetSize() ; ++idx) {
words.push_back(std::string(text[idx].GetAString()));
}
return words;
}
示例3: getExtensions
StringVector Codec::getExtensions(void)
{
StringVector result;
result.reserve(ms_mapCodecs.size());
CodecList::const_iterator i;
for (i = ms_mapCodecs.begin(); i != ms_mapCodecs.end(); ++i)
{
result.push_back(i->first);
}
return result;
}
示例4: handleMessage
//-----------------------------------------------------------------------------
void CommunityManager::handleMessage(ChatOnGetIgnoreList const &message)
{
//DEBUG_REPORT_LOG(true, ("CommunityManager::handleMessage() - <ChatOnGetIgnoreList> networkId: %s ignore count: %d\n", message.getCharacter().getValueString().c_str(), message.getIgnoreList().size()));
PlayerObject *playerObject = getPlayerObject(message.getCharacter());
if (playerObject != NULL)
{
typedef std::vector<std::string> StringVector;
StringVector ignoreList;
ignoreList.reserve(message.getIgnoreList().size());
std::vector<ChatAvatarId>::const_iterator iterIgnoreList = message.getIgnoreList().begin();
#ifdef _DEBUG
int count = 1;
#endif // _DEBUG
std::string const & thisGameCode = Chat::getGameCode();
std::string const & thisClusterName = GameServer::getInstance().getClusterName();
for (; iterIgnoreList != message.getIgnoreList().end(); ++iterIgnoreList)
{
if (!iterIgnoreList->name.empty())
{
if (_stricmp(iterIgnoreList->gameCode.c_str(), thisGameCode.c_str()))
{
// ignore is from a different game, so store both the game and cluster name
ignoreList.push_back(iterIgnoreList->gameCode + std::string(".") + iterIgnoreList->cluster + std::string(".") + iterIgnoreList->name);
}
else if (_stricmp(iterIgnoreList->cluster.c_str(), thisClusterName.c_str()))
{
// ignore is from a different cluster, so store cluster name
ignoreList.push_back(iterIgnoreList->cluster + std::string(".") + iterIgnoreList->name);
}
else
{
// ignore is from the same cluster, so don't need to store game name
ignoreList.push_back(iterIgnoreList->name);
}
}
//DEBUG_REPORT_LOG(true, (" %2d CommunityManager::handleMessage() - <ChatOnGetIgnoreList> networkId: %s friend: %s\n", ++count, message.getCharacter().getValueString().c_str(), iterIgnoreList->getFullName().c_str()));
//playerObject->addIgnore(iterIgnoreList->name);
#ifdef _DEBUG
++count;
#endif // _DEBUG
}
playerObject->setIgnoreList(ignoreList);
}
}
示例5: getOptimizations
static StringVector getOptimizations(const std::string& optimizationList)
{
StringVector passes = hydrazine::split(optimizationList, ",");
StringVector splitPasses;
splitPasses.reserve(passes.size());
for(hydrazine::StringVector::iterator pass = passes.begin();
pass != passes.end(); ++pass)
{
splitPasses.push_back(hydrazine::strip(*pass, " "));
}
return splitPasses;
}
示例6: convertSpellingOutput
// convert output to wrapper format
std::vector<SpellingResults> convertSpellingOutput(CFSArray<CFSVar>& words) {
std::vector<SpellingResults> results;
results.reserve(words.GetSize());
for (int widx=0 ; widx < words.GetSize() ; ++widx) {
CFSVar word = words[widx];
std::string text = std::string(word["text"].GetAString());
CFSVar suggestions = word["suggestions"];
StringVector suggestStrings;
suggestStrings.reserve(suggestions.GetSize());
for (int sidx=0 ; sidx < suggestions.GetSize() ; ++sidx) {
CFSVar suggestion = suggestions[sidx];
suggestStrings.push_back(std::string(suggestion.GetAString()));
}
results.push_back(SpellingResults(text, word["spelling"].GetInt(), suggestStrings));
}
return results;
}
示例7: enumerateTests
static StringVector enumerateTests(const StringVector& files,
const StringVector& passes)
{
StringVector tests;
tests.reserve(files.size() * passes.size());
for(auto file = files.begin(); file != files.end(); ++file)
{
for(auto pass = passes.begin(); pass != passes.end(); ++pass)
{
tests.push_back(*file + "|" + *pass);
}
}
return tests;
}
示例8: split
StringVector StringUtil::split(const String& str, const String& delims, uint32_t maxSplits, BOOL preserveDelims)
{
StringVector ret;
ret.reserve(maxSplits ? maxSplits + 1 : 10);
uint32_t numSplits = 0;
size_t start, pos;
start = 0;
do
{
pos = str.find_first_of(delims, start);
if (pos == start)
{
start = pos + 1;
}
else if (pos == String::npos || (maxSplits && numSplits == maxSplits))
{
ret.push_back(str.substr(start));
break;
}
else
{
ret.push_back(str.substr(start, pos - start));
if (preserveDelims)
{
size_t delimStart = pos, delimPos;
delimPos = str.find_first_not_of(delims, delimStart);
if (delimPos == String::npos)
{
ret.push_back(str.substr(delimStart));
}
else
{
ret.push_back(str.substr(delimStart, delimPos - delimStart));
}
}
start = pos + 1;
}
start = str.find_first_not_of(delims, start);
++numSplits;
} while (pos != String::npos);
return ret;
}
示例9: tokenise
//-----------------------------------------------------------------------
StringVector StringUtil::tokenise( const String& str, const String& singleDelims, const String& doubleDelims, unsigned int maxSplits)
{
StringVector ret;
// Pre-allocate some space for performance
ret.reserve(maxSplits ? maxSplits+1 : 10); // 10 is guessed capacity for most case
unsigned int numSplits = 0;
String delims = singleDelims + doubleDelims;
// Use STL methods
size_t start, pos;
char curDoubleDelim = 0;
start = 0;
do
{
if (curDoubleDelim != 0)
{
pos = str.find(curDoubleDelim, start);
}
else
{
pos = str.find_first_of(delims, start);
}
if (pos == start)
{
char curDelim = str.at(pos);
if (doubleDelims.find_first_of(curDelim) != String::npos)
{
curDoubleDelim = curDelim;
}
// Do nothing
start = pos + 1;
}
else if (pos == String::npos || (maxSplits && numSplits == maxSplits))
{
if (curDoubleDelim != 0)
{
//Missing closer. Warn or throw exception?
}
// Copy the rest of the string
ret.push_back( str.substr(start) );
break;
}
else
{
if (curDoubleDelim != 0)
{
curDoubleDelim = 0;
}
// Copy up to delimiter
ret.push_back( str.substr(start, pos - start) );
start = pos + 1;
}
if (curDoubleDelim == 0)
{
// parse up to next real data
start = str.find_first_not_of(singleDelims, start);
}
++numSplits;
} while (pos != String::npos);
return ret;
}
示例10: LoadWeapons
//----------------------------------------------------------------------------------------------------------------
void CConfiguration::LoadWeapons( good::ini_file::const_iterator it )
{
good::string_buffer sbBuffer(szMainBuffer, iMainBufferSize, false);
CWeapons::Clear();
// Iterate throught key-values of weapons section.
BLOG_D("Weapons:");
for ( good::ini_section::const_iterator itemIt = it->begin(); itemIt != it->end(); ++itemIt )
{
sbBuffer = itemIt->value;
good::escape(sbBuffer);
StringVector aParams;
good::split((good::string)sbBuffer, aParams, ',', true);
good::vector<good::string> aAmmos[2];
good::vector<int> aAmmosCount[2];
CWeapon* pWeapon = new CWeapon();
StringVector aCurrent;
aCurrent.reserve(4);
bool bError = false;
int iSecondary = 0;
for ( StringVector::iterator paramsIt = aParams.begin(); paramsIt != aParams.end(); ++paramsIt )
{
int iValue = -1;
bool bProcessed = true;
aCurrent.clear();
good::split(*paramsIt, aCurrent);
BASSERT( aCurrent.size() > 0, exit(1) );
if ( aCurrent[0] == "class" )
{
if ( aCurrent.size() > 1 )
{
for ( int i=1; i<aCurrent.size(); ++i )
{
TClass iClass = CTypeToString::ClassFromString(aCurrent[i]);
if ( iClass == -1 )
{
BLOG_E( "File \"%s\", section [%s]:", m_iniFile.name.c_str(), it->name.c_str() );
BLOG_E( " Weapon %s, invalid class: %s.", itemIt->key.c_str(), aCurrent[1].c_str() );
bError = true;
break;
}
FLAG_SET(1 << iClass, pWeapon->iClass);
}
if ( bError )
break;
}
else
{
BLOG_E( "File \"%s\", section [%s]:", m_iniFile.name.c_str(), it->name.c_str() );
BLOG_E( " Weapon %s, class not specified.", itemIt->key.c_str() );
bError = true;
break;
}
}
else if ( aCurrent.size() == 1 )
{
if ( aCurrent[0] == "secondary" )
iSecondary = CWeapon::SECONDARY;
else
{
TWeaponFlags iFlag = CTypeToString::WeaponFlagsFromString(aCurrent[0]);
if ( iFlag == -1 )
bProcessed = false;
else
FLAG_SET(iFlag, pWeapon->iFlags[iSecondary]);
}
}
else if ( aCurrent.size() == 2 )
{
if ( aCurrent[0] == "type" )
{
int iType = CTypeToString::WeaponTypeFromString(aCurrent[1]);
if ( iType == -1 )
{
BLOG_E( "File \"%s\", section [%s]:", m_iniFile.name.c_str(), it->name.c_str() );
BLOG_E( " Weapon %s, invalid type: %s.", itemIt->key.c_str(), aCurrent[1].c_str() );
bError = true;
break;
}
pWeapon->iType = iType;
// Set weapon default parameters.
switch (iType)
{
case EWeaponMelee:
case EWeaponPhysics:
pWeapon->iAttackBullets[0] = pWeapon->iAttackBullets[1] = 0;
break;
case EWeaponRocket:
case EWeaponGrenade:
case EWeaponRemoteDetonation:
pWeapon->iClipSize[0] = 1;
break;
}
//.........这里部分代码省略.........
示例11: AddHeadersAutomatically
static void AddHeadersAutomatically(StringVector* files)
{
MetaBuilderContext* ctx = mbGetMainContext();
StringVector result;
result.reserve(files->size()*2);
for (size_t i = 0; i < files->size(); ++i)
{
const std::string& filename = (*files)[i];
result.push_back(filename);
char fileExt[MB_MAX_PATH];
mbPathGetFileExtension(fileExt, filename.c_str());
for (const char** sourceExtCursor = mbGetCAndCPPSourceFileExtensions(); *sourceExtCursor; ++sourceExtCursor)
{
if (!strcmp(*sourceExtCursor, fileExt))
{
//Add headers
{
const char** candidateExt = mbGetCAndCPPHeaderFileExtensions();
for (const char** candidateExtCursor = candidateExt; *candidateExtCursor; ++candidateExtCursor)
{
char candidateRelativeName[MB_MAX_PATH];
mbPathReplaceFileExtension(candidateRelativeName, filename.c_str(), *candidateExtCursor);
char candidateFilename[MB_MAX_PATH];
sprintf(candidateFilename, "%s/%s", ctx->currentMetaMakeDirAbs.c_str(), candidateRelativeName);
if (mbFileExists(candidateFilename))
{
MB_LOGDEBUG("Automatically adding header file %s", candidateRelativeName);
result.push_back(candidateRelativeName);
break;
}
}
}
//Add inline files
{
const char** candidateExt = mbGetCAndCPPInlineFileExtensions();
for (const char** candidateExtCursor = candidateExt; *candidateExtCursor; ++candidateExtCursor)
{
char candidateRelativeName[MB_MAX_PATH];
mbPathReplaceFileExtension(candidateRelativeName, filename.c_str(), *candidateExtCursor);
char candidateFilename[MB_MAX_PATH];
sprintf(candidateFilename, "%s/%s", ctx->currentMetaMakeDirAbs.c_str(), candidateRelativeName);
if (mbFileExists(candidateFilename))
{
MB_LOGDEBUG("Automatically adding inline file %s", candidateRelativeName);
result.push_back(candidateRelativeName);
break;
}
}
}
break;
}
}
}
*files = result;
}