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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*!********************************************************************
Audacity: A Digital Audio Editor
BasicSettings.h
Vitaly Sverchinsky
**********************************************************************/
#include "BasicSettings.h"
using namespace audacity;
BasicSettings::BasicSettings() = default;
BasicSettings::~BasicSettings() = default;
bool BasicSettings::Exists(const wxString& key) const
{
return HasEntry(key) || HasGroup(key);
}
bool BasicSettings::DeleteGroup(const wxString& key)
{
if(HasGroup(key))
return Remove(key);
return false;
}
bool BasicSettings::DeleteEntry(const wxString& key)
{
if(HasEntry(key))
return Remove(key);
return false;
}
auto BasicSettings::BeginGroup(const wxString& prefix) -> GroupScope
{
DoBeginGroup(prefix);
return { *this };
}
bool BasicSettings::Read(const wxString& key, float* value) const
{
double d;
if(Read(key, &d))
{
*value = static_cast<float>(d);
return true;
}
return false;
}
wxString BasicSettings::Read(const wxString& key, const wxString& defaultValue) const
{
wxString value;
if(!Read(key, &value))
return defaultValue;
return value;
}
wxString BasicSettings::Read(const wxString& key, const char* defaultValue) const
{
wxString value;
if(!Read(key, &value))
return { defaultValue };
return value;
}
wxString BasicSettings::Read(const wxString& key, const wchar_t* defaultValue) const
{
wxString value;
if(!Read(key, &value))
return { defaultValue };
return value;
}
bool BasicSettings::ReadBool(const wxString& key, bool defaultValue) const
{
return Read(key, defaultValue);
}
long BasicSettings::ReadLong(const wxString& key, long defaultValue) const
{
return Read(key, defaultValue);
}
double BasicSettings::ReadDouble(const wxString& key, double defaultValue) const
{
return Read(key, defaultValue);
}
bool BasicSettings::Write(const wxString& key, float value)
{
return Write(key, static_cast<double>(value));
}
bool BasicSettings::Write(const wxString& key, const char* value)
{
return Write(key, wxString(value));
}
bool BasicSettings::Write(const wxString& key, const wchar_t* value)
{
return Write(key, wxString(value));
}
BasicSettings::GroupScope::GroupScope(BasicSettings& settings)
: mSettings(settings)
{
}
void BasicSettings::GroupScope::Reset() noexcept
{
if(mSettings)
mSettings->get().DoEndGroup();
mSettings.reset();
}
BasicSettings::GroupScope::~GroupScope() { Reset(); }
|