Mercurial > malikania
diff libserver/malikania/server/db/spell.hpp @ 116:d7025649d85c
Server: add database account
Implement accounts using a abstract factory mechanism, the database object
creates abstract account which are implemented differently depending on the
backend.
See:
- test_database,
- test_account
- broken_account
Refs #687, #682
author | David Demelier <markand@malikania.fr> |
---|---|
date | Mon, 11 Sep 2017 13:18:43 +0200 |
parents | f8c6d2244795 |
children | 1359e09fb3c8 |
line wrap: on
line diff
--- a/libserver/malikania/server/db/spell.hpp Mon Sep 11 16:26:35 2017 +0200 +++ b/libserver/malikania/server/db/spell.hpp Mon Sep 11 13:18:43 2017 +0200 @@ -19,26 +19,66 @@ #ifndef MALIKANIA_SERVER_DB_SPELL_HPP #define MALIKANIA_SERVER_DB_SPELL_HPP -#include <cstdint> +/** + * \file spell.hpp + * \brief Database spell object. + */ + #include <memory> +#include <unordered_set> #include "model.hpp" namespace mlk { +/** + * \brief Database spell object. + */ namespace server { -class character; - /** * \brief Describe a spell. */ -class spell : public model<spell> { +class spell : public model { +private: + friend class character; + protected: - std::string classname_; - std::uint8_t level_{1}; - std::weak_ptr<class character> character_; + std::int64_t character_id_{-1}; //!< parent character + std::string classname_; //!< class type to instanciate + std::uint8_t level_{1}; //!< spell level + + /** + * Save this spell. + * + * The implementation must save the spell and update id, character_id + * member variables. + * + * Then it will be added into character.spells_ variable. + * + * \note called by character::add_spell. + */ + virtual void do_save(std::int64_t character_id) = 0; + /** + * Remove this spell. + * + * The implementation must remove the spell from the database and update + * id, character_id member variables. + * + * \note called by character::remove_spell + */ + virtual void do_remove() = 0; + + /** + * Update the spell level in database. + * + * Only called when the level needs to be changed, the implementation does + * not need to update level_ field. + * + * \note called from set_level helper + * \throw std::exception if the operation could not succeed + */ virtual void do_set_level(std::uint8_t level) = 0; /** @@ -76,38 +116,12 @@ level_ = level; } - - /** - * Get the owner. - * - * \return the owner or null if is_draft() or if character does not exist - */ - inline std::shared_ptr<class character> character() const noexcept - { - return character_.lock(); - } - -#if 0 - /** - * Set the character owner. - * - * \param ch the character (may be null) - * \throw referenced_error if is_public() - */ - void set_character(std::shared_ptr<class character> ch); -#endif }; -#if 0 - -class spell::dao { -public: - virtual void save(std::shared_ptr<spell>&, std::shared_ptr<class character>&) = 0; - virtual void set_level(std::shared_ptr<spell>&, std::uint8_t) = 0; - virtual void remove(std::shared_ptr<spell>&) = 0; -}; - -#endif +/** + * Type for storing spells. + */ +using spell_set = std::unordered_set<std::unique_ptr<spell>>; } // !server