4773n0x

Config.h

Jun 8th, 2017
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include <string>
  4. #include <fstream>
  5. #include <vector>
  6. #include <memory>
  7.  
  8. class Config
  9. {
  10. public:
  11.     Config(std::string file_path);
  12.  
  13.     void SetupValue(std::string name, std::string& value);
  14.     void SetupValue(std::string name, int& value);
  15.     void SetupValue(std::string name, bool& value);
  16.     void SetupValue(std::string name, float& value);
  17.     void SetupValue(std::string name, double& value);
  18.  
  19.     void Save();
  20.     void Load();
  21.  
  22. private:
  23.     std::string file_path;
  24.  
  25.     template<typename T>
  26.     struct Value
  27.     {
  28.         Value(std::string name, T* value)
  29.         {
  30.             this->name = name;
  31.             this->value = value;
  32.         }
  33.  
  34.         std::string name;
  35.         T* value;
  36.     };
  37.  
  38.     std::vector<std::unique_ptr<Value<std::string>>> strings;
  39.     std::vector<std::unique_ptr<Value<int>>> ints;
  40.     std::vector<std::unique_ptr<Value<bool>>> bools;
  41.     std::vector<std::unique_ptr<Value<float>>> floats;
  42.     std::vector<std::unique_ptr<Value<double>>> doubles;
  43.  
  44.     const std::string delimiter = " = ";
  45.  
  46.     std::vector<std::pair<std::string, std::string>> FileToPairs(std::ifstream& file);
  47. };
Advertisement
Add Comment
Please, Sign In to add comment