Update Linker and Unlinker tool to use virtual functions directly instead of internal impl pointer

This commit is contained in:
Jan 2023-06-19 21:15:43 +02:00
parent 3c2774614f
commit 0da6a4dc43
6 changed files with 38 additions and 67 deletions

View File

@ -40,7 +40,7 @@ const IZoneCreator* const ZONE_CREATORS[]
new T6::ZoneCreator()
};
class Linker::Impl
class LinkerImpl final : public Linker
{
static constexpr const char* METADATA_GAME = "game";
static constexpr const char* METADATA_GDT = "gdt";
@ -543,13 +543,7 @@ class Linker::Impl
}
public:
Impl()
= default;
/**
* \copydoc Linker::Start
*/
bool Start(const int argc, const char** argv)
bool Start(const int argc, const char** argv) override
{
if (!m_args.ParseArgs(argc, argv))
return false;
@ -576,18 +570,7 @@ public:
}
};
Linker::Linker()
std::unique_ptr<Linker> Linker::Create()
{
m_impl = new Impl();
}
Linker::~Linker()
{
delete m_impl;
m_impl = nullptr;
}
bool Linker::Start(const int argc, const char** argv) const
{
return m_impl->Start(argc, argv);
return std::make_unique<LinkerImpl>();
}

View File

@ -1,18 +1,19 @@
#pragma once
#include <memory>
class Linker
{
class Impl;
Impl* m_impl;
public:
Linker();
~Linker();
Linker() = default;
virtual ~Linker() = default;
Linker(const Linker& other) = delete;
Linker(Linker&& other) noexcept = delete;
Linker& operator=(const Linker& other) = delete;
Linker& operator=(Linker&& other) noexcept = delete;
Linker(const Linker& other) = default;
Linker(Linker&& other) noexcept = default;
Linker& operator=(const Linker& other) = default;
Linker& operator=(Linker&& other) noexcept = default;
static std::unique_ptr<Linker> Create();
/**
* \brief Starts the Linker application logic.
@ -20,5 +21,5 @@ public:
* \param argv The command line arguments.
* \return \c true if the application was successful or \c false if an error occurred.
*/
bool Start(int argc, const char** argv) const;
};
virtual bool Start(int argc, const char** argv) = 0;
};

View File

@ -2,7 +2,7 @@
int main(const int argc, const char** argv)
{
Linker linker;
const auto linker = Linker::Create();
return linker.Start(argc, argv) ? 0 : 1;
return linker->Start(argc, argv) ? 0 : 1;
}

View File

@ -34,7 +34,7 @@ const IZoneDefWriter* const ZONE_DEF_WRITERS[]
new T6::ZoneDefWriter()
};
class Unlinker::Impl
class UnlinkerImpl final : public Unlinker
{
UnlinkerArgs m_args;
SearchPaths m_search_paths;
@ -403,7 +403,7 @@ class Unlinker::Impl
if (ShouldLoadObj())
{
ObjLoading::LoadReferencedContainersForZone(&searchPathsForZone, zone.get());
ObjLoading::LoadObjDataForZone(&searchPathsForZone, zone.get());
ObjLoading::LoadObjDataForZone(&searchPathsForZone, zone.get());
}
if (!HandleZone(zone.get()))
@ -421,15 +421,12 @@ class Unlinker::Impl
}
public:
Impl()
UnlinkerImpl()
{
m_last_zone_search_path = nullptr;
}
/**
* \copydoc Unlinker::Start
*/
bool Start(const int argc, const char** argv)
bool Start(const int argc, const char** argv) override
{
if (!m_args.ParseArgs(argc, argv))
return false;
@ -447,18 +444,7 @@ public:
}
};
Unlinker::Unlinker()
std::unique_ptr<Unlinker> Unlinker::Create()
{
m_impl = new Impl();
}
Unlinker::~Unlinker()
{
delete m_impl;
m_impl = nullptr;
}
bool Unlinker::Start(const int argc, const char** argv) const
{
return m_impl->Start(argc, argv);
return std::make_unique<UnlinkerImpl>();
}

View File

@ -1,18 +1,19 @@
#pragma once
#include <memory>
class Unlinker
{
class Impl;
Impl* m_impl;
public:
Unlinker();
~Unlinker();
Unlinker() = default;
virtual ~Unlinker() = default;
Unlinker(const Unlinker& other) = delete;
Unlinker(Unlinker&& other) noexcept = delete;
Unlinker& operator=(const Unlinker& other) = delete;
Unlinker& operator=(Unlinker&& other) noexcept = delete;
Unlinker(const Unlinker& other) = default;
Unlinker(Unlinker&& other) noexcept = default;
Unlinker& operator=(const Unlinker& other) = default;
Unlinker& operator=(Unlinker&& other) noexcept = default;
static std::unique_ptr<Unlinker> Create();
/**
* \brief Starts the Unlinker application logic.
@ -20,5 +21,5 @@ public:
* \param argv The command line arguments.
* \return \c true if the application was successful or \c false if an error occurred.
*/
bool Start(int argc, const char** argv) const;
};
virtual bool Start(int argc, const char** argv) = 0;
};

View File

@ -2,7 +2,7 @@
int main(const int argc, const char** argv)
{
Unlinker unlinker;
const auto unlinker = Unlinker::Create();
return unlinker.Start(argc, argv) ? 0 : 1;
return unlinker->Start(argc, argv) ? 0 : 1;
}