Audacity 3.2.0
BasicSettings.cpp
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*!********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 BasicSettings.h
7
8 Vitaly Sverchinsky
9
10**********************************************************************/
11
12#include "BasicSettings.h"
13
14using namespace audacity;
15
16BasicSettings::BasicSettings() = default;
17
18BasicSettings::~BasicSettings() = default;
19
20bool BasicSettings::Exists(const wxString& key) const
21{
22 return HasEntry(key) || HasGroup(key);
23}
24
25bool BasicSettings::DeleteGroup(const wxString& key)
26{
27 if(HasGroup(key))
28 return Remove(key);
29 return false;
30}
31
32bool BasicSettings::DeleteEntry(const wxString& key)
33{
34 if(HasEntry(key))
35 return Remove(key);
36 return false;
37}
38
39auto BasicSettings::BeginGroup(const wxString& prefix) -> GroupScope
40{
41 DoBeginGroup(prefix);
42 return { *this };
43}
44
45bool BasicSettings::Read(const wxString& key, float* value) const
46{
47 double d;
48 if(Read(key, &d))
49 {
50 *value = static_cast<float>(d);
51 return true;
52 }
53 return false;
54}
55
56wxString BasicSettings::Read(const wxString& key, const wxString& defaultValue) const
57{
58 wxString value;
59 if(!Read(key, &value))
60 return defaultValue;
61 return value;
62}
63
64wxString BasicSettings::Read(const wxString& key, const char* defaultValue) const
65{
66 wxString value;
67 if(!Read(key, &value))
68 return { defaultValue };
69 return value;
70}
71
72wxString BasicSettings::Read(const wxString& key, const wchar_t* defaultValue) const
73{
74 wxString value;
75 if(!Read(key, &value))
76 return { defaultValue };
77 return value;
78}
79
80bool BasicSettings::ReadBool(const wxString& key, bool defaultValue) const
81{
82 return Read(key, defaultValue);
83}
84
85long BasicSettings::ReadLong(const wxString& key, long defaultValue) const
86{
87 return Read(key, defaultValue);
88}
89
90double BasicSettings::ReadDouble(const wxString& key, double defaultValue) const
91{
92 return Read(key, defaultValue);
93}
94
95bool BasicSettings::Write(const wxString& key, float value)
96{
97 return Write(key, static_cast<double>(value));
98}
99
100bool BasicSettings::Write(const wxString& key, const char* value)
101{
102 return Write(key, wxString(value));
103}
104
105bool BasicSettings::Write(const wxString& key, const wchar_t* value)
106{
107 return Write(key, wxString(value));
108}
109
111 : mSettings(settings)
112{
113}
114
116{
117 if(mSettings)
118 mSettings->get().DoEndGroup();
119 mSettings.reset();
120}
121
static const AudacityProject::AttachedObjects::RegisteredFactory key
static Settings & settings()
Definition: TrackInfo.cpp:51
GroupScope(BasicSettings &settings)
Base class for objects that provide facility to store data persistently, and access it with string ke...
Definition: BasicSettings.h:31
double ReadDouble(const wxString &key, double defaultValue) const
virtual bool HasGroup(const wxString &key) const =0
Checks whether specified group exists relative to the current group.
GroupScope BeginGroup(const wxString &prefix)
Appends a prefix to the current group or sets a new absolute path. Group that was set as current befo...
virtual bool HasEntry(const wxString &key) const =0
Checks whether specified key exists within the current group.
bool DeleteGroup(const wxString &key)
Deletes specified group if exists.
virtual bool Write(const wxString &key, bool value)=0
long ReadLong(const wxString &key, long defaultValue) const
virtual bool Remove(const wxString &key)=0
Removes group or entry within the current group, if exists. Pass empty string to remove each entry in...
bool ReadBool(const wxString &key, bool defaultValue) const
bool DeleteEntry(const wxString &key)
Deletes specified entry if exists.
virtual bool Read(const wxString &key, bool *value) const =0