From 15deae1504fcb09cbfb967ef313dcd8d77b97ee4 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 26 Sep 2020 12:46:48 +0200 Subject: [PATCH] Adds some documentation, add .clang-tidy file. Signed-off-by: Deukhoofd --- .clang-tidy | 11 +++++++++++ src/Defines.hpp | 2 +- src/Library/CreatureData/SpeciesVariant.cpp | 16 ++++++++------- src/Library/CreatureData/SpeciesVariant.hpp | 2 -- src/Library/CreatureData/TalentIndex.hpp | 22 +++++++++++++++------ 5 files changed, 37 insertions(+), 16 deletions(-) create mode 100644 .clang-tidy diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..884002b --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,11 @@ +Checks: 'readability-*,clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-alpha*,performance-*,cppcoreguidelines-*, +bugprone-*,modernize-*,-modernize-use-trailing-return-type' +HeaderFilterRegex: '' +AnalyzeTemporaryDtors: false +CheckOptions: + - key: readability-identifier-naming.ClassCase + value: CamelCase + - key: readability-identifier-naming.PrivateMemberCase + value: camelBack + - key: readability-identifier-naming.PrivateMemberPrefix + value: '_' \ No newline at end of file diff --git a/src/Defines.hpp b/src/Defines.hpp index d9102e8..4bc62e9 100644 --- a/src/Defines.hpp +++ b/src/Defines.hpp @@ -1,6 +1,6 @@ #ifndef CREATURELIB_DEFINES_HPP #define CREATURELIB_DEFINES_HPP -typedef uint8_t level_int_t; +using level_int_t = int; #endif // CREATURELIB_DEFINES_HPP diff --git a/src/Library/CreatureData/SpeciesVariant.cpp b/src/Library/CreatureData/SpeciesVariant.cpp index 98f2639..510b693 100644 --- a/src/Library/CreatureData/SpeciesVariant.cpp +++ b/src/Library/CreatureData/SpeciesVariant.cpp @@ -16,12 +16,12 @@ namespace CreatureLib::Library { public: impl(const ArbUt::StringView& name, float height, float weight, uint32_t baseExperience, - const ArbUt::List& types, Library::StatisticSet baseStats, - const ArbUt::List& talents, const ArbUt::List& secretTalents, + ArbUt::List types, Library::StatisticSet baseStats, + ArbUt::List talents, ArbUt::List secretTalents, const LearnableAttacks* attacks, std::unordered_set flags) - : _name(name), _height(height), _weight(weight), _baseExperience(baseExperience), _types((types)), - _baseStatistics(baseStats), _talents(talents), _secretTalents(secretTalents), _attacks(attacks), - _flags(flags){}; + : _name(name), _height(height), _weight(weight), _baseExperience(baseExperience), + _types(std::move((types))), _baseStatistics(baseStats), _talents(std::move(talents)), + _secretTalents(std::move(secretTalents)), _attacks(attacks), _flags(std::move(flags)){}; inline const ArbUt::StringView& GetName() const { return _name; } inline float GetHeight() const { return _height; } @@ -39,13 +39,15 @@ namespace CreatureLib::Library { [[nodiscard]] const ArbUt::StringView& GetTalent(const TalentIndex& index) const { if (index.IsSecret() && _secretTalents.Count() > 0) { auto i = index.GetIndex(); - if (i > _secretTalents.Count()) + if (i > _secretTalents.Count()) { i = _secretTalents.Count(); + } return _secretTalents.At(i); } auto i = index.GetIndex(); - if (i > _talents.Count()) + if (i > _talents.Count()) { i = _talents.Count(); + } return _talents.At(i); } [[nodiscard]] TalentIndex GetTalentIndex(const ArbUt::StringView& talent) const { diff --git a/src/Library/CreatureData/SpeciesVariant.hpp b/src/Library/CreatureData/SpeciesVariant.hpp index 696ef3e..d1d086d 100644 --- a/src/Library/CreatureData/SpeciesVariant.hpp +++ b/src/Library/CreatureData/SpeciesVariant.hpp @@ -12,8 +12,6 @@ namespace CreatureLib::Library { struct impl; std::unique_ptr _impl; - protected: - private: public: /// @brief Instantiate SpeciesVariant. /// @param name The unique name of the variant. diff --git a/src/Library/CreatureData/TalentIndex.hpp b/src/Library/CreatureData/TalentIndex.hpp index e13438d..34f9d1b 100644 --- a/src/Library/CreatureData/TalentIndex.hpp +++ b/src/Library/CreatureData/TalentIndex.hpp @@ -2,15 +2,25 @@ #define CREATURELIB_TALENTINDEX_HPP namespace CreatureLib::Library { + /// @brief Stores the index of a talent on a creature. Defines whether or not the talent is secret, and what it's + /// index is. class TalentIndex { - bool _secret; - uint8_t _index; - public: - inline TalentIndex() noexcept : _secret(false), _index(0){}; + inline TalentIndex() noexcept : _index(0){}; + /// @brief Initialises a Talent Index from whether or not this is a secret talent, and it's index. + /// @param secret Whether or not this is a secret talent. + /// @param index The index of the talent on the species variant. inline TalentIndex(bool secret, uint8_t index) noexcept : _secret(secret), _index(index) {} - constexpr inline bool IsSecret() const noexcept { return _secret; } - constexpr inline bool GetIndex() const noexcept { return _index; } + /// @brief Returns whether or not this is a secret talent. + /// @return Whether or not this is a secret talent. + [[nodiscard]] constexpr inline bool IsSecret() const noexcept { return _secret; } + /// @brief Returns the index of the talent on the species variant. + /// @return The index of the talent on the species variant. + [[nodiscard]] constexpr inline uint8_t GetIndex() const noexcept { return _index; } + + private: + bool _secret = false; + uint8_t _index; }; }