coming
天行健 君子以自强不息
记录我的成长
文章目录
类Preferences就是用来处理项目的配置文件。它定义于src/musikcore/support/Preferences.h,继承自类IPreferences(类IPreferences定义于src/musikcore/sdk/IPreferences.h,仅定义了一些读取与设置配置项的虚函数,具体由子类实现)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| class Preferences : public mymusic::core::sdk::IPreferences { public: enum Mode { ModeTransient, ModeReadOnly, ModeReadWrite, ModeAutoSave }; static void LoadPluginPreferences(); static void SavePluginPreferences();
static mymusic::core::sdk::IPreferences* Unmanaged(const std::string& name); static std::shared_ptr<Preferences> ForPlugin(const std::string& pluginName); static std::shared_ptr<Preferences> ForComponent(const std::string& c, Mode mode = ModeAutoSave); ~Preferences();
virtual void Release() override; bool GetBool(const char* key, bool defaultValue = false) override; int GetInt(const char* key, int defaultValue = 0) override; double GetDouble(const char* key, double defaultValue = 0.0f) override; int GetString(const char* key, char* dst, size_t size, const char* defaultValue = "") override; void SetBool(const char* key, bool value) override; void SetInt(const char* key, int value) override; void SetDouble(const char* key, double value) override; void SetString(const char* key, const char* value) override;
void Save() override;
bool GetBool(const std::string& key, bool defaultValue = false); int GetInt(const std::string& key, int defaultValue = 0); double GetDouble(const std::string& key, double defaultValue = 0.0f); std::string GetString(const std::string& key, const std::string& defaultValue = "");
void SetBool(const std::string& key, bool value); void SetInt(const std::string& key, int value); void SetDouble(const std::string& key, double value); void SetString(const std::string& key, const char* value); void GetKeys(std::vector<std::string>& target); bool HasKey(const std::string& key); void Remove(const std::string& key);
private: Preferences(const std::string& component, Mode mode); void Load(); std::mutex mutex; nlohmann::json json; std::string component; Mode mode; };
|
本文代表个人观点,内容仅供参考。若有不恰当之处,望不吝赐教!