Audacity 3.2.0
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
SettingsWX Class Referencefinal

#include <SettingsWX.h>

Inheritance diagram for SettingsWX:
[legend]
Collaboration diagram for SettingsWX:
[legend]

Public Member Functions

 SettingsWX (std::shared_ptr< wxConfigBase > config)
 
 SettingsWX (const wxString &filepath)
 Constructs BasicSettings object to access BasicSettings stored in the file, using platform-specific format. More...
 
 ~SettingsWX () override
 
wxString GetGroup () const override
 Returns current group prefix. More...
 
wxArrayString GetChildGroups () const override
 Returns all child groups within the current group. More...
 
wxArrayString GetChildKeys () const override
 Returns all child keys within the current group. More...
 
bool HasEntry (const wxString &key) const override
 Checks whether specified key exists within the current group. More...
 
bool HasGroup (const wxString &key) const override
 Checks whether specified group exists relative to the current group. More...
 
bool Remove (const wxString &key) override
 Removes group or entry within the current group, if exists. Pass empty string to remove each entry in the current group. More...
 
void Clear () override
 Remove all groups and keys. More...
 
bool Read (const wxString &key, bool *value) const override
 
bool Read (const wxString &key, int *value) const override
 
bool Read (const wxString &key, long *value) const override
 
bool Read (const wxString &key, long long *value) const override
 
bool Read (const wxString &key, double *value) const override
 
bool Read (const wxString &key, wxString *value) const override
 
bool Write (const wxString &key, bool value) override
 
bool Write (const wxString &key, int value) override
 
bool Write (const wxString &key, long value) override
 
bool Write (const wxString &key, long long value) override
 
bool Write (const wxString &key, double value) override
 
bool Write (const wxString &key, const wxString &value) override
 
bool Flush () noexcept override
 
- Public Member Functions inherited from audacity::BasicSettings
 BasicSettings ()
 
virtual ~BasicSettings ()
 
 BasicSettings (const BasicSettings &)=delete
 
 BasicSettings (BasicSettings &&)=default
 
BasicSettingsoperator= (const BasicSettings &)=delete
 
BasicSettingsoperator= (BasicSettings &&)=default
 
virtual wxString GetGroup () const =0
 Returns current group prefix. More...
 
virtual wxArrayString GetChildGroups () const =0
 Returns all child groups within the current group. More...
 
virtual wxArrayString GetChildKeys () const =0
 Returns all child keys within the current group. More...
 
virtual bool HasEntry (const wxString &key) const =0
 Checks whether specified key exists within the current group. More...
 
virtual bool HasGroup (const wxString &key) const =0
 Checks whether specified group exists relative to the current group. More...
 
virtual bool Exists (const wxString &key) const
 Returns true if group or entry exists. More...
 
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 the current group. More...
 
virtual void Clear ()=0
 Remove all groups and keys. More...
 
bool DeleteGroup (const wxString &key)
 Deletes specified group if exists. More...
 
bool DeleteEntry (const wxString &key)
 Deletes specified entry if exists. More...
 
GroupScope BeginGroup (const wxString &prefix)
 Appends a prefix to the current group or sets a new absolute path. Group that was set as current before BeginGroup is called, will be restored once GroupScope is destroyed. More...
 
virtual bool Read (const wxString &key, bool *value) const =0
 
virtual bool Read (const wxString &key, int *value) const =0
 
virtual bool Read (const wxString &key, long *value) const =0
 
virtual bool Read (const wxString &key, long long *value) const =0
 
virtual bool Read (const wxString &key, double *value) const =0
 
virtual bool Read (const wxString &key, wxString *value) const =0
 
virtual bool Read (const wxString &key, float *value) const
 
template<typename T >
bool Read (const wxString &key, T *value) const
 Uses wxFromString to read object. More...
 
template<typename T >
std::enable_if_t< std::is_scalar_v< T >, bool > Read (const wxString &key, T *value, T defaultValue) const
 
template<typename T >
std::enable_if_t<!std::is_scalar_v< T >, bool > Read (const wxString &key, T *value, const T &defaultValue)
 
wxString Read (const wxString &key, const wxString &defaultValue=wxEmptyString) const
 
wxString Read (const wxString &key, const char *defaultValue) const
 
wxString Read (const wxString &key, const wchar_t *defaultValue) const
 
template<typename T >
std::enable_if_t< std::is_scalar_v< T >, T > Read (const wxString &key, T defaultValue) const
 
template<typename T >
std::enable_if_t<!std::is_scalar_v< T >, T > Read (const wxString &key, const T &defaultValue) const
 
