diff options
author | Spencer Dixon <spencercdixon@gmail.com> | 2021-07-02 09:20:30 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-02 16:47:14 +0200 |
commit | 4a3958c8ae16258071fa127eed7417dd07c41b5d (patch) | |
tree | 10622a02d92f7706bbe51683b4749b0bab016e71 /Userland/Applications/Assistant/Providers.h | |
parent | ccbc54358d351318337c2d49abad48c4d84290df (diff) | |
download | serenity-4a3958c8ae16258071fa127eed7417dd07c41b5d.zip |
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.
Diffstat (limited to 'Userland/Applications/Assistant/Providers.h')
-rw-r--r-- | Userland/Applications/Assistant/Providers.h | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/Userland/Applications/Assistant/Providers.h b/Userland/Applications/Assistant/Providers.h index 89c2ae1357..7d94e1fd12 100644 --- a/Userland/Applications/Assistant/Providers.h +++ b/Userland/Applications/Assistant/Providers.h @@ -11,17 +11,12 @@ #include <LibGUI/Desktop.h> #include <LibJS/Interpreter.h> #include <LibJS/Runtime/VM.h> +#include <typeinfo> namespace Assistant { class Result : public RefCounted<Result> { public: - enum class Kind { - Unknown, - App, - Calculator, - }; - virtual ~Result() = default; virtual void activate() const = 0; @@ -29,22 +24,20 @@ public: RefPtr<Gfx::Bitmap> bitmap() { return m_bitmap; } String const& title() const { return m_title; } String const& subtitle() const { return m_subtitle; } - Kind kind() const { return m_kind; } int score() const { return m_score; } bool equals(Result const& other) const { - return kind() == other.kind() + return typeid(this) == typeid(&other) && title() == other.title() && subtitle() == other.subtitle(); } 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_title(move(title)) , m_subtitle(move(subtitle)) , m_score(score) - , m_kind(kind) { } @@ -53,13 +46,12 @@ private: String m_title; String m_subtitle; int m_score { 0 }; - Kind m_kind; }; class AppResult : public Result { public: 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)) { } @@ -73,7 +65,7 @@ private: class CalculatorResult : public Result { public: 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; |