1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 15:07:45 +00:00

LibDSP: Get rid of DeprecatedString

This was a rather easy change, since only parameter names make use of
strings in the first place.

This also improves OOM resistance: If we can't create a parameter name,
we will just set it to the empty string.
This commit is contained in:
kleines Filmröllchen 2023-02-25 12:07:01 +01:00 committed by Linus Groh
parent 8a50c967b8
commit 76b71fcb75
7 changed files with 27 additions and 27 deletions

View file

@ -7,11 +7,11 @@
#pragma once
#include <AK/Concepts.h>
#include <AK/DeprecatedString.h>
#include <AK/FixedPoint.h>
#include <AK/Format.h>
#include <AK/Forward.h>
#include <AK/Function.h>
#include <AK/String.h>
#include <AK/Types.h>
#include <LibDSP/Music.h>
@ -36,17 +36,18 @@ enum class Logarithmic : bool {
// Processors have modifiable parameters that should be presented to the UI in a uniform way without requiring the processor itself to implement custom interfaces.
class ProcessorParameter {
public:
ProcessorParameter(DeprecatedString name, ParameterType type)
: m_name(move(name))
, m_type(type)
ProcessorParameter(ErrorOr<String> name, ParameterType type)
: m_type(type)
{
if (!name.is_error())
m_name = name.release_value();
}
DeprecatedString const& name() const { return m_name; }
String const& name() const { return m_name; }
ParameterType type() const { return m_type; }
private:
DeprecatedString const m_name;
String m_name {};
ParameterType const m_type;
};
@ -60,7 +61,7 @@ template<typename ParameterT>
class ProcessorParameterSingleValue : public ProcessorParameter {
public:
ProcessorParameterSingleValue(DeprecatedString name, ParameterType type, ParameterT initial_value)
ProcessorParameterSingleValue(ErrorOr<String> name, ParameterType type, ParameterT initial_value)
: ProcessorParameter(move(name), type)
, m_value(move(initial_value))
{
@ -106,7 +107,7 @@ protected:
class ProcessorBooleanParameter final : public Detail::ProcessorParameterSingleValue<bool> {
public:
ProcessorBooleanParameter(DeprecatedString name, bool initial_value)
ProcessorBooleanParameter(String name, bool initial_value)
: Detail::ProcessorParameterSingleValue<bool>(move(name), ParameterType::Boolean, move(initial_value))
{
}
@ -114,7 +115,7 @@ public:
class ProcessorRangeParameter final : public Detail::ProcessorParameterSingleValue<ParameterFixedPoint> {
public:
ProcessorRangeParameter(DeprecatedString name, ParameterFixedPoint min_value, ParameterFixedPoint max_value, ParameterFixedPoint initial_value, Logarithmic logarithmic)
ProcessorRangeParameter(ErrorOr<String> name, ParameterFixedPoint min_value, ParameterFixedPoint max_value, ParameterFixedPoint initial_value, Logarithmic logarithmic)
: Detail::ProcessorParameterSingleValue<ParameterFixedPoint>(move(name), ParameterType::Range, move(initial_value))
, m_min_value(move(min_value))
, m_max_value(move(max_value))
@ -150,7 +151,7 @@ private:
template<Enum EnumT>
class ProcessorEnumParameter final : public Detail::ProcessorParameterSingleValue<EnumT> {
public:
ProcessorEnumParameter(DeprecatedString name, EnumT initial_value)
ProcessorEnumParameter(ErrorOr<String> name, EnumT initial_value)
: Detail::ProcessorParameterSingleValue<EnumT>(move(name), ParameterType::Enum, initial_value)
{
}
@ -186,7 +187,7 @@ struct AK::Formatter<DSP::ProcessorRangeParameter> : AK::StandardFormatter {
m_width = m_width.value_or(0);
m_precision = m_precision.value_or(NumericLimits<size_t>::max());
TRY(builder.put_literal(DeprecatedString::formatted("[{} - {}]: {}", value.min_value(), value.max_value(), value.value())));
TRY(builder.put_literal(TRY(String::formatted("[{} - {}]: {}", value.min_value(), value.max_value(), value.value())).bytes_as_string_view()));
return {};
}
};