ShatteredPrism/launcher/Usable.h
Reider745 60234a550b
Some checks failed
CodeQL Code Scanning / CodeQL (push) Has been cancelled
Build Application / Build Debug (push) Has been cancelled
Nix / Build (${{ matrix.system }}) (macos-13, x86_64-darwin) (push) Has been cancelled
Nix / Build (${{ matrix.system }}) (macos-14, aarch64-darwin) (push) Has been cancelled
Nix / Build (${{ matrix.system }}) (ubuntu-22.04, x86_64-linux) (push) Has been cancelled
Nix / Build (${{ matrix.system }}) (ubuntu-22.04-arm, aarch64-linux) (push) Has been cancelled
Update Flake Lockfile / update-flake (push) Has been cancelled
feat: auto install modpack & choise nickname
2025-04-15 11:13:45 +03:00

49 lines
1.0 KiB
C++
Executable File

#pragma once
#include <cstddef>
#include <memory>
#include "QObjectPtr.h"
class Usable;
/**
* Base class for things that can be used by multiple other things and we want to track the use count.
*
* @see UseLock
*/
class Usable {
friend class UseLock;
public:
virtual ~Usable() {}
std::size_t useCount() const { return m_useCount; }
bool isInUse() const { return m_useCount > 0; }
protected:
virtual void decrementUses() { m_useCount--; }
virtual void incrementUses() { m_useCount++; }
private:
std::size_t m_useCount = 0;
};
/**
* Lock class to use for keeping track of uses of other things derived from Usable
*
* @see Usable
*/
class UseLock {
public:
UseLock(shared_qobject_ptr<Usable> usable) : m_usable(usable)
{
// this doesn't use shared pointer use count, because that wouldn't be correct. this count is separate.
m_usable->incrementUses();
}
~UseLock() { m_usable->decrementUses(); }
private:
shared_qobject_ptr<Usable> m_usable;
};