iniparser.h 1.2 KB

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