version-handler: Refactor maps to simplify accesses
This reduces the number of map lookups needed for read() and close()
operations and the number of stored strings by referencing the pinned
blobId.
Change-Id: I8c6af5749b8cc8415eedeba484bf4a39a98f0286
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/util.hpp b/util.hpp
index e5197dd..26067b5 100644
--- a/util.hpp
+++ b/util.hpp
@@ -13,4 +13,25 @@
inline constexpr char ubiTarballBlobId[] = "/flash/tarball";
inline constexpr char cleanupBlobId[] = "/flash/cleanup";
+/** @brief Lightweight class wrapper that removes move operations from a class
+ * in order to guarantee the contents stay pinned to a specific location
+ * in memory.
+ */
+template <typename T>
+struct Pinned : public T
+{
+ template <typename... Args>
+ Pinned(Args&&... args) : T(std::forward<Args>(args)...)
+ {}
+ template <typename Arg>
+ Pinned& operator=(const Arg& o)
+ {
+ *static_cast<T*>(this) = o;
+ return *this;
+ }
+
+ Pinned(Pinned&&) = delete;
+ Pinned& operator=(Pinned&&) = delete;
+};
+
} // namespace ipmi_flash