From 9df087ede0b539ecbd2778236c7d1143362b384d Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Thu, 7 Nov 2024 18:57:04 +0100 Subject: check code standard --- src/crepe/api/SaveManager.h | 74 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 68 insertions(+), 6 deletions(-) (limited to 'src/crepe/api/SaveManager.h') diff --git a/src/crepe/api/SaveManager.h b/src/crepe/api/SaveManager.h index 035e2b7..3073656 100644 --- a/src/crepe/api/SaveManager.h +++ b/src/crepe/api/SaveManager.h @@ -8,21 +8,58 @@ namespace crepe { class DB; +/** + * \brief Save data manager + * + * This class provides access to a simple key-value store that stores + * - integers (8-64 bit, signed or unsigned) + * - real numbers (float or double) + * - string (std::string) + * + * The underlying database is a key-value store. + */ class SaveManager { public: - //! Get a reference to a value and initialize it with a value if it does not yet exist + /** + * \brief Get a read/write reference to a value and initialize it if it does not yet exist + * + * \param key The value key + * \param default_value Value to initialize \c key with if it does not already exist in the database + * + * \return Read/write reference to the value + */ template ValueBroker get(const std::string & key, const T & default_value); - //! Get a reference to a value + /** + * \brief Get a read/write reference to a value + * + * \param key The value key + * + * \return Read/write reference to the value + * + * \note Attempting to read this value before it is initialized (i.e. set) + * will result in an exception + */ template ValueBroker get(const std::string & key); - //! Set a value directly + /** + * \brief Set a value directly + * + * \param key The value key + * \param value The value to store + */ template void set(const std::string & key, const T & value); - //! Check if the save file has a value for this \c key + /** + * \brief Check if the save file has a value for this \c key + * + * \param key The value key + * + * \returns True if the key exists, or false if it does not + */ bool has(const std::string & key); private: @@ -30,11 +67,26 @@ private: virtual ~SaveManager() = default; private: + /** + * \brief Serialize an arbitrary value to STL string + * + * \tparam T Type of arbitrary value + * + * \returns String representation of value + */ template - std::string serialize(const T &); + std::string serialize(const T &) const noexcept; + /** + * \brief Deserialize an STL string back to type \c T + * + * \tparam T Type of value + * \param value Serialized value + * + * \returns Deserialized value + */ template - T deserialize(const std::string &); + T deserialize(const std::string & value) const noexcept; public: // singleton @@ -45,6 +97,16 @@ public: SaveManager & operator = (SaveManager &&) = delete; private: + /** + * \brief Create an instance of DB and return its reference + * + * \returns DB instance + * + * This function exists because DB is a facade class, which can't directly be + * used in the API without workarounds + * + * TODO: better solution + */ static DB & get_db(); }; -- cgit v1.2.3