1
0

iniparser.h 1.1 KB

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