本文整理汇总了C++中stringlist::iterator::rfind方法的典型用法代码示例。如果您正苦于以下问题:C++ iterator::rfind方法的具体用法?C++ iterator::rfind怎么用?C++ iterator::rfind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stringlist::iterator
的用法示例。
在下文中一共展示了iterator::rfind方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: writeToFile
bool ObjectTemplateCustomizationDataWriter::writeToFile(const std::string &pathName, bool allowOverwrite)
{
//-- Don't write anything if there's no data to write.
bool hasData = false;
if (!m_paletteColorData->empty())
hasData = true;
if (!m_rangedIntData->empty())
hasData = true;
if (!hasData)
{
DEBUG_REPORT_LOG(true, ("writeToFile(): no data: skipped writing [%s].\n", pathName.c_str()));
return true;
}
//-- Handle no-overwrite case.
if (!allowOverwrite)
{
FILE *const testFile = fopen(pathName.c_str(), "r");
if (testFile != NULL)
{
fclose(testFile);
DEBUG_REPORT_LOG(true, ("writeToFile(): overwrite attempt: skipped writing [%s] because it already exists and allowOverwrite == false.\n", pathName.c_str()));
return false;
}
}
//-- open file
FILE *const file = fopen(pathName.c_str(), "w");
if (!file)
{
WARNING(true, ("failed to create file [%s].", pathName.c_str()));
return false;
}
//-- sort the output data
m_paletteColorData->sort();
m_rangedIntData->sort();
//-- write palette color variables
fprintf(file, "paletteColorCustomizationVariables = [");
{
int i = 0;
int const count = static_cast<int>(m_paletteColorData->size());
const StringList::iterator endIt = m_paletteColorData->end();
for (StringList::iterator it = m_paletteColorData->begin(); it != endIt; ++it, ++i)
{
if (i == (count - 1))
{
// -- Fixup last entry to use ] in place of final comma.
std::string::size_type position = it->rfind(',');
DEBUG_FATAL(static_cast<int>(position) == static_cast<int>(std::string::npos), ("bad data, where's the final comma?"));
(*it)[position] = ']';
}
fprintf(file, "\n %s", it->c_str());
}
}
if (m_paletteColorData->empty())
fprintf(file, "]");
fprintf(file, "\n\n");
//-- write ranged int variables
fprintf(file, "rangedIntCustomizationVariables = [");
{
int i = 0;
int const count = static_cast<int>(m_rangedIntData->size());
const StringList::iterator endIt = m_rangedIntData->end();
for (StringList::iterator it = m_rangedIntData->begin(); it != endIt; ++it, ++i)
{
if (i == (count - 1))
{
// -- Fixup last entry to use ] in place of final comma.
std::string::size_type position = it->rfind(',');
DEBUG_FATAL(static_cast<int>(position) == static_cast<int>(std::string::npos), ("bad data, where's the final comma?"));
(*it)[position] = ']';
}
fprintf(file, "\n %s", it->c_str());
}
}
if (m_rangedIntData->empty())
fprintf(file, "]");
fprintf(file, "\n\n");
fclose(file);
//-- return success
return true;
}