virtual bool Write (const wxString &key, bool value)=0
 
virtual bool Write (const wxString &key, int value)=0
 
virtual bool Write (const wxString &key, long value)=0
 
virtual bool Write (const wxString &key, long long value)=0
 
virtual bool Write (const wxString &key, double value)=0
 
virtual bool Write (const wxString &key, const wxString &value)=0
 
virtual bool Write (const wxString &key, float value)
 
virtual bool Write (const wxString &key, const char *value)
 
virtual bool Write (const wxString &key, const wchar_t *value)
 
template<typename T >
bool Write (const wxString &key, const T &value)
 Uses wxToString to convert object into string. More...
 
virtual bool Flush () noexcept=0
 
bool ReadBool (const wxString &key, bool defaultValue) const
 
long ReadLong (const wxString &key, long defaultValue) const
 
double ReadDouble (const wxString &key, double defaultValue) const
 
template<typename T >
ReadObject (const wxString &key, const T &defaultValue) const
 

Protected Member Functions

void DoBeginGroup (const wxString &prefix) override
 
void DoEndGroup () noexcept override
 
virtual void DoBeginGroup (const wxString &prefix)=0
 
virtual void DoEndGroup () noexcept=0
 

Private Member Functions

wxString MakePath (const wxString &key) const
 

Private Attributes

wxArrayString mGroupStack
 
std::shared_ptr< wxConfigBase > mConfig
 

Detailed Description

Definition at line 11 of file SettingsWX.h.

Constructor & Destructor Documentation

◆ SettingsWX() [1/2]

SettingsWX::SettingsWX ( std::shared_ptr< wxConfigBase >  config)
explicit

Definition at line 32 of file SettingsWX.cpp.

33 : mConfig{std::move(config)}
34{
35 mGroupStack.push_back("/");
36}
std::shared_ptr< wxConfigBase > mConfig
Definition: SettingsWX.h:14
wxArrayString mGroupStack
Definition: SettingsWX.h:13

References mGroupStack.

◆ SettingsWX() [2/2]

SettingsWX::SettingsWX ( const wxString &  filepath)
explicit

Constructs BasicSettings object to access BasicSettings stored in the file, using platform-specific format.

Definition at line 38 of file SettingsWX.cpp.

39{
40 mConfig = std::make_shared<wxFileConfig>(wxEmptyString, wxEmptyString, filepath);
41 mGroupStack.push_back("/");
42}

References mConfig, and mGroupStack.

◆ ~SettingsWX()

SettingsWX::~SettingsWX ( )
override

Definition at line 44 of file SettingsWX.cpp.

45{
46 mConfig->Flush();
47}

References mConfig.

Member Function Documentation

◆ Clear()

void SettingsWX::Clear ( )
overridevirtual

Remove all groups and keys.

Implements audacity::BasicSettings.

Definition at line 119 of file SettingsWX.cpp.

120{
121 mConfig->DeleteAll();
122}

References mConfig.

◆ DoBeginGroup()

void SettingsWX::DoBeginGroup ( const wxString &  prefix)
overrideprotectedvirtual

Implements audacity::BasicSettings.

Definition at line 7 of file SettingsWX.cpp.

8{
9 if(prefix.StartsWith("/"))
10 mGroupStack.push_back(prefix);
11 else
12 {
13 if(mGroupStack.size() > 1)
14 mGroupStack.push_back(mGroupStack.Last() + "/" + prefix);
15 else
16 mGroupStack.push_back("/" + prefix);
17 }
18 //This creates group if it didn't exist
19 mConfig->SetPath(mGroupStack.Last());
20}

References mConfig, and mGroupStack.

◆ DoEndGroup()

void SettingsWX::DoEndGroup ( )
overrideprotectedvirtualnoexcept

Implements audacity::BasicSettings.

Definition at line 22 of file SettingsWX.cpp.

23{
24 assert(mGroupStack.size() > 1);// "No matching DoBeginGroup"
25
26 if(mGroupStack.size() > 1)
27 mGroupStack.pop_back();
28
29 mConfig->SetPath(mGroupStack.Last());
30}

References mConfig, and mGroupStack.

◆ Flush()

bool SettingsWX::Flush ( )
overridevirtualnoexcept

Implements audacity::BasicSettings.

Definition at line 190 of file SettingsWX.cpp.

191{
192 try
193 {
194 return mConfig->Flush();
195 }
196 catch(...)
197 {
198 //TODO: log error
199 }
200 return false;
201}

References mConfig.

◆ GetChildGroups()

