mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-22 00:55:45 +00:00
chore: update code style in ZoneCodeGenerator entrypoint
This commit is contained in:
parent
ab21b7adc4
commit
3e58ddd2ad
@ -2,6 +2,6 @@
|
||||
|
||||
int main(const int argc, const char** argv)
|
||||
{
|
||||
const ZoneCodeGenerator zoneCodeGenerator;
|
||||
return zoneCodeGenerator.Run(argc, argv);
|
||||
auto zoneCodeGenerator = ZoneCodeGenerator::Create();
|
||||
return zoneCodeGenerator->Run(argc, argv);
|
||||
}
|
||||
|
@ -13,11 +13,39 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class ZoneCodeGenerator::Impl
|
||||
class ZoneCodeGeneratorImpl : public ZoneCodeGenerator
|
||||
{
|
||||
ZoneCodeGeneratorArguments m_args;
|
||||
std::unique_ptr<IDataRepository> m_repository;
|
||||
public:
|
||||
ZoneCodeGeneratorImpl()
|
||||
: m_repository(std::make_unique<InMemoryRepository>())
|
||||
{
|
||||
}
|
||||
|
||||
int Run(const int argc, const char** argv) override
|
||||
{
|
||||
auto shouldContinue = true;
|
||||
if (!m_args.ParseArgs(argc, argv, shouldContinue))
|
||||
return 1;
|
||||
|
||||
if (!shouldContinue)
|
||||
return 0;
|
||||
|
||||
if (!ReadHeaderData() || !ReadCommandsData())
|
||||
return 1;
|
||||
|
||||
if (m_args.ShouldPrint())
|
||||
PrintData();
|
||||
|
||||
if (m_args.ShouldGenerate())
|
||||
{
|
||||
if (!GenerateCode())
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private:
|
||||
bool ReadHeaderData()
|
||||
{
|
||||
for (const auto& headerFile : m_args.m_header_paths)
|
||||
@ -56,51 +84,11 @@ class ZoneCodeGenerator::Impl
|
||||
return codeGenerator.GenerateCode(m_repository.get());
|
||||
}
|
||||
|
||||
public:
|
||||
Impl()
|
||||
{
|
||||
m_repository = std::make_unique<InMemoryRepository>();
|
||||
}
|
||||
|
||||
int Run(const int argc, const char** argv)
|
||||
{
|
||||
auto shouldContinue = true;
|
||||
if (!m_args.ParseArgs(argc, argv, shouldContinue))
|
||||
return 1;
|
||||
|
||||
if (!shouldContinue)
|
||||
return 0;
|
||||
|
||||
if (!ReadHeaderData() || !ReadCommandsData())
|
||||
return 1;
|
||||
|
||||
if (m_args.ShouldPrint())
|
||||
{
|
||||
PrintData();
|
||||
}
|
||||
|
||||
if (m_args.ShouldGenerate())
|
||||
{
|
||||
if (!GenerateCode())
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
ZoneCodeGeneratorArguments m_args;
|
||||
std::unique_ptr<IDataRepository> m_repository;
|
||||
};
|
||||
|
||||
ZoneCodeGenerator::ZoneCodeGenerator()
|
||||
std::unique_ptr<ZoneCodeGenerator> ZoneCodeGenerator::Create()
|
||||
{
|
||||
m_impl = new Impl();
|
||||
}
|
||||
|
||||
ZoneCodeGenerator::~ZoneCodeGenerator()
|
||||
{
|
||||
delete m_impl;
|
||||
m_impl = nullptr;
|
||||
}
|
||||
|
||||
int ZoneCodeGenerator::Run(const int argc, const char** argv) const
|
||||
{
|
||||
return m_impl->Run(argc, argv);
|
||||
return std::make_unique<ZoneCodeGeneratorImpl>();
|
||||
}
|
||||
|
@ -1,17 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
class ZoneCodeGenerator
|
||||
{
|
||||
class Impl;
|
||||
Impl* m_impl;
|
||||
protected:
|
||||
ZoneCodeGenerator() = default;
|
||||
|
||||
public:
|
||||
ZoneCodeGenerator();
|
||||
~ZoneCodeGenerator();
|
||||
ZoneCodeGenerator(const ZoneCodeGenerator& other) = delete;
|
||||
ZoneCodeGenerator(ZoneCodeGenerator&& other) noexcept = default;
|
||||
ZoneCodeGenerator& operator=(const ZoneCodeGenerator& other) = delete;
|
||||
ZoneCodeGenerator& operator=(ZoneCodeGenerator&& other) noexcept = default;
|
||||
virtual ~ZoneCodeGenerator() = default;
|
||||
virtual int Run(int argc, const char** argv) = 0;
|
||||
|
||||
int Run(int argc, const char** argv) const;
|
||||
static std::unique_ptr<ZoneCodeGenerator> Create();
|
||||
};
|
||||
|
@ -93,18 +93,24 @@ const CommandLineOption* const COMMAND_LINE_OPTIONS[]{
|
||||
OPTION_GENERATE,
|
||||
};
|
||||
|
||||
ZoneCodeGeneratorArguments::GenerationTask::GenerationTask()
|
||||
namespace
|
||||
{
|
||||
static constexpr unsigned FLAG_TASK_GENERATE = 1 << 0;
|
||||
static constexpr unsigned FLAG_TASK_PRINT = 1 << 1;
|
||||
} // namespace
|
||||
|
||||
GenerationTask::GenerationTask()
|
||||
: m_all_assets(false)
|
||||
{
|
||||
}
|
||||
|
||||
ZoneCodeGeneratorArguments::GenerationTask::GenerationTask(std::string templateName)
|
||||
GenerationTask::GenerationTask(std::string templateName)
|
||||
: m_all_assets(true),
|
||||
m_template_name(std::move(templateName))
|
||||
{
|
||||
}
|
||||
|
||||
ZoneCodeGeneratorArguments::GenerationTask::GenerationTask(std::string assetName, std::string templateName)
|
||||
GenerationTask::GenerationTask(std::string assetName, std::string templateName)
|
||||
: m_all_assets(false),
|
||||
m_asset_name(std::move(assetName)),
|
||||
m_template_name(std::move(templateName))
|
||||
@ -113,7 +119,7 @@ ZoneCodeGeneratorArguments::GenerationTask::GenerationTask(std::string assetName
|
||||
|
||||
ZoneCodeGeneratorArguments::ZoneCodeGeneratorArguments()
|
||||
: m_argument_parser(COMMAND_LINE_OPTIONS, std::extent_v<decltype(COMMAND_LINE_OPTIONS)>),
|
||||
m_task_flags(0)
|
||||
m_task_flags(0u)
|
||||
{
|
||||
m_verbose = false;
|
||||
}
|
||||
@ -123,9 +129,7 @@ void ZoneCodeGeneratorArguments::PrintUsage() const
|
||||
UsageInformation usage(m_argument_parser.GetExecutableName());
|
||||
|
||||
for (const auto* commandLineOption : COMMAND_LINE_OPTIONS)
|
||||
{
|
||||
usage.AddCommandLineOption(commandLineOption);
|
||||
}
|
||||
|
||||
usage.Print();
|
||||
}
|
||||
|
@ -1,35 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include "Utils/Arguments/ArgumentParser.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class GenerationTask
|
||||
{
|
||||
public:
|
||||
bool m_all_assets;
|
||||
std::string m_asset_name;
|
||||
std::string m_template_name;
|
||||
|
||||
GenerationTask();
|
||||
explicit GenerationTask(std::string templateName);
|
||||
GenerationTask(std::string assetName, std::string templateName);
|
||||
};
|
||||
|
||||
class ZoneCodeGeneratorArguments
|
||||
{
|
||||
ArgumentParser m_argument_parser;
|
||||
|
||||
/**
|
||||
* \brief Prints a command line usage help text for the Unlinker tool to stdout.
|
||||
*/
|
||||
void PrintUsage() const;
|
||||
static void PrintVersion();
|
||||
|
||||
public:
|
||||
static constexpr unsigned FLAG_TASK_GENERATE = 1 << 0;
|
||||
static constexpr unsigned FLAG_TASK_PRINT = 1 << 1;
|
||||
ZoneCodeGeneratorArguments();
|
||||
bool ParseArgs(int argc, const char** argv, bool& shouldContinue);
|
||||
|
||||
class GenerationTask
|
||||
{
|
||||
public:
|
||||
bool m_all_assets;
|
||||
std::string m_asset_name;
|
||||
std::string m_template_name;
|
||||
|
||||
GenerationTask();
|
||||
explicit GenerationTask(std::string templateName);
|
||||
GenerationTask(std::string assetName, std::string templateName);
|
||||
};
|
||||
[[nodiscard]] bool ShouldGenerate() const;
|
||||
[[nodiscard]] bool ShouldPrint() const;
|
||||
|
||||
bool m_verbose;
|
||||
|
||||
@ -37,12 +32,12 @@ public:
|
||||
std::vector<std::string> m_command_paths;
|
||||
std::string m_output_directory;
|
||||
|
||||
unsigned m_task_flags;
|
||||
std::vector<GenerationTask> m_generation_tasks;
|
||||
|
||||
ZoneCodeGeneratorArguments();
|
||||
bool ParseArgs(int argc, const char** argv, bool& shouldContinue);
|
||||
private:
|
||||
void PrintUsage() const;
|
||||
static void PrintVersion();
|
||||
|
||||
_NODISCARD bool ShouldGenerate() const;
|
||||
_NODISCARD bool ShouldPrint() const;
|
||||
ArgumentParser m_argument_parser;
|
||||
unsigned m_task_flags;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user