Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include "tinyxml2.h"
- #include <map>
- #include <string>
- #include <sstream>
- /*
- Provides access to the settings of the game. The settings are loaded once
- as the game launches, and then every aspect that needs the settings
- (read or write) can access one singleton (DONT JUDGE ME!) of the settings class.
- */
- class GameSettings
- {
- public:
- static void LoadSettings(std::string settingsFileName);
- static GameSettings* GetSettings();
- template <typename T> inline T GetValue(std::string settingsName);
- protected:
- private:
- GameSettings(std::string settingsFileName);
- ~GameSettings();
- static GameSettings* m_SettingsInstance;
- tinyxml2::XMLElement* m_SettingsElement;
- tinyxml2::XMLElement* GetXMLElementWithTagName(std::string tagName);
- };
- /*
- Returns an integer value.
- */
- template <> int GameSettings::GetValue<int>(std::string settingsName)
- {
- tinyxml2::XMLElement* valueElement = GetXMLElementWithTagName(settingsName);
- if (!valueElement)
- {
- throw valueElement;
- }
- std::stringstream strValue;
- strValue << valueElement->GetText();
- int intValue; strValue >> intValue;
- return intValue;
- }
- /*
- Returns a std::string value.
- */
- template <> std::string GameSettings::GetValue<std::string>(std::string settingsName)
- {
- tinyxml2::XMLElement* valueElement = GetXMLElementWithTagName(settingsName);
- if (!valueElement)
- {
- throw valueElement;
- }
- return std::string(valueElement->GetText());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement