Created
June 21, 2013 22:26
-
-
Save Shaptic/5834800 to your computer and use it in GitHub Desktop.
operator[] of the Settings module.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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