Skip to content

Instantly share code, notes, and snippets.

@Shaptic
Created June 21, 2013 22:26
Show Gist options
  • Save Shaptic/5834800 to your computer and use it in GitHub Desktop.
Save Shaptic/5834800 to your computer and use it in GitHub Desktop.
operator[] of the Settings module.
// In the CSettings.hpp class definition:
std::map<
#ifndef _DEBUG
uint32_t,
#else
string_t,
#endif // _DEBUG
COption> m_Options;
COption& CSettings::operator[](const string_t& opt)
{
// Search via hash with release builds.
#ifndef _DEBUG
uint32_t hash = util::string_hash(opt);
#else
const string_t& hash = opt;
#endif // _DEBUG
// Search for an existing option
auto iter = m_Options.find(hash);
// Not found?
if(iter == m_Options.end())
{
// Create a new blank option and return it
m_Options[hash] = COption();
return m_Options[hash];
}
return iter->second;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment