Medical Imaging Interaction Toolkit
2023.12.00
Medical Imaging Interaction Toolkit
|
Go to the documentation of this file.
13 #ifndef mitkPreferences_h
14 #define mitkPreferences_h
19 #include <unordered_map>
23 class IPreferencesStorage;
35 using Properties = std::unordered_map<std::string, std::string>;
46 std::string
Get(
const std::string& key,
const std::string& def)
const override;
47 void Put(
const std::string& key,
const std::string& value)
override;
49 int GetInt(
const std::string& key,
int def)
const override;
50 void PutInt(
const std::string& key,
int value)
override;
52 bool GetBool(
const std::string& key,
bool def)
const override;
53 void PutBool(
const std::string& key,
bool value)
override;
55 float GetFloat(
const std::string& key,
float def)
const override;
56 void PutFloat(
const std::string& key,
float value)
override;
58 double GetDouble(
const std::string& key,
double def)
const override;
59 void PutDouble(
const std::string& key,
double value)
override;
61 std::vector<std::byte>
GetByteArray(
const std::string& key,
const std::byte* def,
size_t size)
const override;
62 void PutByteArray(
const std::string& key,
const std::byte* array,
size_t size)
override;
64 void Remove(
const std::string& key)
override;
65 void Clear()
override;
66 std::vector<std::string>
Keys()
const override;
74 std::string
Name()
const override;
76 void Flush()
override;
79 const std::vector<std::unique_ptr<Preferences>>&
GetChildren()
const;
83 void Put(
const std::string& key,
const T& value,
const std::function<std::string(
const T&)>& toString)
85 const auto oldValue = m_Properties[key];
86 const auto newValue = toString(value);
87 m_Properties[key] = newValue;
89 if (oldValue != newValue)
97 std::vector<std::unique_ptr<Preferences>> m_Children;
102 IPreferencesStorage* m_Storage;
void PutByteArray(const std::string &key, const std::byte *array, size_t size) override
Put binary data into a property value.
std::vector< std::byte > GetByteArray(const std::string &key, const std::byte *def, size_t size) const override
Get a property value as typeless binary representation.
void PutDouble(const std::string &key, double value) override
Set a double property value.
std::unordered_map< std::string, std::string > Properties
std::string Name() const override
Get the name of this preferences node.
Event object sent on IPreferences::OnPropertyChanged events.
const Properties & GetProperties() const
IPreferences * Node(const std::string &path) override
Get (and possibly create) the preferences node specified by the given path.
Preferences(const Properties &properties, const std::string &name, Preferences *parent, IPreferencesStorage *storage)
Message1< const ChangeEvent & > OnPropertyChanged
Notify on property changes.
double GetDouble(const std::string &key, double def) const override
Get a property value as double.
void Clear() override
Remove all properties from this preferences node.
std::vector< std::string > ChildrenNames() const override
Get the names of all direct child preference nodes.
void PutBool(const std::string &key, bool value) override
Set a bool property value.
std::vector< std::string > Keys() const override
Get the names of all properties of this preferences node.
The backend for persistent preferences.
int GetInt(const std::string &key, int def) const override
Get a property value as int.
float GetFloat(const std::string &key, float def) const override
Get a property value as float.
Find image slices visible on a given plane.
void RemoveNode() override
Remove this preferences node from its parent node.
Message1< const IPreferences * > OnChanged
Notify on node changes.
void PutInt(const std::string &key, int value) override
Set an int property value.
IPreferences * Root() override
Get the root preferences node.
Implementation of the IPreferences interface.
bool GetBool(const std::string &key, bool def) const override
Get a property value as bool.
void PutFloat(const std::string &key, float value) override
Set a float property value.
void Put(const std::string &key, const std::string &value) override
Set a property value.
void Remove(const std::string &key) override
Remove a property from this preferences node.
Preferences & operator=(const Preferences &)=delete
Interface to application preferences.
const std::vector< std::unique_ptr< Preferences > > & GetChildren() const
std::string Get(const std::string &key, const std::string &def) const override
Get a property value as string.
void Flush() override
Write all (!) preferences to disk.
std::string AbsolutePath() const override
Get the absolute path (relative to the root node) of this preferences node.
IPreferences * Parent() override
Get the parent preferences node or nullptr in case of the root node.