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

Assistant: Remove Result::Kind in favor of native typeid

I was unaware of the `typeid` construct in C++ which can be used to
achieve the same thing I was doing with this extra Kind enum.
This commit is contained in:
Spencer Dixon 2021-07-02 09:20:30 -04:00 committed by Andreas Kling
parent ccbc54358d
commit 4a3958c8ae

View file

@ -11,17 +11,12 @@
#include <LibGUI/Desktop.h> #include <LibGUI/Desktop.h>
#include <LibJS/Interpreter.h> #include <LibJS/Interpreter.h>
#include <LibJS/Runtime/VM.h> #include <LibJS/Runtime/VM.h>
#include <typeinfo>
namespace Assistant { namespace Assistant {
class Result : public RefCounted<Result> { class Result : public RefCounted<Result> {
public: public:
enum class Kind {
Unknown,
App,
Calculator,
};
virtual ~Result() = default; virtual ~Result() = default;
virtual void activate() const = 0; virtual void activate() const = 0;
@ -29,22 +24,20 @@ public:
RefPtr<Gfx::Bitmap> bitmap() { return m_bitmap; } RefPtr<Gfx::Bitmap> bitmap() { return m_bitmap; }
String const& title() const { return m_title; } String const& title() const { return m_title; }
String const& subtitle() const { return m_subtitle; } String const& subtitle() const { return m_subtitle; }
Kind kind() const { return m_kind; }
int score() const { return m_score; } int score() const { return m_score; }
bool equals(Result const& other) const bool equals(Result const& other) const
{ {
return kind() == other.kind() return typeid(this) == typeid(&other)
&& title() == other.title() && title() == other.title()
&& subtitle() == other.subtitle(); && subtitle() == other.subtitle();
} }
protected: protected:
Result(RefPtr<Gfx::Bitmap> bitmap, String title, String subtitle, int score = 0, Kind kind = Kind::Unknown) Result(RefPtr<Gfx::Bitmap> bitmap, String title, String subtitle, int score = 0)
: m_bitmap(move(bitmap)) : m_bitmap(move(bitmap))
, m_title(move(title)) , m_title(move(title))
, m_subtitle(move(subtitle)) , m_subtitle(move(subtitle))
, m_score(score) , m_score(score)
, m_kind(kind)
{ {
} }
@ -53,13 +46,12 @@ private:
String m_title; String m_title;
String m_subtitle; String m_subtitle;
int m_score { 0 }; int m_score { 0 };
Kind m_kind;
}; };
class AppResult : public Result { class AppResult : public Result {
public: public:
AppResult(RefPtr<Gfx::Bitmap> bitmap, String title, String subtitle, NonnullRefPtr<Desktop::AppFile> af, int score) AppResult(RefPtr<Gfx::Bitmap> bitmap, String title, String subtitle, NonnullRefPtr<Desktop::AppFile> af, int score)
: Result(move(bitmap), move(title), move(subtitle), score, Kind::App) : Result(move(bitmap), move(title), move(subtitle), score)
, m_app_file(move(af)) , m_app_file(move(af))
{ {
} }
@ -73,7 +65,7 @@ private:
class CalculatorResult : public Result { class CalculatorResult : public Result {
public: public:
explicit CalculatorResult(String title) explicit CalculatorResult(String title)
: Result(GUI::Icon::default_icon("app-calculator").bitmap_for_size(16), move(title), "'Enter' will copy to clipboard"sv, 100, Kind::Calculator) : Result(GUI::Icon::default_icon("app-calculator").bitmap_for_size(16), move(title), "'Enter' will copy to clipboard"sv, 100)
{ {
} }
~CalculatorResult() override = default; ~CalculatorResult() override = default;