Some checks failed
Conan Packaging / Package Bin2CPP/1.0.0 (push) Has been cancelled
Bin2CPP / Build & Test Debug with ./ConanProfiles/clangd (Unity Build: OFF) (push) Has been cancelled
Bin2CPP / Build & Test Debug with ./ConanProfiles/clangd (Unity Build: ON) (push) Has been cancelled
Bin2CPP / Build & Test Debug with ./ConanProfiles/clangd_asan (Unity Build: OFF) (push) Has been cancelled
Bin2CPP / Build & Test Debug with ./ConanProfiles/clangd_asan (Unity Build: ON) (push) Has been cancelled
Bin2CPP / Build & Test RelWithDebInfo with ./ConanProfiles/clang (Unity Build: OFF) (push) Has been cancelled
Bin2CPP / Build & Test RelWithDebInfo with ./ConanProfiles/clang (Unity Build: ON) (push) Has been cancelled
Bin2CPP / Build & Test RelWithDebInfo with ./ConanProfiles/clangd (Unity Build: OFF) (push) Has been cancelled
Bin2CPP / Build & Test RelWithDebInfo with ./ConanProfiles/clangd (Unity Build: ON) (push) Has been cancelled
Bin2CPP / Build & Test RelWithDebInfo with ./ConanProfiles/clangd_asan (Unity Build: OFF) (push) Has been cancelled
Bin2CPP / Build & Test Release with ./ConanProfiles/clangd (Unity Build: ON) (push) Has been cancelled
Bin2CPP / Build & Test Release with ./ConanProfiles/clangd_asan (Unity Build: OFF) (push) Has been cancelled
Bin2CPP / Build & Test Debug with ./ConanProfiles/clang (Unity Build: ON) (push) Has been cancelled
Bin2CPP / Build & Test RelWithDebInfo with ./ConanProfiles/clangd_asan (Unity Build: ON) (push) Has been cancelled
Bin2CPP / Build & Test Release with ./ConanProfiles/clang (Unity Build: OFF) (push) Has been cancelled
Bin2CPP / Build & Test Release with ./ConanProfiles/clang (Unity Build: ON) (push) Has been cancelled
Bin2CPP / Build & Test Release with ./ConanProfiles/clangd (Unity Build: OFF) (push) Has been cancelled
Bin2CPP / Build & Test Release with ./ConanProfiles/clangd_asan (Unity Build: ON) (push) Has been cancelled
Bin2CPP / Clang Format Checks (push) Has been cancelled
Bin2CPP / Build & Test Debug with ./ConanProfiles/clang (Unity Build: OFF) (push) Has been cancelled
Bin2CPP / Sonarqube (push) Has been cancelled
Reviewed-on: #2 Co-authored-by: Romain BOULLARD <romain.boullard@protonmail.com> Co-committed-by: Romain BOULLARD <romain.boullard@protonmail.com>
158 lines
3.0 KiB
C++
158 lines
3.0 KiB
C++
/*********************************************************************
|
|
* \file Generator.hpp
|
|
*
|
|
* \author Romain BOULLARD
|
|
* \date February 2026
|
|
*********************************************************************/
|
|
#ifndef BIN2CPP_GENERATOR_HPP
|
|
#define BIN2CPP_GENERATOR_HPP
|
|
#include <magic_enum/magic_enum.hpp>
|
|
|
|
#include <array>
|
|
#include <span>
|
|
#include <string>
|
|
|
|
namespace Bin2CPP
|
|
{
|
|
enum class MappingKey
|
|
{
|
|
FILENAME,
|
|
GUARD_NAME,
|
|
NAMESPACE,
|
|
ARRAY_TYPE_INCLUDE,
|
|
ARRAY_TYPE,
|
|
ARRAY_SIZE,
|
|
ARRAY_NAME,
|
|
DATA
|
|
};
|
|
|
|
class Generator
|
|
{
|
|
public:
|
|
/**
|
|
* Constructor
|
|
*
|
|
* \param p_inputFile the Input file
|
|
*/
|
|
Generator(const std::string_view p_inputFile);
|
|
|
|
Generator(const Generator& p_generator) = default;
|
|
Generator(Generator&& p_generator) = default;
|
|
|
|
/**
|
|
* Set a mapping
|
|
*
|
|
*/
|
|
void SetMapping(const MappingKey p_key, const std::string_view p_value);
|
|
|
|
/**
|
|
* Generate
|
|
*
|
|
* \return True if successful, false otherwise
|
|
*/
|
|
[[nodiscard]]
|
|
bool Generate();
|
|
|
|
/**
|
|
* Get
|
|
*
|
|
*/
|
|
[[nodiscard]]
|
|
std::string_view Get() const;
|
|
|
|
~Generator() = default;
|
|
|
|
Generator& operator=(const Generator& p_generator) = default;
|
|
Generator& operator=(Generator&& p_generator) = default;
|
|
|
|
private:
|
|
/**
|
|
* Compute the mappings
|
|
*
|
|
* \return True if all mappings have valid values, false otherwise
|
|
*/
|
|
[[nodiscard]]
|
|
bool ComputeMappings();
|
|
|
|
/**
|
|
* Compute the filename mapping
|
|
*
|
|
* \return True if success, false otherwise
|
|
*/
|
|
[[nodiscard]]
|
|
bool ComputeFilename();
|
|
|
|
/**
|
|
* Compute the guardName mapping
|
|
*
|
|
* \return True if success, false otherwise
|
|
*/
|
|
[[nodiscard]]
|
|
bool ComputeGuardName();
|
|
|
|
/**
|
|
* Compute the arrayTypeInclude mapping
|
|
*
|
|
* \return True if success, false otherwise
|
|
*/
|
|
[[nodiscard]]
|
|
bool ComputeArrayTypeInclude();
|
|
|
|
/**
|
|
* Compute the arrayType mapping
|
|
*
|
|
* \return True if success, false otherwise
|
|
*/
|
|
[[nodiscard]]
|
|
bool ComputeArrayType();
|
|
|
|
/**
|
|
* Compute the arrayName mapping
|
|
*
|
|
* \return True if success, false otherwise
|
|
*/
|
|
[[nodiscard]]
|
|
bool ComputeArrayName();
|
|
|
|
/**
|
|
* Compute the arraySize mapping
|
|
*
|
|
* \return True if success, false otherwise
|
|
*/
|
|
[[nodiscard]]
|
|
bool ComputeArraySize(const std::span<std::byte> p_data);
|
|
|
|
/**
|
|
* Compute the data mapping
|
|
*
|
|
* \return True if success, false otherwise
|
|
*/
|
|
[[nodiscard]]
|
|
bool ComputeData(const std::span<std::byte> p_data);
|
|
|
|
/**
|
|
* Validate generated is correct (no remaining tags)
|
|
*
|
|
* \return True if valid, false otherwise
|
|
*/
|
|
[[nodiscard]]
|
|
bool Validate();
|
|
|
|
/**
|
|
* The mapping table
|
|
*/
|
|
std::array<std::string, magic_enum::enum_count<MappingKey>()> m_mappingTable;
|
|
|
|
/**
|
|
* The input file
|
|
*/
|
|
std::string m_inputFile;
|
|
|
|
/**
|
|
* The result
|
|
*/
|
|
std::string m_result;
|
|
};
|
|
} // namespace Bin2CPP
|
|
#endif
|