mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 16:15:43 +00:00
Change ZCG cpp to be able to handle multiple tasks
This commit is contained in:
parent
22b95e337a
commit
21440daf27
@ -45,8 +45,8 @@ class ZoneCodeGenerator::Impl
|
|||||||
|
|
||||||
void PrintData() const
|
void PrintData() const
|
||||||
{
|
{
|
||||||
PrettyPrinter prettyPrinter;
|
const PrettyPrinter prettyPrinter(std::cout, m_repository.get());
|
||||||
prettyPrinter.Print(m_repository.get());
|
prettyPrinter.PrintAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GenerateCode()
|
bool GenerateCode()
|
||||||
@ -73,20 +73,19 @@ public:
|
|||||||
|
|
||||||
if (!ReadHeaderData() || !ReadCommandsData())
|
if (!ReadHeaderData() || !ReadCommandsData())
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
switch(m_args.m_task)
|
if(m_args.ShouldPrint())
|
||||||
{
|
{
|
||||||
case ZoneCodeGeneratorArguments::ProcessingTask::PRINT_DATA:
|
|
||||||
PrintData();
|
PrintData();
|
||||||
return 0;
|
|
||||||
|
|
||||||
case ZoneCodeGeneratorArguments::ProcessingTask::GENERATE_CODE:
|
|
||||||
return GenerateCode() ? 0 : 1;
|
|
||||||
|
|
||||||
default:
|
|
||||||
std::cout << "Unknown task: " << static_cast<int>(m_args.m_task) << std::endl;
|
|
||||||
return 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(m_args.ShouldGenerate())
|
||||||
|
{
|
||||||
|
if (!GenerateCode())
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -94,10 +94,10 @@ ZoneCodeGeneratorArguments::GenerationTask::GenerationTask(std::string assetName
|
|||||||
}
|
}
|
||||||
|
|
||||||
ZoneCodeGeneratorArguments::ZoneCodeGeneratorArguments()
|
ZoneCodeGeneratorArguments::ZoneCodeGeneratorArguments()
|
||||||
: m_argument_parser(COMMAND_LINE_OPTIONS, _countof(COMMAND_LINE_OPTIONS))
|
: m_argument_parser(COMMAND_LINE_OPTIONS, _countof(COMMAND_LINE_OPTIONS)),
|
||||||
|
m_task_flags(0)
|
||||||
{
|
{
|
||||||
m_verbose = false;
|
m_verbose = false;
|
||||||
m_task = ProcessingTask::GENERATE_CODE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZoneCodeGeneratorArguments::PrintUsage()
|
void ZoneCodeGeneratorArguments::PrintUsage()
|
||||||
@ -132,7 +132,7 @@ bool ZoneCodeGeneratorArguments::Parse(const int argc, const char** argv)
|
|||||||
|
|
||||||
// -p; --print
|
// -p; --print
|
||||||
if (m_argument_parser.IsOptionSpecified(OPTION_PRINT))
|
if (m_argument_parser.IsOptionSpecified(OPTION_PRINT))
|
||||||
m_task = ProcessingTask::PRINT_DATA;
|
m_task_flags |= FLAG_TASK_PRINT;
|
||||||
|
|
||||||
// -o; --output
|
// -o; --output
|
||||||
if (m_argument_parser.IsOptionSpecified(OPTION_OUTPUT_FOLDER))
|
if (m_argument_parser.IsOptionSpecified(OPTION_OUTPUT_FOLDER))
|
||||||
@ -164,25 +164,30 @@ bool ZoneCodeGeneratorArguments::Parse(const int argc, const char** argv)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_task == ProcessingTask::GENERATE_CODE)
|
if (m_argument_parser.IsOptionSpecified(OPTION_GENERATE))
|
||||||
{
|
{
|
||||||
if (!m_argument_parser.IsOptionSpecified(OPTION_GENERATE))
|
m_task_flags |= FLAG_TASK_GENERATE;
|
||||||
{
|
|
||||||
std::cout << "A generate parameter needs to be specified when generating code" << std::endl;
|
|
||||||
PrintUsage();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto generateParameterValues = m_argument_parser.GetParametersForOption(OPTION_GENERATE);
|
const auto generateParameterValues = m_argument_parser.GetParametersForOption(OPTION_GENERATE);
|
||||||
for (auto i = 0u; i < generateParameterValues.size(); i+=2)
|
for (auto i = 0u; i < generateParameterValues.size(); i += 2)
|
||||||
m_generation_tasks.emplace_back(generateParameterValues[i], generateParameterValues[i + 1]);
|
m_generation_tasks.emplace_back(generateParameterValues[i], generateParameterValues[i + 1]);
|
||||||
}
|
}
|
||||||
else if (m_argument_parser.IsOptionSpecified(OPTION_GENERATE))
|
|
||||||
|
if (m_task_flags == 0)
|
||||||
{
|
{
|
||||||
std::cout << "Cannot specify generate parameter when not generating code" << std::endl;
|
std::cout << "There was no output task specified." << std::endl;
|
||||||
PrintUsage();
|
PrintUsage();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ZoneCodeGeneratorArguments::ShouldGenerate() const
|
||||||
|
{
|
||||||
|
return m_task_flags & FLAG_TASK_GENERATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ZoneCodeGeneratorArguments::ShouldPrint() const
|
||||||
|
{
|
||||||
|
return m_task_flags & FLAG_TASK_PRINT;
|
||||||
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "Utils/ClassUtils.h"
|
||||||
#include "Utils/Arguments/ArgumentParser.h"
|
#include "Utils/Arguments/ArgumentParser.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -13,11 +15,8 @@ class ZoneCodeGeneratorArguments
|
|||||||
static void PrintUsage();
|
static void PrintUsage();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum class ProcessingTask
|
static constexpr unsigned FLAG_TASK_GENERATE = 1 << 0;
|
||||||
{
|
static constexpr unsigned FLAG_TASK_PRINT = 1 << 1;
|
||||||
GENERATE_CODE,
|
|
||||||
PRINT_DATA
|
|
||||||
};
|
|
||||||
|
|
||||||
class GenerationTask
|
class GenerationTask
|
||||||
{
|
{
|
||||||
@ -35,10 +34,13 @@ 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;
|
||||||
|
|
||||||
ProcessingTask m_task;
|
unsigned m_task_flags;
|
||||||
std::vector<GenerationTask> m_generation_tasks;
|
std::vector<GenerationTask> m_generation_tasks;
|
||||||
|
|
||||||
ZoneCodeGeneratorArguments();
|
ZoneCodeGeneratorArguments();
|
||||||
|
|
||||||
bool Parse(int argc, const char** argv);
|
bool Parse(int argc, const char** argv);
|
||||||
|
|
||||||
|
_NODISCARD bool ShouldGenerate() const;
|
||||||
|
_NODISCARD bool ShouldPrint() const;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user