43#ifndef __AUDACITY_COMMAND_PARAMETERS_H__
44#define __AUDACITY_COMMAND_PARAMETERS_H__
48#include <wx/cmdline.h>
49#include <wx/fileconf.h>
70 : wxFileConfig(wxEmptyString,
76 SetExpandEnvVars(
false);
82 virtual bool HasGroup(
const wxString & strName)
const override
84 return wxFileConfig::HasGroup(NormalizeName(strName));
87 virtual bool HasEntry(
const wxString& strName)
const override
89 return wxFileConfig::HasEntry(NormalizeName(strName));
94 return wxFileConfig::DoReadString(NormalizeName(
key), pStr);
99 return wxFileConfig::DoReadLong(NormalizeName(
key), pl);
107 struct lconv *info = localeconv();
109 info ? wxString::FromUTF8(info->decimal_point) : wxString(
".");
111 str.Replace(
wxT(
","), dec);
112 str.Replace(
wxT(
"."), dec);
114 return str.ToDouble(pd);
122 return wxFileConfig::DoWriteString(NormalizeName(
key), szValue);
127 return wxFileConfig::DoWriteLong(NormalizeName(
key), lValue);
132 return DoWriteString(
key, wxString::Format(
wxT(
"%.8g"), value));
138 bool success = Read(
key, &d);
148 if (!ReadFloat(
key, pf))
157 return Write(
key, f);
168 size_t nObsoletes = 0)
const
171 if (!wxFileConfig::Read(
key, &s))
175 *
pi = std::find( choices, choices + nChoices,
177 if (*
pi == (
int)nChoices)
179 if (*
pi < 0 && obsoletes) {
180 auto index = std::find_if(obsoletes, obsoletes + nObsoletes,
182 return entry.first == s; })
184 if (index < (
int)nObsoletes)
185 *
pi = (int)obsoletes[index].second;
193 size_t nObsoletes = 0)
const
195 if (!ReadEnum(
key,
pi, choices, nChoices, obsoletes, nObsoletes))
205 if (value < 0 || value >= (
int)nChoices)
210 return wxFileConfig::Write(
key, choices[value].
Internal());
215 ReadFloat(
key, val, defVal);
216 return (*val >=
min && *val <= max);
221 Read(
key, val, defVal);
222 return (*val >=
min && *val <= max);
227 Read(
key, val, defVal);
228 return (*val >=
min && *val <= max);
233 Read(
key, val, defVal);
234 return (*val >=
min && *val <= max);
237 bool ReadAndVerify(
const wxString &
key,
bool *val,
bool defVal,
bool =
false,
bool =
false)
const
239 Read(
key, val, defVal);
244 const wxString& = {},
const wxString& = {} )
const
246 Read(
key, val, defVal);
253 size_t nObsoletes = 0)
const
255 ReadEnum(
key, val, defVal, choices, nChoices, obsoletes, nObsoletes);
256 return (*val != wxNOT_FOUND);
261 wxFileConfig::SetPath(
wxT(
"/"));
267 bool res = wxFileConfig::GetFirstEntry(
key, ndx);
271 if (!wxFileConfig::Read(
key, &val))
278 res = wxFileConfig::GetNextEntry(
key, ndx);
289 wxFileConfig::SetPath(
wxT(
"/"));
291 auto parsed = wxCmdLineParser::ConvertStringToArgs(parms);
293 for (
size_t i = 0, cnt = parsed.size(); i < cnt; i++)
295 wxString
key = parsed[i].BeforeFirst(
wxT(
'=')).Trim(
false).Trim(
true);
296 wxString val = parsed[i].AfterFirst(
wxT(
'=')).Trim(
false).Trim(
true);
298 if (!wxFileConfig::Write(
key, Unescape(val)))
309 wxString cleaned =
name;
311 cleaned.Trim(
true).Trim(
false);
312 cleaned.Replace(
wxT(
" "),
wxT(
"_"));
313 cleaned.Replace(
wxT(
"/"),
wxT(
"_"));
314 cleaned.Replace(
wxT(
"\\"),
wxT(
"_"));
315 cleaned.Replace(
wxT(
":"),
wxT(
"_"));
316 cleaned.Replace(
wxT(
"="),
wxT(
"_"));
323 val.Replace(
wxT(
"\\"),
wxT(
"\\\\"),
true);
324 val.Replace(
wxT(
"\""),
wxT(
"\\\""),
true);
325 val.Replace(
wxT(
"\n"),
wxT(
"\\n"),
true);
332 val.Replace(
wxT(
"\\n"),
wxT(
"\n"),
true);
333 val.Replace(
wxT(
"\\\""),
wxT(
"\""),
true);
334 val.Replace(
wxT(
"\\\\"),
wxT(
"\\"),
true);
@ Internal
Indicates internal failure from Audacity.
static ProjectFileIORegistry::AttributeWriterEntry entry
CommandParameters, derived from wxFileConfig, is essentially doing the same things as the SettingsVis...
virtual bool DoReadDouble(const wxString &key, double *pd) const override
bool ReadAndVerify(const wxString &key, float *val, float defVal, float min, float max) const
virtual bool HasEntry(const wxString &strName) const override
virtual bool DoReadLong(const wxString &key, long *pl) const override
virtual bool DoWriteLong(const wxString &key, long lValue) override
CommandParameters(const wxString &parms={})
static wxString NormalizeName(const wxString &name)
bool WriteEnum(const wxString &key, int value, const EnumValueSymbol choices[], size_t nChoices)
virtual bool DoWriteDouble(const wxString &key, double value) override
bool GetParameters(wxString &parms)
bool ReadEnum(const wxString &key, int *pi, const EnumValueSymbol choices[], size_t nChoices, const ObsoleteMap obsoletes[]=nullptr, size_t nObsoletes=0) const
bool ReadEnum(const wxString &key, int *pi, int defVal, const EnumValueSymbol choices[], size_t nChoices, const ObsoleteMap obsoletes[]=nullptr, size_t nObsoletes=0) const
virtual ~CommandParameters()
std::pair< wxString, size_t > ObsoleteMap
bool ReadAndVerify(const wxString &key, wxString *val, const wxString &defVal, const wxString &={}, const wxString &={}) const
bool ReadAndVerify(const wxString &key, int *val, int defVal, const EnumValueSymbol choices[], size_t nChoices, const ObsoleteMap obsoletes[]=nullptr, size_t nObsoletes=0) const
virtual bool DoWriteString(const wxString &key, const wxString &szValue) override
bool WriteFloat(const wxString &key, float f)
bool ReadAndVerify(const wxString &key, double *val, double defVal, double min, double max) const
wxString Escape(wxString val)
wxString Unescape(wxString val)
bool SetParameters(const wxString &parms)
bool ReadAndVerify(const wxString &key, long *val, long defVal, long min, long max) const
virtual bool DoReadString(const wxString &key, wxString *pStr) const override
bool ReadAndVerify(const wxString &key, bool *val, bool defVal, bool=false, bool=false) const
bool ReadFloat(const wxString &key, float *pf, float defVal) const
bool ReadAndVerify(const wxString &key, int *val, int defVal, int min, int max) const
virtual bool HasGroup(const wxString &strName) const override
bool ReadFloat(const wxString &key, float *pf) const
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...