replace almost all uses of shared_ptr with unique_ptr.

This commit is contained in:
ITotalJustice
2025-06-23 20:02:04 +01:00
parent aa724e12ba
commit 2ff2923d39
37 changed files with 446 additions and 442 deletions

View File

@@ -58,7 +58,7 @@ public:
static void Exit();
static void ExitRestart();
static auto GetVg() -> NVGcontext*;
static void Push(std::shared_ptr<ui::Widget>);
static void Push(std::unique_ptr<ui::Widget>&&);
// pops all widgets above a menu
static void PopToMenu();
@@ -260,7 +260,7 @@ public:
Vec2 m_scale{1, 1};
std::vector<std::shared_ptr<ui::Widget>> m_widgets;
std::vector<std::unique_ptr<ui::Widget>> m_widgets;
u32 m_pop_count{};
ui::NotifMananger m_notif_manager{};

View File

@@ -55,10 +55,10 @@ using OnExit = std::function<void(Result rc)>;
using OnLocation = std::function<void(const DumpLocation& loc)>;
// prompts the user to select dump location, calls on_loc on success with the selected location.
void DumpGetLocation(const std::string& title, u32 location_flags, OnLocation on_loc);
void DumpGetLocation(const std::string& title, u32 location_flags, const OnLocation& on_loc);
// dumps to a fetched location using DumpGetLocation().
void Dump(std::shared_ptr<BaseSource> source, const DumpLocation& location, const std::vector<fs::FsPath>& paths, OnExit on_exit);
void Dump(const std::shared_ptr<BaseSource>& source, const DumpLocation& location, const std::vector<fs::FsPath>& paths, const OnExit& on_exit);
// DumpGetLocation() + Dump() all in one.
void Dump(std::shared_ptr<BaseSource> source, const std::vector<fs::FsPath>& paths, OnExit on_exit = [](Result){}, u32 location_flags = DumpLocationFlag_All);
void Dump(const std::shared_ptr<BaseSource>& source, const std::vector<fs::FsPath>& paths, const OnExit& on_exit = [](Result){}, u32 location_flags = DumpLocationFlag_All);
} // namespace sphaira::dump

View File

