1
0

iniparser.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #ifndef HV_INI_PARSER_H_
  2. #define HV_INI_PARSER_H_
  3. #include <string>
  4. using std::string;
  5. #include "hexport.h"
  6. #define DEFAULT_INI_COMMENT "#"
  7. #define DEFAULT_INI_DELIM "="
  8. // fwd
  9. class IniNode;
  10. class HV_EXPORT IniParser {
  11. public:
  12. IniParser();
  13. ~IniParser();
  14. int LoadFromFile(const char* filepath);
  15. int LoadFromMem(const char* data);
  16. int Unload();
  17. int Reload();
  18. string DumpString();
  19. int Save();
  20. int SaveAs(const char* filepath);
  21. string GetValue(const string& key, const string& section = "");
  22. void SetValue(const string& key, const string& value, const string& section = "");
  23. // T = [bool, int, float]
  24. template<typename T>
  25. T Get(const string& key, const string& section = "", T defvalue = 0);
  26. // T = [bool, int, float]
  27. template<typename T>
  28. void Set(const string& key, const T& value, const string& section = "");
  29. protected:
  30. void DumpString(IniNode* pNode, string& str);
  31. public:
  32. string _comment;
  33. string _delim;
  34. string _filepath;
  35. private:
  36. IniNode* root_;
  37. };
  38. #endif // HV_INI_PARSER_H_