WiiUPluginLoaderBackend/source/utils/storage/StorageItem.h

82 lines
2.0 KiB
C
Raw Normal View History

2023-10-07 22:38:27 +02:00
#pragma once
#include <cstdint>
#include <string>
#include <variant>
#include <vector>
2024-11-27 20:44:36 +01:00
2023-10-07 22:38:27 +02:00
enum class StorageItemType { None,
Boolean,
String,
Binary,
S64,
U64,
Double };
class StorageItem {
public:
2024-11-27 20:44:36 +01:00
explicit StorageItem(std::string_view key);
2023-10-07 22:38:27 +02:00
2024-11-27 20:44:36 +01:00
[[nodiscard]] uint32_t getHandle() const;
2023-10-07 22:38:27 +02:00
// Setters for different types
void setValue(bool value);
void setValue(const std::string &value);
void setValue(int32_t value);
void setValue(int64_t value);
void setValue(uint64_t value);
void setValue(uint32_t value);
void setValue(float value);
void setValue(double value);
void setValue(const std::vector<uint8_t> &data);
void setValue(const uint8_t *data, size_t size);
bool getValue(bool &result) const;
bool getValue(int32_t &result) const;
bool getValue(int64_t &result) const;
bool getValue(uint32_t &result) const;
bool getValue(uint64_t &result) const;
bool getValue(float &result) const;
bool getValue(double &result) const;
bool getValue(std::string &result) const;
2023-12-16 12:44:20 +01:00
bool getValue(std::vector<uint8_t> &result) const;
2023-10-07 22:38:27 +02:00
[[nodiscard]] StorageItemType getType() const {
return mType;
}
[[nodiscard]] const std::string &getKey() const {
return mKey;
}
bool getItemSizeString(uint32_t &outSize) const;
bool getItemSizeBinary(uint32_t &outSize) const;
2023-10-07 22:38:27 +02:00
bool attemptBinaryConversion();
private:
std::variant<std::monostate, std::string, bool, int64_t, uint64_t, double, std::vector<uint8_t>> mData = std::monostate{};
StorageItemType mType = StorageItemType::None;
std::string mKey = {};
bool mBinaryConversionDone = true;
};