Make LibrarySettings follow PIMPL, adds documentation.

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
Deukhoofd 2020-09-30 18:49:39 +02:00
parent dd8847a441
commit 539a278114
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
2 changed files with 36 additions and 9 deletions

View File

@ -0,0 +1,22 @@
#include "LibrarySettings.hpp"
namespace CreatureLib::Library {
struct LibrarySettings::impl {
level_int_t _maximalLevel;
uint8_t _maximalAttacks;
public:
impl(level_int_t maximalLevel, uint8_t maximalAttacks)
: _maximalLevel(maximalLevel), _maximalAttacks(maximalAttacks) {}
[[nodiscard]] inline level_int_t GetMaximalLevel() const noexcept { return _maximalLevel; }
[[nodiscard]] inline uint8_t GetMaximalAttacks() const noexcept { return _maximalAttacks; }
};
LibrarySettings::LibrarySettings(level_int_t maximalLevel, uint8_t maximalAttacks)
: _impl(new impl(maximalLevel, maximalAttacks)) {}
LibrarySettings::~LibrarySettings() = default;
level_int_t LibrarySettings::GetMaximalLevel() const noexcept { return _impl->GetMaximalLevel(); }
uint8_t LibrarySettings::GetMaximalAttacks() const noexcept { return _impl->GetMaximalAttacks(); }
}

View File

@ -1,20 +1,25 @@
#ifndef CREATURELIB_LIBRARYSETTINGS_HPP
#define CREATURELIB_LIBRARYSETTINGS_HPP
#include "../Defines.hpp"
namespace CreatureLib::Library {
/// @brief Hold the different runtime settings for a given library.
class LibrarySettings {
level_int_t _maximalLevel;
uint8_t _maximalAttacks;
struct impl;
std::unique_ptr<impl> _impl;
public:
LibrarySettings(level_int_t maximalLevel, uint8_t maximalAttacks)
: _maximalLevel(maximalLevel), _maximalAttacks(maximalAttacks) {}
/// @brief Initialises LibrarySettings.
/// @param maximalLevel The maximal level a creature can be.
/// @param maximalAttacks The maximal number of attacks a creature can have.
LibrarySettings(level_int_t maximalLevel, uint8_t maximalAttacks);
virtual ~LibrarySettings();
inline level_int_t GetMaximalLevel() const noexcept { return _maximalLevel; }
inline uint8_t GetMaximalAttacks() const noexcept { return _maximalAttacks; }
/// @brief Returns the maximal level a creature can be in the current library.
/// @return The maximal level a creature can be in the current library.
[[nodiscard]] level_int_t GetMaximalLevel() const noexcept;
/// @brief Returns the maximal number of attacks a creature can have.
/// @return The maximal number of attacks a creature can have.
[[nodiscard]] uint8_t GetMaximalAttacks() const noexcept;
};
}