iniparser.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #ifndef HV_INI_PARSER_H_
  2. #define HV_INI_PARSER_H_
  3. #include <string>
  4. #include <list>
  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. std::string DumpString();
  19. int Save();
  20. int SaveAs(const char* filepath);
  21. std::list<std::string> GetKeys(const std::string& section = "");
  22. std::string GetValue(const std::string& key, const std::string& section = "");
  23. void SetValue(const std::string& key, const std::string& value, const std::string& section = "");
  24. // T = [bool, int, float]
  25. template<typename T>
  26. T Get(const std::string& key, const std::string& section = "", T defvalue = 0);
  27. // T = [bool, int, float]
  28. template<typename T>
  29. void Set(const std::string& key, const T& value, const std::string& section = "");
  30. protected:
  31. void DumpString(IniNode* pNode, std::string& str);
  32. public:
  33. std::string _comment;
  34. std::string _delim;
  35. std::string _filepath;
  36. private:
  37. IniNode* root_;
  38. };
  39. #endif // HV_INI_PARSER_H_