From df5d1256c26c305f14f398fbc935aa4b6b6aa3bf Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Fri, 15 Apr 2022 13:25:11 +0100 Subject: [PATCH] Implement an object backed IStorage backing This is more convinient and efficient to use when passing structured data out of applets --- .../skyline/services/am/storage/ObjIStorage.h | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 app/src/main/cpp/skyline/services/am/storage/ObjIStorage.h diff --git a/app/src/main/cpp/skyline/services/am/storage/ObjIStorage.h b/app/src/main/cpp/skyline/services/am/storage/ObjIStorage.h new file mode 100644 index 00000000..e00b6373 --- /dev/null +++ b/app/src/main/cpp/skyline/services/am/storage/ObjIStorage.h @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: MPL-2.0 +// Copyright © 2022 Skyline Team and Contributors (https://github.com/skyline-emu/) + +#pragma once + +#include +#include "IStorage.h" + +namespace skyline::service::am { + /** + * @brief ObjIStorage is an IStorage backed by a trivially copyable object + */ + template requires std::is_trivially_copyable_v + class ObjIStorage : public IStorage { + private: + T obj; + + public: + ObjIStorage(const DeviceState &state, ServiceManager &manager, T &&obj) : IStorage(state, manager, true), obj(obj) {} + + ~ObjIStorage() override = default; + + span GetSpan() override { + return {reinterpret_cast(&obj), sizeof(T)}; + }; + }; +}