settings.h 668 B

1234567891011121314151617181920212223242526
  1. #ifndef SETTINGS_H
  2. #define SETTINGS_H
  3. #include <string>
  4. #include <nvs_flash.h>
  5. class Settings {
  6. public:
  7. Settings(const std::string& ns, bool read_write = false);
  8. ~Settings();
  9. std::string GetString(const std::string& key, const std::string& default_value = "");
  10. void SetString(const std::string& key, const std::string& value);
  11. int32_t GetInt(const std::string& key, int32_t default_value = 0);
  12. void SetInt(const std::string& key, int32_t value);
  13. void EraseKey(const std::string& key);
  14. void EraseAll();
  15. private:
  16. std::string ns_;
  17. nvs_handle_t nvs_handle_ = 0;
  18. bool read_write_ = false;
  19. bool dirty_ = false;
  20. };
  21. #endif