本文整理汇总了C++中ConfigFile::close方法的典型用法代码示例。如果您正苦于以下问题:C++ ConfigFile::close方法的具体用法?C++ ConfigFile::close怎么用?C++ ConfigFile::close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConfigFile
的用法示例。
在下文中一共展示了ConfigFile::close方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: load
bool Label::load(const std::string& configFileFilename)
{
m_LoadedConfigFile = configFileFilename;
// Open the config file
ConfigFile configFile;
if (!configFile.open(configFileFilename))
{
TGUI_OUTPUT("TGUI error: Failed to open " + configFileFilename + ".");
return false;
}
// Read the properties and their values (as strings)
std::vector<std::string> properties;
std::vector<std::string> values;
if (!configFile.read("Label", properties, values))
{
TGUI_OUTPUT("TGUI error: Failed to parse " + configFileFilename + ".");
return false;
}
// Close the config file
configFile.close();
// Handle the read properties
for (unsigned int i = 0; i < properties.size(); ++i)
{
std::string property = properties[i];
std::string value = values[i];
if (property == "textcolor")
{
setTextColor(extractColor(value));
}
else
TGUI_OUTPUT("TGUI warning: Unrecognized property '" + property + "' in section Label in " + configFileFilename + ".");
}
return false;
}
示例2: load
bool Checkbox::load(const std::string& configFileFilename)
{
m_LoadedConfigFile = configFileFilename;
// When everything is loaded successfully, this will become true.
m_Loaded = false;
// If the checkbox was loaded before then remove the old textures
if (m_TextureUnchecked.data != nullptr) TGUI_TextureManager.removeTexture(m_TextureUnchecked);
if (m_TextureChecked.data != nullptr) TGUI_TextureManager.removeTexture(m_TextureChecked);
if (m_TextureHover.data != nullptr) TGUI_TextureManager.removeTexture(m_TextureHover);
if (m_TextureFocused.data != nullptr) TGUI_TextureManager.removeTexture(m_TextureFocused);
// Open the config file
ConfigFile configFile;
if (!configFile.open(configFileFilename))
{
TGUI_OUTPUT("TGUI error: Failed to open " + configFileFilename + ".");
return false;
}
// Read the properties and their values (as strings)
std::vector<std::string> properties;
std::vector<std::string> values;
if (!configFile.read("Checkbox", properties, values))
{
TGUI_OUTPUT("TGUI error: Failed to parse " + configFileFilename + ".");
return false;
}
// Close the config file
configFile.close();
// Find the folder that contains the config file
std::string configFileFolder = "";
std::string::size_type slashPos = configFileFilename.find_last_of("/\\");
if (slashPos != std::string::npos)
configFileFolder = configFileFilename.substr(0, slashPos+1);
// Handle the read properties
for (unsigned int i = 0; i < properties.size(); ++i)
{
std::string property = properties[i];
std::string value = values[i];
if (property == "textcolor")
{
m_Text.setColor(configFile.readColor(value));
}
else if (property == "checkedimage")
{
if (!configFile.readTexture(value, configFileFolder, m_TextureChecked))
{
TGUI_OUTPUT("TGUI error: Failed to parse value for CheckedImage in section Checkbox in " + configFileFilename + ".");
return false;
}
}
else if (property == "uncheckedimage")
{
if (!configFile.readTexture(value, configFileFolder, m_TextureUnchecked))
{
TGUI_OUTPUT("TGUI error: Failed to parse value for UncheckedImage in section Checkbox in " + configFileFilename + ".");
return false;
}
}
else if (property == "hoverimage")
{
if (!configFile.readTexture(value, configFileFolder, m_TextureHover))
{
TGUI_OUTPUT("TGUI error: Failed to parse value for HoverImage in section Checkbox in " + configFileFilename + ".");
return false;
}
}
else if (property == "focusedimage")
{
if (!configFile.readTexture(value, configFileFolder, m_TextureFocused))
{
TGUI_OUTPUT("TGUI error: Failed to parse value for FocusedImage in section Checkbox in " + configFileFilename + ".");
return false;
}
}
else
TGUI_OUTPUT("TGUI warning: Unrecognized property '" + property + "' in section Checkbox in " + configFileFilename + ".");
}
// Make sure the required texture was loaded
if ((m_TextureChecked.data != nullptr) && (m_TextureUnchecked.data != nullptr))
{
m_Loaded = true;
setSize(static_cast<float>(m_TextureUnchecked.getSize().x), static_cast<float>(m_TextureUnchecked.getSize().y));
}
else
{
TGUI_OUTPUT("TGUI error: Not all needed images were loaded for the checkbox. Is the Checkbox section in " + configFileFilename + " complete?");
return false;
}
// Check if optional textures were loaded
if (m_TextureFocused.data != nullptr)
{
//.........这里部分代码省略.........