adding convertType and minor changes
This commit is contained in:
parent
d29b139321
commit
43001f40b7
|
@ -93,12 +93,12 @@ void ConfigManager::setValue(const std::string &key, const char *value)
|
||||||
|
|
||||||
void ConfigManager::setValue(const std::string &key, int value)
|
void ConfigManager::setValue(const std::string &key, int value)
|
||||||
{
|
{
|
||||||
setValue(key, boost::lexical_cast<std::string>(value));
|
setValue(key, convertType<std::string, int>(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigManager::setValue(const std::string &key, float value)
|
void ConfigManager::setValue(const std::string &key, float value)
|
||||||
{
|
{
|
||||||
setValue(key, boost::lexical_cast<std::string>(value));
|
setValue(key, convertType<std::string, float>(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigManager::setValue(const std::string &key, bool value)
|
void ConfigManager::setValue(const std::string &key, bool value)
|
||||||
|
@ -127,7 +127,7 @@ float ConfigManager::getFloat(const std::string &key)
|
||||||
warning("Config value %s not found", key.c_str());
|
warning("Config value %s not found", key.c_str());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return boost::lexical_cast<float>(iter->second);
|
return convertType<float, std::string>(iter->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConfigManager::getBoolean(const std::string &key)
|
bool ConfigManager::getBoolean(const std::string &key)
|
||||||
|
@ -147,5 +147,5 @@ int ConfigManager::getInteger(const std::string &key)
|
||||||
warning("Config value %s not found", key.c_str());
|
warning("Config value %s not found", key.c_str());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return boost::lexical_cast<int>(iter->second);
|
return convertType<int, std::string>(iter->second);
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ bool ResourceManager::setWriteDir(const std::string& path)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ResourceManager::addToSearchPath(const std::string& path, bool insertInFront)
|
bool ResourceManager::addToSearchPath(const std::string& path, bool insertInFront /*= true*/)
|
||||||
{
|
{
|
||||||
if(!PHYSFS_addToSearchPath(path.c_str(), insertInFront ? 0 : 1)) {
|
if(!PHYSFS_addToSearchPath(path.c_str(), insertInFront ? 0 : 1)) {
|
||||||
error("Error while adding \"%s\" to resources search path: %s", path.c_str(), PHYSFS_getLastError());
|
error("Error while adding \"%s\" to resources search path: %s", path.c_str(), PHYSFS_getLastError());
|
||||||
|
|
|
@ -33,4 +33,21 @@ std::string vformat(const char *format, va_list args);
|
||||||
/// Formatting like printf for std::string
|
/// Formatting like printf for std::string
|
||||||
std::string format(const char *format, ...);
|
std::string format(const char *format, ...);
|
||||||
|
|
||||||
|
/// Convert any data type through boost::lexical_cast
|
||||||
|
//TODO: move declatation to util.cpp
|
||||||
|
template<class R, class T>
|
||||||
|
R convertType(T t)
|
||||||
|
{
|
||||||
|
R r = R();
|
||||||
|
|
||||||
|
try{
|
||||||
|
r = boost::lexical_cast<R>(t);
|
||||||
|
}
|
||||||
|
catch(boost::bad_lexical_cast bad){
|
||||||
|
//TODO: add an error message
|
||||||
|
}
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -288,7 +288,7 @@ void Platform::showMouseCursor()
|
||||||
ShowCursor(true);
|
ShowCursor(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Platform::setVsync(bool enable)
|
void Platform::setVsync(bool enable /*= true*/)
|
||||||
{
|
{
|
||||||
typedef GLint (*glSwapIntervalProc)(GLint);
|
typedef GLint (*glSwapIntervalProc)(GLint);
|
||||||
glSwapIntervalProc glSwapInterval = NULL;
|
glSwapIntervalProc glSwapInterval = NULL;
|
||||||
|
|
|
@ -108,7 +108,7 @@ int main(int argc, const char *argv[])
|
||||||
|
|
||||||
// state scope
|
// state scope
|
||||||
{
|
{
|
||||||
std::unique_ptr<MenuState> menuState(new MenuState);
|
std::unique_ptr<MenuState> menuState(new MenuState());
|
||||||
g_engine.changeState(menuState.get());
|
g_engine.changeState(menuState.get());
|
||||||
|
|
||||||
Platform::showWindow();
|
Platform::showWindow();
|
||||||
|
|
|
@ -35,14 +35,14 @@ public:
|
||||||
MenuState();
|
MenuState();
|
||||||
virtual ~MenuState();
|
virtual ~MenuState();
|
||||||
|
|
||||||
void onEnter();
|
virtual void onEnter();
|
||||||
void onLeave();
|
virtual void onLeave();
|
||||||
|
|
||||||
void onClose();
|
virtual void onClose();
|
||||||
void onInputEvent(InputEvent *event);
|
virtual void onInputEvent(InputEvent *event);
|
||||||
|
|
||||||
void render();
|
virtual void render();
|
||||||
void update(int ticks, int elapsedTicks);
|
virtual void update(int ticks, int elapsedTicks);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TexturePtr m_background;
|
TexturePtr m_background;
|
||||||
|
|
Loading…
Reference in New Issue