INI.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // Created by xcbosa on 2023/1/30.
  3. //
  4. #pragma once
  5. #include "utils-private.h"
  6. namespace xc {
  7. namespace utils {
  8. class INI;
  9. class INISection {
  10. friend class INI;
  11. public:
  12. INISection();
  13. INISection(string title, map<string, string> data);
  14. bool has(string key);
  15. string get(string key);
  16. void set(string key, string value);
  17. string getTitle();
  18. void setTitle(string title);
  19. private:
  20. string title;
  21. map<string, string> data;
  22. };
  23. class INI {
  24. public:
  25. INI();
  26. INI(string string);
  27. INI(vector<INISection> data);
  28. friend INI readFromFile(string filePath);
  29. bool has(string header);
  30. INISection* get(string header);
  31. INISection* getMust(string header);
  32. void remove(string header);
  33. string getINIString();
  34. vector<INISection> data;
  35. };
  36. class INIFile: public INI {
  37. public:
  38. INIFile(string filePath);
  39. void save();
  40. private:
  41. string filePath;
  42. };
  43. } // xc
  44. } // utils