wxArrayString SettingsWX::GetChildGroups ( ) const
overridevirtual

Returns all child groups within the current group.

Implements audacity::BasicSettings.

Definition at line 60 of file SettingsWX.cpp.

61{
62 long index;
63 wxString group;
64
65 if(mConfig->GetFirstGroup(group, index))
66 {
67 wxArrayString groups;
68 groups.push_back(group);
69 while(mConfig->GetNextGroup(group, index))
70 groups.push_back(group);
71 return groups;
72 }
73 return {};
74}

References mConfig.

Referenced by Remove().

Here is the caller graph for this function:

◆ GetChildKeys()

wxArrayString SettingsWX::GetChildKeys ( ) const
overridevirtual

Returns all child keys within the current group.

Implements audacity::BasicSettings.

Definition at line 76 of file SettingsWX.cpp.

77{
78 long index;
79 wxString key;
80 if(mConfig->GetFirstEntry(key, index))
81 {
82 wxArrayString keys;
83 keys.push_back(key);
84 while(mConfig->GetNextEntry(key, index))
85 keys.push_back(key);
86 return keys;
87 }
88 return {};
89}
static const AudacityProject::AttachedObjects::RegisteredFactory key

References key, and mConfig.

Referenced by Remove().

Here is the caller graph for this function:

◆ GetGroup()

wxString SettingsWX::GetGroup ( ) const
overridevirtual

Returns current group prefix.

Implements audacity::BasicSettings.

Definition at line 49 of file SettingsWX.cpp.

50{
51 assert(!mGroupStack.empty());
52 if(mGroupStack.size() > 1)
53 {
54 const auto& path = mGroupStack.Last();
55 return path.Right(path.Length() - 1);
56 }
57 return {};
58}

References mGroupStack.

◆ HasEntry()

bool SettingsWX::HasEntry ( const wxString &  key) const
overridevirtual

Checks whether specified key exists within the current group.

Implements audacity::BasicSettings.

Definition at line 91 of file SettingsWX.cpp.

92{
93 return mConfig->HasEntry(MakePath(key));
94}
wxString MakePath(const wxString &key) const
Definition: SettingsWX.cpp:203

References key, MakePath(), and mConfig.

Here is the call graph for this function:

◆ HasGroup()

bool SettingsWX::HasGroup ( const wxString &  key) const
overridevirtual

Checks whether specified group exists relative to the current group.

Implements audacity::BasicSettings.

Definition at line 96 of file SettingsWX.cpp.

97{
98 return mConfig->HasGroup(MakePath(key));
99}

References key, MakePath(), and mConfig.

Here is the call graph for this function:

◆ MakePath()

wxString SettingsWX::MakePath ( const wxString &  key) const
private

Definition at line 203 of file SettingsWX.cpp.

204{
205 if(key.StartsWith("/"))
206 return key;
207 if(mGroupStack.size() > 1)
208 return mGroupStack.Last() + "/" + key;
209 return "/" + key;
210}

References key, and mGroupStack.

Referenced by HasEntry(), HasGroup(), Read(), Remove(), and Write().

Here is the caller graph for this function:

◆ Read() [1/6]

bool SettingsWX::Read ( const wxString &  key,
bool *  value 
) const
overridevirtual

Implements audacity::BasicSettings.

Definition at line 124 of file SettingsWX.cpp.

125{
126 return mConfig->Read(MakePath(key), value);
127}

References key, MakePath(), and mConfig.

Here is the call graph for this function:

◆ Read() [2/6]

bool SettingsWX::Read ( const wxString &  key,
double *  value 
) const
overridevirtual

Implements audacity::BasicSettings.

Definition at line 150 of file SettingsWX.cpp.

151{
152 return mConfig->Read(MakePath(key), value);
153}

References key, MakePath(), and mConfig.

Here is the call graph for this function:

◆ Read() [3/6]

bool SettingsWX::Read ( const wxString &  key,
int *  value 
) const
overridevirtual

Implements audacity::BasicSettings.

Definition at line 129 of file SettingsWX.cpp.

130{
131 return mConfig->Read(MakePath(key), value);
132}

References key, MakePath(), and mConfig.

Here is the call graph for this function:

◆ Read() [4/6]

bool SettingsWX::Read ( const wxString &  key,
long *  value 
) const
overridevirtual

Implements audacity::BasicSettings.

Definition at line 134 of file SettingsWX.cpp.

135{
136 return mConfig->Read(MakePath(key), value);
137}

References key, MakePath(), and mConfig.

Here is the call graph for this function:

◆ Read() [5/6]

