StoragePreferences.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * StoragePreferences.h
  3. *
  4. * Created on: Nov 9, 2017
  5. * Author: guoxs
  6. */
  7. #ifndef _STORAGE_STORAGEPREFERENCES_H_
  8. #define _STORAGE_STORAGEPREFERENCES_H_
  9. #include <string>
  10. /**
  11. * @brief 数据存储
  12. */
  13. class StoragePreferences {
  14. public:
  15. /**
  16. * @brief 存储string值
  17. */
  18. static bool putString(const std::string &key, const std::string &val);
  19. /**
  20. * @brief 存储int值
  21. */
  22. static bool putInt(const std::string &key, int val);
  23. /**
  24. * @brief 存储bool值
  25. */
  26. static bool putBool(const std::string &key, bool val);
  27. /**
  28. * @brief 存储float值
  29. */
  30. static bool putFloat(const std::string &key, float val);
  31. /**
  32. * @brief 删除key对应的数据
  33. */
  34. static bool remove(const std::string &key);
  35. /**
  36. * @brief 清空存储数据
  37. */
  38. static bool clear();
  39. /**
  40. * @brief 获取key对应的string值,获取不到则返回defVal默认值
  41. */
  42. static std::string getString(const std::string &key, const std::string &defVal);
  43. /**
  44. * @brief 获取key对应的int值,获取不到则返回defVal默认值
  45. */
  46. static int getInt(const std::string &key, int defVal);
  47. /**
  48. * @brief 获取key对应的bool值,获取不到则返回defVal默认值
  49. */
  50. static bool getBool(const std::string &key, bool defVal);
  51. /**
  52. * @brief 获取key对应的float值,获取不到则返回defVal默认值
  53. */
  54. static float getFloat(const std::string &key, float defVal);
  55. };
  56. #endif /* _STORAGE_STORAGEPREFERENCES_H_ */