mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2026-06-29 01:54:20 +03:00
GradleSpecifier: Use std::optional instead of DefaultVariable
Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
parent
9171e2b2e1
commit
eba6ffb37b
3 changed files with 5 additions and 32 deletions
|
|
@ -75,9 +75,6 @@ set(CORE_SOURCES
|
|||
# RW lock protected map
|
||||
RWStorage.h
|
||||
|
||||
# A variable that has an implicit default value and keeps track of changes
|
||||
DefaultVariable.h
|
||||
|
||||
# a smart pointer wrapper intended for safer use with Qt signal/slot mechanisms
|
||||
QObjectPtr.h
|
||||
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
template <typename T>
|
||||
class DefaultVariable {
|
||||
public:
|
||||
DefaultVariable(const T& value) { defaultValue = value; }
|
||||
DefaultVariable<T>& operator=(const T& value)
|
||||
{
|
||||
currentValue = value;
|
||||
is_default = currentValue == defaultValue;
|
||||
is_explicit = true;
|
||||
return *this;
|
||||
}
|
||||
operator const T&() const { return is_default ? defaultValue : currentValue; }
|
||||
bool isDefault() const { return is_default; }
|
||||
bool isExplicit() const { return is_explicit; }
|
||||
|
||||
private:
|
||||
T currentValue;
|
||||
T defaultValue;
|
||||
bool is_default = true;
|
||||
bool is_explicit = false;
|
||||
};
|
||||
|
|
@ -38,7 +38,6 @@
|
|||
#include <QRegularExpression>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include "DefaultVariable.h"
|
||||
|
||||
struct GradleSpecifier {
|
||||
GradleSpecifier() { m_valid = false; }
|
||||
|
|
@ -83,8 +82,8 @@ struct GradleSpecifier {
|
|||
if (!m_classifier.isEmpty()) {
|
||||
retval += ":" + m_classifier;
|
||||
}
|
||||
if (m_extension.isExplicit()) {
|
||||
retval += "@" + m_extension;
|
||||
if (m_extension.has_value()) {
|
||||
retval += "@" + m_extension.value();
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
|
@ -97,7 +96,7 @@ struct GradleSpecifier {
|
|||
if (!m_classifier.isEmpty()) {
|
||||
filename += "-" + m_classifier;
|
||||
}
|
||||
filename += "." + m_extension;
|
||||
filename += "." + m_extension.value_or("jar");
|
||||
return filename;
|
||||
}
|
||||
QString toPath(const QString& filenameOverride = QString()) const
|
||||
|
|
@ -122,7 +121,7 @@ struct GradleSpecifier {
|
|||
inline QString artifactId() const { return m_artifactId; }
|
||||
inline void setClassifier(const QString& classifier) { m_classifier = classifier; }
|
||||
inline QString classifier() const { return m_classifier; }
|
||||
inline QString extension() const { return m_extension; }
|
||||
inline std::optional<QString> extension() const { return m_extension; }
|
||||
inline QString artifactPrefix() const { return m_groupId + ":" + m_artifactId; }
|
||||
bool matchName(const GradleSpecifier& other) const
|
||||
{
|
||||
|
|
@ -149,6 +148,6 @@ struct GradleSpecifier {
|
|||
QString m_artifactId;
|
||||
QString m_version;
|
||||
QString m_classifier;
|
||||
DefaultVariable<QString> m_extension = DefaultVariable<QString>("jar");
|
||||
std::optional<QString> m_extension;
|
||||
bool m_valid = false;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue