Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
properties_file.hpp
Go to the documentation of this file.
1#pragma once
2
3// PropertiesFile — JSON-backed persistent key-value settings.
4// ApplicationProperties — user + common properties with platform-standard paths.
5
6#include <string>
7#include <string_view>
8#include <optional>
9#include <vector>
10#include <map>
11#include <cstdint>
12
13namespace pulp::state {
14
17public:
18 PropertiesFile() = default;
19
21 bool load(std::string_view path);
22
24 bool save(std::string_view path);
25
27 bool save() const;
28
30 std::optional<std::string> get_string(std::string_view key) const;
31 void set_string(std::string_view key, std::string_view value);
32
34 std::optional<int64_t> get_int(std::string_view key) const;
35 void set_int(std::string_view key, int64_t value);
36
38 std::optional<double> get_double(std::string_view key) const;
39 void set_double(std::string_view key, double value);
40
42 std::optional<bool> get_bool(std::string_view key) const;
43 void set_bool(std::string_view key, bool value);
44
46 void remove(std::string_view key);
47
49 bool contains(std::string_view key) const;
50
52 void clear();
53
55 int size() const { return static_cast<int>(values_.size()); }
56
58 std::vector<std::string> keys() const;
59
61 const std::string& path() const { return path_; }
62 void set_path(std::string_view p) { path_ = std::string(p); }
63
64private:
65 bool save_to(const std::string& dest) const;
66 std::map<std::string, std::string, std::less<>> values_;
67 std::string path_;
68};
69
73public:
75 explicit ApplicationProperties(std::string_view app_name);
76
78 PropertiesFile& user_settings() { return user_; }
79 const PropertiesFile& user_settings() const { return user_; }
80
82 PropertiesFile& common_settings() { return common_; }
83 const PropertiesFile& common_settings() const { return common_; }
84
86 void load();
87
89 void save();
90
92 const std::string& app_name() const { return app_name_; }
93
95 static std::string user_settings_dir(std::string_view app_name);
96
98 static std::string common_settings_dir(std::string_view app_name);
99
100private:
101 std::string app_name_;
102 PropertiesFile user_;
103 PropertiesFile common_;
104};
105
106} // namespace pulp::state
const PropertiesFile & user_settings() const
Definition properties_file.hpp:79
static std::string common_settings_dir(std::string_view app_name)
Platform-specific common settings directory.
PropertiesFile & common_settings()
Common/shared settings (e.g., /Library/Application Support/AppName/settings.json).
Definition properties_file.hpp:82
const std::string & app_name() const
Application name.
Definition properties_file.hpp:92
const PropertiesFile & common_settings() const
Definition properties_file.hpp:83
static std::string user_settings_dir(std::string_view app_name)
Platform-specific user settings directory.
PropertiesFile & user_settings()
User-specific settings (e.g., ~/Library/Preferences/AppName.json on macOS).
Definition properties_file.hpp:78
ApplicationProperties(std::string_view app_name)
Initialize with application name (determines storage path).
void save()
Save both settings files.
void load()
Load both user and common settings from their platform paths.
JSON-backed persistent settings file.
Definition properties_file.hpp:16
std::optional< int64_t > get_int(std::string_view key) const
Get/set integer properties.
int size() const
Number of properties.
Definition properties_file.hpp:55
bool load(std::string_view path)
Load properties from a JSON file. Returns false if file doesn't exist or is invalid.
bool save(std::string_view path)
Save properties to a JSON file. Stores the path for subsequent save() calls.
bool contains(std::string_view key) const
Whether a key exists.
void clear()
Clear all properties.
void set_int(std::string_view key, int64_t value)
void set_string(std::string_view key, std::string_view value)
void remove(std::string_view key)
Remove a property.
void set_bool(std::string_view key, bool value)
const std::string & path() const
The file path (set after load or explicit set).
Definition properties_file.hpp:61
void set_path(std::string_view p)
Definition properties_file.hpp:62
std::optional< double > get_double(std::string_view key) const
Get/set float properties.
std::optional< std::string > get_string(std::string_view key) const
Get/set string properties.
std::vector< std::string > keys() const
Get all keys.
bool save() const
Save to the path it was loaded from (or last saved to).
void set_double(std::string_view key, double value)
std::optional< bool > get_bool(std::string_view key) const
Get/set boolean properties.
SequencerStateChannel is the audio-safe transport for a plugin's structured NON-parameter state: the ...
Definition audio_device_manager.hpp:48