CConfigFile.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #pragma once
  2. #include <AK/String.h>
  3. #include <AK/HashMap.h>
  4. #include <AK/RefPtr.h>
  5. #include <AK/RefCounted.h>
  6. #include <AK/Vector.h>
  7. #include <LibDraw/Color.h>
  8. class CConfigFile : public RefCounted<CConfigFile> {
  9. public:
  10. static NonnullRefPtr<CConfigFile> get_for_app(const String& app_name);
  11. static NonnullRefPtr<CConfigFile> get_for_system(const String& app_name);
  12. ~CConfigFile();
  13. bool has_group(const String&) const;
  14. bool has_key(const String& group, const String& key) const;
  15. Vector<String> groups() const;
  16. Vector<String> keys(const String& group) const;
  17. String read_entry(const String& group, const String& key, const String& default_vaule = String()) const;
  18. int read_num_entry(const String& group, const String& key, int default_value = 0) const;
  19. bool read_bool_entry(const String& group, const String& key, bool default_value = false) const;
  20. Color read_color_entry(const String& group, const String& key, Color default_value) const;
  21. void write_entry(const String& group, const String& key, const String& value);
  22. void write_num_entry(const String& group, const String& key, int value);
  23. void write_bool_entry(const String& group, const String& key, bool value);
  24. void write_color_entry(const String& group, const String& key, Color value);
  25. void dump() const;
  26. bool is_dirty() const { return m_dirty; }
  27. bool sync();
  28. void remove_group(const String& group);
  29. void remove_entry(const String& group, const String& key);
  30. String file_name() const { return m_file_name; }
  31. private:
  32. explicit CConfigFile(const String& file_name);
  33. void reparse();
  34. String m_file_name;
  35. HashMap<String, HashMap<String, String>> m_groups;
  36. bool m_dirty { false };
  37. };