mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-04-20 16:15:43 +00:00
Implement ZCG CPP workflow basis
This commit is contained in:
parent
c09c685369
commit
584492d1ef
@ -1,10 +0,0 @@
|
|||||||
#include "Session.h"
|
|
||||||
|
|
||||||
Session::Session()
|
|
||||||
= default;
|
|
||||||
|
|
||||||
Session::Session(ZoneCodeGeneratorArguments args)
|
|
||||||
: m_args(std::move(args))
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
@ -1,11 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "ZoneCodeGeneratorArguments.h"
|
|
||||||
|
|
||||||
class Session
|
|
||||||
{
|
|
||||||
ZoneCodeGeneratorArguments m_args;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Session();
|
|
||||||
explicit Session(ZoneCodeGeneratorArguments args);
|
|
||||||
};
|
|
@ -0,0 +1,15 @@
|
|||||||
|
#include "CommandsFileReader.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
CommandsFileReader::CommandsFileReader(const ZoneCodeGeneratorArguments* args, std::string filename)
|
||||||
|
: m_args(args),
|
||||||
|
m_filename(std::move(filename))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CommandsFileReader::ReadCommandsFile(IDataRepository* repository)
|
||||||
|
{
|
||||||
|
std::cout << "Reading commands file: " << m_filename << std::endl;
|
||||||
|
return true;
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "ZoneCodeGeneratorArguments.h"
|
||||||
|
#include "Persistence/IDataRepository.h"
|
||||||
|
|
||||||
|
class CommandsFileReader
|
||||||
|
{
|
||||||
|
const ZoneCodeGeneratorArguments* m_args;
|
||||||
|
std::string m_filename;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit CommandsFileReader(const ZoneCodeGeneratorArguments* args, std::string filename);
|
||||||
|
|
||||||
|
bool ReadCommandsFile(IDataRepository* repository);
|
||||||
|
};
|
15
src/ZoneCodeGeneratorNew/Parsing/Header/HeaderFileReader.cpp
Normal file
15
src/ZoneCodeGeneratorNew/Parsing/Header/HeaderFileReader.cpp
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include "HeaderFileReader.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
HeaderFileReader::HeaderFileReader(const ZoneCodeGeneratorArguments* args, std::string filename)
|
||||||
|
: m_args(args),
|
||||||
|
m_filename(std::move(filename))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HeaderFileReader::ReadHeaderFile(IDataRepository* repository)
|
||||||
|
{
|
||||||
|
std::cout << "Reading header file: " << m_filename << std::endl;
|
||||||
|
return true;
|
||||||
|
}
|
17
src/ZoneCodeGeneratorNew/Parsing/Header/HeaderFileReader.h
Normal file
17
src/ZoneCodeGeneratorNew/Parsing/Header/HeaderFileReader.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "ZoneCodeGeneratorArguments.h"
|
||||||
|
#include "Persistence/IDataRepository.h"
|
||||||
|
|
||||||
|
class HeaderFileReader
|
||||||
|
{
|
||||||
|
const ZoneCodeGeneratorArguments* m_args;
|
||||||
|
std::string m_filename;
|
||||||
|
|
||||||
|
public:
|
||||||
|
HeaderFileReader(const ZoneCodeGeneratorArguments* args, std::string filename);
|
||||||
|
|
||||||
|
bool ReadHeaderFile(IDataRepository* repository);
|
||||||
|
};
|
7
src/ZoneCodeGeneratorNew/Persistence/IDataRepository.h
Normal file
7
src/ZoneCodeGeneratorNew/Persistence/IDataRepository.h
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
class IDataRepository
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~IDataRepository() = default;
|
||||||
|
};
|
@ -0,0 +1 @@
|
|||||||
|
#include "InMemoryRepository.h"
|
@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Persistence/IDataRepository.h"
|
||||||
|
|
||||||
|
class InMemoryRepository final : public IDataRepository
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
};
|
8
src/ZoneCodeGeneratorNew/Printing/PrettyPrinter.cpp
Normal file
8
src/ZoneCodeGeneratorNew/Printing/PrettyPrinter.cpp
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#include "PrettyPrinter.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
void PrettyPrinter::Print(const IDataRepository* repository)
|
||||||
|
{
|
||||||
|
std::cout << "Pretty printing..." << std::endl;
|
||||||
|
}
|
8
src/ZoneCodeGeneratorNew/Printing/PrettyPrinter.h
Normal file
8
src/ZoneCodeGeneratorNew/Printing/PrettyPrinter.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "Persistence/IDataRepository.h"
|
||||||
|
|
||||||
|
class PrettyPrinter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void Print(const IDataRepository* repository);
|
||||||
|
};
|
107
src/ZoneCodeGeneratorNew/ZoneCodeGenerator.cpp
Normal file
107
src/ZoneCodeGeneratorNew/ZoneCodeGenerator.cpp
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
#include "ZoneCodeGenerator.h"
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "ZoneCodeGeneratorArguments.h"
|
||||||
|
#include "Parsing/Commands/CommandsFileReader.h"
|
||||||
|
#include "Parsing/Header/HeaderFileReader.h"
|
||||||
|
#include "Persistence/IDataRepository.h"
|
||||||
|
#include "Persistence/InMemory/InMemoryRepository.h"
|
||||||
|
#include "Printing/PrettyPrinter.h"
|
||||||
|
|
||||||
|
class ZoneCodeGenerator::Impl
|
||||||
|
{
|
||||||
|
ZoneCodeGeneratorArguments m_args;
|
||||||
|
std::unique_ptr<IDataRepository> m_repository;
|
||||||
|
|
||||||
|
bool ReadHeaderData()
|
||||||
|
{
|
||||||
|
for (const auto& headerFile : m_args.m_header_paths)
|
||||||
|
{
|
||||||
|
HeaderFileReader headerFileReader(&m_args, headerFile);
|
||||||
|
|
||||||
|
if (!headerFileReader.ReadHeaderFile(m_repository.get()))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ReadCommandsData()
|
||||||
|
{
|
||||||
|
for (const auto& commandsFile : m_args.m_command_paths)
|
||||||
|
{
|
||||||
|
CommandsFileReader commandsFileReader(&m_args, commandsFile);
|
||||||
|
|
||||||
|
if (!commandsFileReader.ReadCommandsFile(m_repository.get()))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrintData() const
|
||||||
|
{
|
||||||
|
PrettyPrinter prettyPrinter;
|
||||||
|
prettyPrinter.Print(m_repository.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GenerateCode()
|
||||||
|
{
|
||||||
|
for(const auto& generationTask : m_args.m_generation_tasks)
|
||||||
|
{
|
||||||
|
// TODO: Implement
|
||||||
|
std::cout << "Generating code for asset \"" << generationTask.m_asset_name << "\" and preset \"" << generationTask.m_preset_name << "\" ..." << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
Impl()
|
||||||
|
{
|
||||||
|
m_repository = std::make_unique<InMemoryRepository>();
|
||||||
|
}
|
||||||
|
|
||||||
|
int Run(const int argc, const char** argv)
|
||||||
|
{
|
||||||
|
if (!m_args.Parse(argc, argv))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (!ReadHeaderData() || !ReadCommandsData())
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
switch(m_args.m_task)
|
||||||
|
{
|
||||||
|
case ZoneCodeGeneratorArguments::ProcessingTask::PRINT_DATA:
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ZoneCodeGenerator::ZoneCodeGenerator()
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
17
src/ZoneCodeGeneratorNew/ZoneCodeGenerator.h
Normal file
17
src/ZoneCodeGeneratorNew/ZoneCodeGenerator.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
class ZoneCodeGenerator
|
||||||
|
{
|
||||||
|
class Impl;
|
||||||
|
Impl* m_impl;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
int Run(int argc, const char** argv) const;
|
||||||
|
};
|
@ -1,5 +1,7 @@
|
|||||||
#include "ZoneCodeGeneratorArguments.h"
|
#include "ZoneCodeGeneratorArguments.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include "Utils/Arguments/CommandLineOption.h"
|
#include "Utils/Arguments/CommandLineOption.h"
|
||||||
#include "Utils/Arguments/UsageInformation.h"
|
#include "Utils/Arguments/UsageInformation.h"
|
||||||
|
|
||||||
@ -21,26 +23,23 @@ const CommandLineOption* const OPTION_VERBOSE = CommandLineOption::Builder::Crea
|
|||||||
|
|
||||||
constexpr const char* CATEGORY_INPUT = "Input";
|
constexpr const char* CATEGORY_INPUT = "Input";
|
||||||
|
|
||||||
const CommandLineOption* const OPTION_CREATE = CommandLineOption::Builder::Create()
|
const CommandLineOption* const OPTION_HEADER = CommandLineOption::Builder::Create()
|
||||||
.WithShortName("h")
|
.WithShortName("h")
|
||||||
.WithLongName("header")
|
.WithLongName("header")
|
||||||
.WithDescription("Create a new database from the specified header file.")
|
.WithDescription("Reads from the specified header file.")
|
||||||
.WithCategory(CATEGORY_INPUT)
|
.WithCategory(CATEGORY_INPUT)
|
||||||
.WithParameter("headerFile")
|
.WithParameter("headerFile")
|
||||||
|
.Reusable()
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
// ------
|
const CommandLineOption* const OPTION_COMMANDS_FILE = CommandLineOption::Builder::Create()
|
||||||
// EDITING
|
.WithShortName("c")
|
||||||
// ------
|
.WithLongName("commands-file")
|
||||||
constexpr const char* CATEGORY_EDITING = "Editing";
|
.WithDescription("Specifies the commands file. Defaults to stdin.")
|
||||||
|
.WithCategory(CATEGORY_INPUT)
|
||||||
const CommandLineOption* const OPTION_EDITING_COMMANDS = CommandLineOption::Builder::Create()
|
.WithParameter("commandFile")
|
||||||
.WithShortName("e")
|
.Reusable()
|
||||||
.WithLongName("editing-commands")
|
.Build();
|
||||||
.WithDescription("Specifies the editing command file. Defaults to stdin.")
|
|
||||||
.WithCategory(CATEGORY_EDITING)
|
|
||||||
.WithParameter("commandFile")
|
|
||||||
.Build();
|
|
||||||
|
|
||||||
// ------
|
// ------
|
||||||
// OUTPUT
|
// OUTPUT
|
||||||
@ -65,7 +64,8 @@ const CommandLineOption* const OPTION_PRINT = CommandLineOption::Builder::Create
|
|||||||
const CommandLineOption* const OPTION_GENERATE = CommandLineOption::Builder::Create()
|
const CommandLineOption* const OPTION_GENERATE = CommandLineOption::Builder::Create()
|
||||||
.WithShortName("g")
|
.WithShortName("g")
|
||||||
.WithLongName("generate")
|
.WithLongName("generate")
|
||||||
.WithDescription("Generates a specified asset/preset combination. Can be used multiple times. Available presets: "
|
.WithDescription(
|
||||||
|
"Generates a specified asset/preset combination. Can be used multiple times. Available presets: "
|
||||||
"ZoneLoad, ZoneWrite, AssetStructTests")
|
"ZoneLoad, ZoneWrite, AssetStructTests")
|
||||||
.WithCategory(CATEGORY_OUTPUT)
|
.WithCategory(CATEGORY_OUTPUT)
|
||||||
.WithParameter("assetName")
|
.WithParameter("assetName")
|
||||||
@ -77,8 +77,8 @@ const CommandLineOption* const COMMAND_LINE_OPTIONS[]
|
|||||||
{
|
{
|
||||||
OPTION_HELP,
|
OPTION_HELP,
|
||||||
OPTION_VERBOSE,
|
OPTION_VERBOSE,
|
||||||
OPTION_CREATE,
|
OPTION_HEADER,
|
||||||
OPTION_EDITING_COMMANDS,
|
OPTION_COMMANDS_FILE,
|
||||||
OPTION_OUTPUT_FOLDER,
|
OPTION_OUTPUT_FOLDER,
|
||||||
OPTION_PRINT,
|
OPTION_PRINT,
|
||||||
OPTION_GENERATE
|
OPTION_GENERATE
|
||||||
@ -137,32 +137,49 @@ bool ZoneCodeGeneratorArguments::Parse(const int argc, const char** argv)
|
|||||||
// -o; --output
|
// -o; --output
|
||||||
if (m_argument_parser.IsOptionSpecified(OPTION_OUTPUT_FOLDER))
|
if (m_argument_parser.IsOptionSpecified(OPTION_OUTPUT_FOLDER))
|
||||||
m_output_directory = m_argument_parser.GetValueForOption(OPTION_OUTPUT_FOLDER);
|
m_output_directory = m_argument_parser.GetValueForOption(OPTION_OUTPUT_FOLDER);
|
||||||
|
else
|
||||||
|
m_output_directory = ".";
|
||||||
|
|
||||||
// -h; --header
|
// -h; --header
|
||||||
if (m_argument_parser.IsOptionSpecified(OPTION_CREATE))
|
if (m_argument_parser.IsOptionSpecified(OPTION_HEADER))
|
||||||
m_header_path = m_argument_parser.GetValueForOption(OPTION_CREATE);
|
{
|
||||||
|
for (const auto& arg : m_argument_parser.GetParametersForOption(OPTION_HEADER))
|
||||||
|
m_header_paths.push_back(arg);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "At least one header file must be specified via -h / --header." << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// -e; --editing-commands
|
// -c; --commands-file
|
||||||
if (m_argument_parser.IsOptionSpecified(OPTION_EDITING_COMMANDS))
|
if (m_argument_parser.IsOptionSpecified(OPTION_COMMANDS_FILE))
|
||||||
m_commands_path = m_argument_parser.GetValueForOption(OPTION_EDITING_COMMANDS);
|
{
|
||||||
|
for (const auto& arg : m_argument_parser.GetParametersForOption(OPTION_COMMANDS_FILE))
|
||||||
|
m_command_paths.push_back(arg);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "At least one commands file must be specified via -c / --commands-file." << std::endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_task == ProcessingTask::GENERATE_CODE)
|
if (m_task == ProcessingTask::GENERATE_CODE)
|
||||||
{
|
{
|
||||||
if (!m_argument_parser.IsOptionSpecified(OPTION_GENERATE))
|
if (!m_argument_parser.IsOptionSpecified(OPTION_GENERATE))
|
||||||
{
|
{
|
||||||
printf("A generate parameter needs to be specified when generating code\n");
|
std::cout << "A generate parameter needs to be specified when generating code" << std::endl;
|
||||||
PrintUsage();
|
PrintUsage();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto generateParameterValues = m_argument_parser.GetParametersForOption(OPTION_GENERATE);
|
const auto generateParameterValues = m_argument_parser.GetParametersForOption(OPTION_GENERATE);
|
||||||
const auto generateCount = generateParameterValues.size() / 2;
|
for (auto i = 0u; i < generateParameterValues.size(); i+=2)
|
||||||
for(auto i = 0u; i < generateCount; i++)
|
|
||||||
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))
|
else if (m_argument_parser.IsOptionSpecified(OPTION_GENERATE))
|
||||||
{
|
{
|
||||||
printf("Cannot specify generate parameter when not generating code\n");
|
std::cout << "Cannot specify generate parameter when not generating code" << std::endl;
|
||||||
PrintUsage();
|
PrintUsage();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
@ -31,8 +31,8 @@ public:
|
|||||||
|
|
||||||
bool m_verbose;
|
bool m_verbose;
|
||||||
|
|
||||||
std::string m_header_path;
|
std::vector<std::string> m_header_paths;
|
||||||
std::string m_commands_path;
|
std::vector<std::string> m_command_paths;
|
||||||
std::string m_output_directory;
|
std::string m_output_directory;
|
||||||
|
|
||||||
ProcessingTask m_task;
|
ProcessingTask m_task;
|
@ -1,18 +1,7 @@
|
|||||||
#include <cstdio>
|
#include "ZoneCodeGenerator.h"
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include "Interface/Session.h"
|
|
||||||
#include "Interface/ZoneCodeGeneratorArguments.h"
|
|
||||||
|
|
||||||
int main(const int argc, const char** argv)
|
int main(const int argc, const char** argv)
|
||||||
{
|
{
|
||||||
ZoneCodeGeneratorArguments args;
|
const ZoneCodeGenerator zoneCodeGenerator;
|
||||||
|
return zoneCodeGenerator.Run(argc, argv);
|
||||||
if(!args.Parse(argc, argv))
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
Session session(args);
|
|
||||||
|
|
||||||
const std::string asdf = "Hello World";
|
|
||||||
printf("%s\n", asdf.c_str());
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user