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)
|
int main(const int argc, const char** argv)
|
||||||
{
|
{
|
||||||
const ZoneCodeGenerator zoneCodeGenerator;
|
auto zoneCodeGenerator = ZoneCodeGenerator::Create();
|
||||||
return zoneCodeGenerator.Run(argc, argv);
|
return zoneCodeGenerator->Run(argc, argv);
|
||||||
}
|
}
|
||||||
|
@ -13,11 +13,39 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class ZoneCodeGenerator::Impl
|
class ZoneCodeGeneratorImpl : public ZoneCodeGenerator
|
||||||
{
|
{
|
||||||
ZoneCodeGeneratorArguments m_args;
|
public:
|
||||||
std::unique_ptr<IDataRepository> m_repository;
|
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()
|
bool ReadHeaderData()
|
||||||
{
|
{
|
||||||
for (const auto& headerFile : m_args.m_header_paths)
|
for (const auto& headerFile : m_args.m_header_paths)
|
||||||
@ -56,51 +84,11 @@ class ZoneCodeGenerator::Impl
|
|||||||
return codeGenerator.GenerateCode(m_repository.get());
|
return codeGenerator.GenerateCode(m_repository.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
ZoneCodeGeneratorArguments m_args;
|
||||||
Impl()
|
std::unique_ptr<IDataRepository> m_repository;
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ZoneCodeGenerator::ZoneCodeGenerator()
|
std::unique_ptr<ZoneCodeGenerator> ZoneCodeGenerator::Create()
|
||||||
{
|
{
|
||||||
m_impl = new Impl();
|
return std::make_unique<ZoneCodeGeneratorImpl>();
|
||||||
}
|
|
||||||
|
|
||||||
ZoneCodeGenerator::~ZoneCodeGenerator()
|
|
||||||
{
|
|
||||||
delete m_impl;
|
|
||||||
m_impl = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ZoneCodeGenerator::Run(const int argc, const char** argv) const
|
|
||||||
{
|
|
||||||
return m_impl->Run(argc, argv);
|
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
class ZoneCodeGenerator
|
class ZoneCodeGenerator
|
||||||
{
|
{
|
||||||
class Impl;
|
protected:
|
||||||
Impl* m_impl;
|
ZoneCodeGenerator() = default;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ZoneCodeGenerator();
|
virtual ~ZoneCodeGenerator() = default;
|
||||||
~ZoneCodeGenerator();
|
virtual int Run(int argc, const char** argv) = 0;
|
||||||
ZoneCodeGenerator(const ZoneCodeGenerator& other) = delete;
|
|
||||||
ZoneCodeGenerator(ZoneCodeGenerator&& other) noexcept = default;
|
|
||||||
ZoneCodeGenerator& operator=(const ZoneCodeGenerator& other) = delete;
|
|
||||||
ZoneCodeGenerator& operator=(ZoneCodeGenerator&& other) noexcept = default;
|
|
||||||
|
|
||||||
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,
|
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)
|
: m_all_assets(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ZoneCodeGeneratorArguments::GenerationTask::GenerationTask(std::string templateName)
|
GenerationTask::GenerationTask(std::string templateName)
|
||||||
: m_all_assets(true),
|
: m_all_assets(true),
|
||||||
m_template_name(std::move(templateName))
|
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_all_assets(false),
|
||||||
m_asset_name(std::move(assetName)),
|
m_asset_name(std::move(assetName)),
|
||||||
m_template_name(std::move(templateName))
|
m_template_name(std::move(templateName))
|
||||||
@ -113,7 +119,7 @@ ZoneCodeGeneratorArguments::GenerationTask::GenerationTask(std::string assetName
|
|||||||
|
|
||||||
ZoneCodeGeneratorArguments::ZoneCodeGeneratorArguments()
|
ZoneCodeGeneratorArguments::ZoneCodeGeneratorArguments()
|
||||||
: m_argument_parser(COMMAND_LINE_OPTIONS, std::extent_v<decltype(COMMAND_LINE_OPTIONS)>),
|
: m_argument_parser(COMMAND_LINE_OPTIONS, std::extent_v<decltype(COMMAND_LINE_OPTIONS)>),
|
||||||
m_task_flags(0)
|
m_task_flags(0u)
|
||||||
{
|
{
|
||||||
m_verbose = false;
|
m_verbose = false;
|
||||||
}
|
}
|
||||||
@ -123,9 +129,7 @@ void ZoneCodeGeneratorArguments::PrintUsage() const
|
|||||||
UsageInformation usage(m_argument_parser.GetExecutableName());
|
UsageInformation usage(m_argument_parser.GetExecutableName());
|
||||||
|
|
||||||
for (const auto* commandLineOption : COMMAND_LINE_OPTIONS)
|
for (const auto* commandLineOption : COMMAND_LINE_OPTIONS)
|
||||||
{
|
|
||||||
usage.AddCommandLineOption(commandLineOption);
|
usage.AddCommandLineOption(commandLineOption);
|
||||||
}
|
|
||||||
|
|
||||||
usage.Print();
|
usage.Print();
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Utils/Arguments/ArgumentParser.h"
|
#include "Utils/Arguments/ArgumentParser.h"
|
||||||
#include "Utils/ClassUtils.h"
|
|
||||||
|
|
||||||
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class ZoneCodeGeneratorArguments
|
class GenerationTask
|
||||||
{
|
{
|
||||||
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:
|
public:
|
||||||
static constexpr unsigned FLAG_TASK_GENERATE = 1 << 0;
|
|
||||||
static constexpr unsigned FLAG_TASK_PRINT = 1 << 1;
|
|
||||||
|
|
||||||
class GenerationTask
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bool m_all_assets;
|
bool m_all_assets;
|
||||||
std::string m_asset_name;
|
std::string m_asset_name;
|
||||||
std::string m_template_name;
|
std::string m_template_name;
|
||||||
@ -29,7 +15,16 @@ public:
|
|||||||
GenerationTask();
|
GenerationTask();
|
||||||
explicit GenerationTask(std::string templateName);
|
explicit GenerationTask(std::string templateName);
|
||||||
GenerationTask(std::string assetName, std::string templateName);
|
GenerationTask(std::string assetName, std::string templateName);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ZoneCodeGeneratorArguments
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ZoneCodeGeneratorArguments();
|
||||||
|
bool ParseArgs(int argc, const char** argv, bool& shouldContinue);
|
||||||
|
|
||||||
|
[[nodiscard]] bool ShouldGenerate() const;
|
||||||
|
[[nodiscard]] bool ShouldPrint() const;
|
||||||
|
|
||||||
bool m_verbose;
|
bool m_verbose;
|
||||||
|
|
||||||
@ -37,12 +32,12 @@ public:
|
|||||||
std::vector<std::string> m_command_paths;
|
std::vector<std::string> m_command_paths;
|
||||||
std::string m_output_directory;
|
std::string m_output_directory;
|
||||||
|
|
||||||
unsigned m_task_flags;
|
|
||||||
std::vector<GenerationTask> m_generation_tasks;
|
std::vector<GenerationTask> m_generation_tasks;
|
||||||
|
|
||||||
ZoneCodeGeneratorArguments();
|
private:
|
||||||
bool ParseArgs(int argc, const char** argv, bool& shouldContinue);
|
void PrintUsage() const;
|
||||||
|
static void PrintVersion();
|
||||||
|
|
||||||
_NODISCARD bool ShouldGenerate() const;
|
ArgumentParser m_argument_parser;
|
||||||
_NODISCARD bool ShouldPrint() const;
|
unsigned m_task_flags;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user