mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Add cppcoreguidelines-special-member-functions clang-tidy check
Fix the warnings it emits. The GameCache copy constructor and assignment operator has also had its use of locks fixed.
This commit is contained in:
+2
-1
@@ -509,7 +509,8 @@ if(RUN_CLANG_TIDY)
|
||||
${CLANG_TIDY_COMMON_CHECKS}
|
||||
"cppcoreguidelines-avoid-goto"
|
||||
"cppcoreguidelines-avoid-magic-numbers"
|
||||
"cppcoreguidelines-non-private-member-variables-in-classes")
|
||||
"cppcoreguidelines-non-private-member-variables-in-classes"
|
||||
"cppcoreguidelines-special-member-functions")
|
||||
|
||||
# Skip some checks for tests because they're not worth the noise (e.g. GTest
|
||||
# happens to use goto).
|
||||
|
||||
@@ -37,18 +37,23 @@ namespace loot {
|
||||
GameCache::GameCache() {}
|
||||
|
||||
GameCache::GameCache(const GameCache& cache) {
|
||||
lock_guard<mutex> lock(mutex_);
|
||||
lock_guard<mutex> otherLock(cache.mutex_);
|
||||
lock_guard<mutex> lock(cache.mutex_);
|
||||
|
||||
plugins_ = cache.plugins_;
|
||||
archivePaths_ = cache.archivePaths_;
|
||||
}
|
||||
|
||||
GameCache& GameCache::operator=(const GameCache& cache) {
|
||||
lock_guard<mutex> lock(mutex_);
|
||||
lock_guard<mutex> otherLock(cache.mutex_);
|
||||
GameCache::GameCache(GameCache&& cache) {
|
||||
lock_guard<mutex> lock(cache.mutex_);
|
||||
|
||||
plugins_ = std::move(cache.plugins_);
|
||||
archivePaths_ = std::move(cache.archivePaths_);
|
||||
}
|
||||
|
||||
GameCache& GameCache::operator=(const GameCache& cache) {
|
||||
if (&cache != this) {
|
||||
std::scoped_lock lock(mutex_, cache.mutex_);
|
||||
|
||||
plugins_ = cache.plugins_;
|
||||
archivePaths_ = cache.archivePaths_;
|
||||
}
|
||||
@@ -56,6 +61,17 @@ GameCache& GameCache::operator=(const GameCache& cache) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
GameCache& GameCache::operator=(GameCache&& cache) {
|
||||
if (&cache != this) {
|
||||
std::scoped_lock lock(mutex_, cache.mutex_);
|
||||
|
||||
plugins_ = std::move(cache.plugins_);
|
||||
archivePaths_ = std::move(cache.archivePaths_);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<const Plugin>> GameCache::GetPlugins() const {
|
||||
lock_guard<mutex> lock(mutex_);
|
||||
|
||||
|
||||
@@ -35,9 +35,12 @@ namespace loot {
|
||||
class GameCache {
|
||||
public:
|
||||
explicit GameCache();
|
||||
explicit GameCache(const GameCache& cache);
|
||||
GameCache(const GameCache& cache);
|
||||
GameCache(GameCache&& cache);
|
||||
~GameCache() = default;
|
||||
|
||||
GameCache& operator=(const GameCache& cache);
|
||||
GameCache& operator=(GameCache&& cache);
|
||||
|
||||
std::vector<std::shared_ptr<const Plugin>> GetPlugins() const;
|
||||
std::shared_ptr<const Plugin> GetPlugin(const std::string& pluginName) const;
|
||||
|
||||
@@ -57,8 +57,23 @@ unsigned int mapGameId(GameType gameType) {
|
||||
|
||||
LoadOrderHandler::LoadOrderHandler() : gh_(nullptr) {}
|
||||
|
||||
LoadOrderHandler::LoadOrderHandler(LoadOrderHandler&& other) : gh_(other.gh_) {
|
||||
other.gh_ = nullptr;
|
||||
}
|
||||
|
||||
LoadOrderHandler::~LoadOrderHandler() { lo_destroy_handle(gh_); }
|
||||
|
||||
LoadOrderHandler& LoadOrderHandler::operator=(LoadOrderHandler&& other) {
|
||||
if (&other != this) {
|
||||
lo_destroy_handle(gh_);
|
||||
|
||||
gh_ = other.gh_;
|
||||
other.gh_ = nullptr;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void LoadOrderHandler::Init(const GameType& gameType,
|
||||
const std::filesystem::path& gamePath,
|
||||
const std::filesystem::path& gameLocalAppData) {
|
||||
|
||||
@@ -38,8 +38,13 @@ namespace loot {
|
||||
class LoadOrderHandler {
|
||||
public:
|
||||
explicit LoadOrderHandler();
|
||||
LoadOrderHandler(const LoadOrderHandler&) = delete;
|
||||
LoadOrderHandler(LoadOrderHandler&& other);
|
||||
~LoadOrderHandler();
|
||||
|
||||
LoadOrderHandler& operator=(const LoadOrderHandler&) = delete;
|
||||
LoadOrderHandler& operator=(LoadOrderHandler&& other);
|
||||
|
||||
void Init(const GameType& game,
|
||||
const std::filesystem::path& gamePath,
|
||||
const std::filesystem::path& gameLocalAppData = "");
|
||||
|
||||
Reference in New Issue
Block a user