bool SettingsWX::Read ( const wxString &  key,
long long *  value 
) const
overridevirtual

Implements audacity::BasicSettings.

Definition at line 139 of file SettingsWX.cpp.

140{
141 wxString str;
142 if(mConfig->Read(MakePath(key), &str))
143 {
144 if(str.ToLongLong(value))
145 return true;
146 }
147 return false;
148}
#define str(a)

References key, MakePath(), mConfig, and str.

Here is the call graph for this function:

◆ Read() [6/6]

bool SettingsWX::Read ( const wxString &  key,
wxString *  value 
) const
overridevirtual

Implements audacity::BasicSettings.

Definition at line 155 of file SettingsWX.cpp.

156{
157 return mConfig->Read(MakePath(key), value);
158}

References key, MakePath(), and mConfig.

Here is the call graph for this function:

◆ Remove()

bool SettingsWX::Remove ( const wxString &  key)
overridevirtual

Removes group or entry within the current group, if exists. Pass empty string to remove each entry in the current group.

Implements audacity::BasicSettings.

Definition at line 101 of file SettingsWX.cpp.

102{
103 if(key.empty())
104 {
105 for(auto& group : GetChildGroups())
106 mConfig->DeleteGroup(group);
107 for(auto& entry : GetChildKeys())
108 mConfig->DeleteEntry(entry, false);
109 return true;
110 }
111 const auto path = MakePath(key);
112 if(mConfig->HasEntry(path))
113 return mConfig->DeleteEntry(path, false);
114 if(mConfig->HasGroup(path))
115 return mConfig->DeleteGroup(path);
116 return false;
117}
static ProjectFileIORegistry::AttributeWriterEntry entry
wxArrayString GetChildGroups() const override
Returns all child groups within the current group.
Definition: SettingsWX.cpp:60
wxArrayString GetChildKeys() const override
Returns all child keys within the current group.
Definition: SettingsWX.cpp:76

References entry, GetChildGroups(), GetChildKeys(), key, MakePath(), and mConfig.

Here is the call graph for this function:

◆ Write() [1/6]

bool SettingsWX::Write ( const wxString &  key,
bool  value 
)
overridevirtual

Implements audacity::BasicSettings.

Definition at line 160 of file SettingsWX.cpp.

161{
162 return mConfig->Write(MakePath(key), value);
163}

References key, MakePath(), and mConfig.

Here is the call graph for this function:

◆ Write() [2/6]

bool SettingsWX::Write ( const wxString &  key,
const wxString &  value 
)
overridevirtual

Implements audacity::BasicSettings.

Definition at line 185 of file SettingsWX.cpp.

186{
187 return mConfig->Write(MakePath(key), value);
188}

References key, MakePath(), and mConfig.

Here is the call graph for this function:

◆ Write() [3/6]

bool SettingsWX::Write ( const wxString &  key,
double  value 
)
overridevirtual

Implements audacity::BasicSettings.

Definition at line 180 of file SettingsWX.cpp.

181{
182 return mConfig->Write(MakePath(key), value);
183}

References key, MakePath(), and mConfig.

Here is the call graph for this function:

◆ Write() [4/6]

bool SettingsWX::Write ( const wxString &  key,
int  value 
)
overridevirtual

Implements audacity::BasicSettings.

Definition at line 165 of file SettingsWX.cpp.

166{
167 return mConfig->Write(MakePath(key), value);
168}

References key, MakePath(), and mConfig.

Here is the call graph for this function:

◆ Write() [5/6]

bool SettingsWX::Write ( const wxString &  key,
long long  value 
)
overridevirtual

Implements audacity::BasicSettings.

Definition at line 175 of file SettingsWX.cpp.

176{
177 return mConfig->Write(MakePath(key), wxString::Format("%lld", value));
178}

References key, MakePath(), and mConfig.

Here is the call graph for this function:

◆ Write() [6/6]

bool SettingsWX::Write ( const wxString &  key,
long  value 
)
overridevirtual

Implements audacity::BasicSettings.

Definition at line 170 of file SettingsWX.cpp.

171{
172 return mConfig->Write(MakePath(key), value);
173}

References key, MakePath(), and mConfig.

Here is the call graph for this function:

Member Data Documentation

◆ mConfig

std::shared_ptr<wxConfigBase> SettingsWX::mConfig
private

◆ mGroupStack

wxArrayString SettingsWX::mGroupStack
private

Definition at line 13 of file SettingsWX.h.

Referenced by DoBeginGroup(), DoEndGroup(), GetGroup(), MakePath(), and SettingsWX().


The documentation for this class was generated from the following files: