Unify singleton pattern in Profile class

1. Use unified function names `initInstance()` and `freeInstance()` and
make them public.
2. Add `freeInstance()` to avoid noise from memory leak detectors.
3. Let `instance()`return a pointer directly to avoid unnecessary
indirections when invoking functions.
This commit is contained in:
Chocobo1
2020-02-11 10:56:04 +08:00
parent 8b330e3ac0
commit 5de75eff05
9 changed files with 39 additions and 34 deletions

View File

@@ -36,8 +36,6 @@
class QString;
class Application;
namespace Private
{
class Profile;
@@ -57,6 +55,11 @@ enum class SpecialFolder
class Profile
{
public:
static void initInstance(const QString &rootProfilePath, const QString &configurationName,
bool convertPathsToProfileRelative);
static void freeInstance();
static const Profile *instance();
QString location(SpecialFolder folder) const;
SettingsPtr applicationSettings(const QString &name) const;
@@ -67,16 +70,11 @@ public:
QString toPortablePath(const QString &absolutePath) const;
QString fromPortablePath(const QString &portablePath) const;
static const Profile &instance();
private:
Profile(Private::Profile *impl, Private::PathConverter *pathConverter);
~Profile();
~Profile() = default; // to generate correct call to ProfilePrivate::~ProfileImpl()
friend class ::Application;
static void initialize(const QString &rootProfilePath, const QString &configurationName,
bool convertPathsToProfileRelative);
void ensureDirectoryExists(SpecialFolder folder);
void ensureDirectoryExists(SpecialFolder folder) const;
const std::unique_ptr<Private::Profile> m_profileImpl;
const std::unique_ptr<Private::PathConverter> m_pathConverterImpl;