@@ -25,7 +25,7 @@ struct BaseSource {
auto GetTypeStr(Type type) -> const char*;
// returns the hash string.
Result Hash(ui::ProgressBox* pbox, Type type, std::shared_ptr<BaseSource> source, std::string& out);
Result Hash(ui::ProgressBox* pbox, Type type, BaseSource* source, std::string& out);
Result Hash(ui::ProgressBox* pbox, Type type, fs::Fs* fs, const fs::FsPath& path, std::string& out);
Result Hash(ui::ProgressBox* pbox, Type type, std::span<const u8> data, std::string& out);

View File

@@ -60,9 +60,9 @@ void Clear();
// adds new entry to queue.
void PushAsync(u64 app_id);
// gets entry without removing it from the queue.
auto GetAsync(u64 app_id) -> std::shared_ptr<ThreadResultData>;
auto GetAsync(u64 app_id) -> ThreadResultData*;
// single threaded title info fetch.
auto Get(u64 app_id, bool* cached = nullptr) -> std::shared_ptr<ThreadResultData>;
auto Get(u64 app_id, bool* cached = nullptr) -> ThreadResultData*;
auto GetNcmCs(u8 storage_id) -> NcmContentStorage&;
auto GetNcmDb(u8 storage_id) -> NcmContentMetaDatabase&;

View File

@@ -105,9 +105,9 @@ private:
LazyImage m_banner{};
std::unique_ptr<List> m_list{};
std::shared_ptr<ScrollableText> m_details{};
std::shared_ptr<ScrollableText> m_changelog{};
std::shared_ptr<ScrollableText> m_detail_changelog{};
std::unique_ptr<ScrollableText> m_details{};
std::unique_ptr<ScrollableText> m_changelog{};
ScrollableText* m_detail_changelog{};
std::unique_ptr<ScrollableText> m_manifest_list{};
bool m_show_changlog{};

View File

@@ -300,7 +300,7 @@ private:
// contains all selected files for a command, such as copy, delete, cut etc.
struct SelectedStash {
void Add(std::shared_ptr<FsView> view, SelectedType type, const std::vector<FileEntry>& files, const fs::FsPath& path) {
void Add(FsView* view, SelectedType type, const std::vector<FileEntry>& files, const fs::FsPath& path) {
if (files.empty()) {
Reset();
} else {
@@ -335,7 +335,7 @@ struct SelectedStash {
}
// private:
std::shared_ptr<FsView> m_view{};
FsView* m_view{};
std::vector<FileEntry> m_files{};
fs::FsPath m_path{};
SelectedType m_type{SelectedType::None};
@@ -389,9 +389,9 @@ private:
private:
static constexpr inline const char* INI_SECTION = "filebrowser";
std::shared_ptr<FsView> view{};
std::shared_ptr<FsView> view_left{};
std::shared_ptr<FsView> view_right{};
FsView* view{};
std::unique_ptr<FsView> view_left{};
std::unique_ptr<FsView> view_right{};
std::vector<FileAssocEntry> m_assoc_entries{};
SelectedStash m_selected{};

View File

@@ -16,8 +16,6 @@ struct Entry {
NacpLanguageEntry lang{};
int image{};
bool selected{};
std::shared_ptr<title::ThreadResultData> info{};
title::NacpLoadStatus status{title::NacpLoadStatus::None};
auto GetName() const -> const char* {

View File

@@ -55,7 +55,7 @@ protected:
void OnInstallClose();
private:
std::shared_ptr<Stream> m_source{};
std::unique_ptr<Stream> m_source{};
Thread m_thread{};
Mutex m_mutex{};
State m_state{State::None};

View File

@@ -17,7 +17,7 @@ enum class UpdateState {
Error,
};
using MiscMenuFunction = std::function<std::shared_ptr<ui::menu::MenuBase>(u32 flags)>;
using MiscMenuFunction = std::function<std::unique_ptr<MenuBase>(u32 flags)>;
enum MiscMenuFlag : u8 {
// can be set as the rightside menu.
@@ -58,14 +58,14 @@ struct MainMenu final : Widget {
}
private:
void OnLRPress(std::shared_ptr<MenuBase> menu, Button b);
void OnLRPress(MenuBase* menu, Button b);
void AddOnLRPress();
private:
std::shared_ptr<MenuBase> m_centre_menu{};
std::shared_ptr<MenuBase> m_left_menu{};
std::shared_ptr<MenuBase> m_right_menu{};
std::shared_ptr<MenuBase> m_current_menu{};
std::unique_ptr<MenuBase> m_centre_menu{};
std::unique_ptr<MenuBase> m_left_menu{};
std::unique_ptr<MenuBase> m_right_menu{};
MenuBase* m_current_menu{};
std::string m_update_url{};
std::string m_update_version{};

View File

@@ -16,8 +16,6 @@ struct Entry final : FsSaveDataInfo {
NacpLanguageEntry lang{};
int image{};
bool selected{};
std::shared_ptr<title::ThreadResultData> info{};
title::NacpLoadStatus status{title::NacpLoadStatus::None};
auto GetName() const -> const char* {

View File

@@ -31,7 +31,7 @@ struct Menu final : MenuBase {
// this should be private
// private:
std::shared_ptr<yati::source::Usb> m_usb_source{};
std::unique_ptr<yati::source::Usb> m_usb_source{};
bool m_was_mtp_enabled{};
Thread m_thread{};

View File

@@ -95,7 +95,7 @@ private:
class Sidebar final : public Widget {
public:
enum class Side { LEFT, RIGHT };
using Items = std::vector<std::shared_ptr<SidebarEntryBase>>;
using Items = std::vector<std::unique_ptr<SidebarEntryBase>>;
public:
Sidebar(std::string title, Side side, Items&& items);
@@ -108,7 +108,18 @@ public:
auto OnFocusGained() noexcept -> void override;
auto OnFocusLost() noexcept -> void override;
void Add(std::shared_ptr<SidebarEntryBase> entry);
void Add(std::unique_ptr<SidebarEntryBase>&& entry);
template<typename T>
void AddMove(T entry) {
Add(std::move(entry));
}
// template<typename _Tp>
// [[nodiscrad,gnu::always_inline]]
// constexpr typename std::remove_reference<_Tp>::type&&
// move(_Tp&& t) noexcept
// { return static_cast<typename std::remove_reference<_Tp>::type&&>(t); }
private:
void SetIndex(s64 index);

View File

@@ -29,7 +29,7 @@ using Collections = std::vector<CollectionEntry>;
struct Base {
using Source = source::Base;
Base(std::shared_ptr<Source> source) : m_source{source} { }
Base(Source* source) : m_source{source} { }
virtual ~Base() = default;
virtual Result GetCollections(Collections& out) = 0;
auto GetSource() const {
@@ -37,7 +37,7 @@ struct Base {
}
protected:
std::shared_ptr<Source> m_source;
Source* m_source;
};
} // namespace sphaira::yati::container

View File

@@ -79,8 +79,8 @@ struct ConfigOverride {
};
Result InstallFromFile(ui::ProgressBox* pbox, fs::Fs* fs, const fs::FsPath& path, const ConfigOverride& override = {});
Result InstallFromSource(ui::ProgressBox* pbox, std::shared_ptr<source::Base> source, const fs::FsPath& path, const ConfigOverride& override = {});
Result InstallFromContainer(ui::ProgressBox* pbox, std::shared_ptr<container::Base> container, const ConfigOverride& override = {});
Result InstallFromCollections(ui::ProgressBox* pbox, std::shared_ptr<source::Base> source, const container::Collections& collections, const ConfigOverride& override = {});
Result InstallFromSource(ui::ProgressBox* pbox, source::Base* source, const fs::FsPath& path, const ConfigOverride& override = {});
Result InstallFromContainer(ui::ProgressBox* pbox, container::Base* container, const ConfigOverride& override = {});
Result InstallFromCollections(ui::ProgressBox* pbox, source::Base* source, const container::Collections& collections, const ConfigOverride& override = {});
} // namespace sphaira::yati