Advertisement
Guest User

Config.h - 4773n0x

a guest
Nov 22nd, 2016
851
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include <string>
  4. #include <vector>
  5. #include <memory>
  6.  
  7. enum ConfigValueType
  8. {
  9.     CONFIG_INT,
  10.     CONFIG_FLOAT,
  11.     CONFIG_BOOL,
  12.     CONFIG_STRING
  13. };
  14.  
  15. struct ConfigValue
  16. {
  17.     ConfigValue() {}
  18.  
  19.     ConfigValue(int Value, ConfigValueType Type)
  20.     {
  21.         this->Int = Value;
  22.         this->Type = Type;
  23.     }
  24.  
  25.     ConfigValue(float Value, ConfigValueType Type)
  26.     {
  27.         this->Float = Value;
  28.         this->Type = Type;
  29.     }
  30.  
  31.     ConfigValue(bool Value, ConfigValueType Type)
  32.     {
  33.         this->Bool = Value;
  34.         this->Type = Type;
  35.     }
  36.  
  37.     ConfigValue(std::string Value, ConfigValueType Type)
  38.     {
  39.         this->String = Value;
  40.         this->Type = Type;
  41.     }
  42.  
  43.     int             Int;
  44.     float           Float;
  45.     bool            Bool;
  46.     std::string     String;
  47.     ConfigValueType Type;
  48. };
  49.  
  50. struct ConfigSection;
  51.  
  52. class CConfig
  53. {
  54. public:
  55.     void SetValue(std::string SectionName, std::string KeyName, std::unique_ptr<ConfigValue> Value);
  56.     std::shared_ptr<ConfigValue> GetValue(const std::string& SectionName, const std::string& KeyName);
  57.  
  58.     // Returns true if succeeded, returns false if failed.
  59.     bool Save(std::string PathToINI);
  60.     void Load(std::string PathToINI);
  61.  
  62.     // Dump config values into a formatted string.
  63.     std::string DumpValues();
  64.  
  65. private:
  66.     std::vector<std::unique_ptr<ConfigSection>> Sections;
  67. };
  68.  
  69. extern std::unique_ptr<CConfig> Config;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement