initial commit for github

This commit is contained in:
Pierre 2019-12-12 14:41:47 +01:00
commit 60968612de
370 changed files with 68427 additions and 0 deletions

View file

@ -0,0 +1,30 @@
set(PROJECT_NAME header2ddl)
set(SOURCES
main.cpp
header2ddl_commandline.h
header2ddl_commandline.cpp
${DDL_GENERATOR_COMMON}
${HEADER_PRESENTATION_H}
${HEADER_PRESENTATION_CPP}
)
if (WIN32)
#list(APPEND SOURCES native_resource.rc)
endif (WIN32)
add_executable(${PROJECT_NAME} WIN32 ${SOURCES})
target_link_libraries(${PROJECT_NAME}
ddl
ddl_generator
)
if(MSVC)
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "/SUBSYSTEM:console")
endif(MSVC)
install(TARGETS ${PROJECT_NAME} DESTINATION ./bin/debug CONFIGURATIONS Debug)
install(TARGETS ${PROJECT_NAME} DESTINATION ./bin CONFIGURATIONS Release RelWithDebInfo)
set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER ddl/utils)

View file

@ -0,0 +1,82 @@
/**
* @file
*
* @copyright
* @verbatim
Copyright @ 2017 Audi Electronics Venture GmbH. All rights reserved.
This Source Code Form is subject to the terms of the Mozilla
Public License, v. 2.0. If a copy of the MPL was not distributed
with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
If it is not possible or desirable to put the notice in a particular file, then
You may include the notice in a location (such as a LICENSE file in a
relevant directory) where a recipient would be likely to look for such a notice.
You may add additional accurate notices of copyright ownership.
@endverbatim
*/
#include <iostream>
#include "header2ddl_commandline.h"
namespace ddl_generator
{
namespace oo
{
//define all needed error types and values locally
_MAKE_RESULT(0, ERR_NOERROR)
_MAKE_RESULT(-5, ERR_INVALID_ARG)
}
}
using namespace ddl_generator::oo;
namespace ddl
{
Header2DDLCommandLine::Header2DDLCommandLine() : CommandLine()
{
_cli |= getDDLVersionOpt();
_cli |= getHeaderFileSetOpt();
}
ddl::DDLVersion Header2DDLCommandLine::getDDLVersion()
{
return DDLVersion::fromString(_opt_DDL_version);
}
std::string Header2DDLCommandLine::getHeaderFileSet()
{
return _opt_header_file_set;
}
void Header2DDLCommandLine::setHeaderFile(std::string header_file)
{
_opt_header_file = header_file;
}
void Header2DDLCommandLine::printExamples()
{
std::cout << "examples: " << std::endl;
std::cout << " --headerfile=c:/myHeaderFile.h " <<
"--descriptionfile=c:/myDescriptionFile.description";
std::cout << std::endl << " or" << std::endl;
std::cout << " --headerfile=c:/myHeaderFile.h " <<
"--descriptionfile=c:/myDescriptionFile.description ";
std::cout << "-struct=tMyStruct" << std::endl;
}
clara::Opt Header2DDLCommandLine::getDDLVersionOpt()
{
return clara::Opt(_opt_DDL_version, "version")
["-v"]["--ddlversion"]
("[Optional] Default value is 4.0. Supported formats are 3.0 and 4.0");
}
clara::Opt Header2DDLCommandLine::getHeaderFileSetOpt()
{
return clara::Opt(_opt_header_file_set, "list,of,files")
["--headerfileset"]
("Can be used instead of the headerfile option. List of comma separated "
"headerfiles (no spaces!) to be merged into a single descriptionfile.");
}
}

View file

@ -0,0 +1,49 @@
/**
* @file
*
* @copyright
* @verbatim
Copyright @ 2017 Audi Electronics Venture GmbH. All rights reserved.
This Source Code Form is subject to the terms of the Mozilla
Public License, v. 2.0. If a copy of the MPL was not distributed
with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
If it is not possible or desirable to put the notice in a particular file, then
You may include the notice in a location (such as a LICENSE file in a
relevant directory) where a recipient would be likely to look for such a notice.
You may add additional accurate notices of copyright ownership.
@endverbatim
*/
#ifndef _HEADER2DDL_COMMAND_LINE_H_
#define _HEADER2DDL_COMMAND_LINE_H_
#include <ddl.h>
#include "commandline.h"
namespace ddl
{
class Header2DDLCommandLine : public ddl::CommandLine
{
public:
Header2DDLCommandLine();
DDLVersion getDDLVersion();
std::string getHeaderFileSet();
void setHeaderFile(std::string headerFile);
protected:
void printExamples() override;
clara::Opt getDDLVersionOpt();
clara::Opt getHeaderFileSetOpt();
std::string _opt_DDL_version = "4.0";
std::string _opt_header_file_set;
};
}
#endif

View file

@ -0,0 +1,110 @@
/**
* @file
* Launcher
*
* @copyright
* @verbatim
Copyright @ 2017 Audi Electronics Venture GmbH. All rights reserved.
This Source Code Form is subject to the terms of the Mozilla
Public License, v. 2.0. If a copy of the MPL was not distributed
with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
If it is not possible or desirable to put the notice in a particular file, then
You may include the notice in a location (such as a LICENSE file in a
relevant directory) where a recipient would be likely to look for such a notice.
You may add additional accurate notices of copyright ownership.
@endverbatim
*/
#include <iostream>
#include <ddl_generator_core.h>
#include "header2ddl_commandline.h"
namespace ddl_generator
{
namespace oo
{
//define all needed error types and values locally
_MAKE_RESULT(0, ERR_NOERROR)
_MAKE_RESULT(-5, ERR_INVALID_ARG)
}
}
using namespace ddl_generator::oo;
a_util::result::Result HandleInputFileset(std::string strHeaderFileSet, std::string& strMergedHeaderFile)
{
std::vector<std::string> vecHeaderFiles = a_util::strings::split(strHeaderFileSet, ",");
if (vecHeaderFiles.size() == 0)
{
LOG_ERROR("ERROR: Empty header file list");
return ERR_INVALID_ARG.getCode();
}
std::string strMergedHeaderContent;
for (std::string strHeaderpath : vecHeaderFiles)
{
std::string strHeaderContent;
if (!a_util::filesystem::exists(strHeaderpath) || a_util::result::isFailed(a_util::filesystem::readTextFile(strHeaderpath, strHeaderContent)))
{
LOG_ERROR(a_util::strings::format("ERROR: Could not read header file '%s'", strHeaderpath.c_str()).c_str());
return ERR_INVALID_ARG.getCode();
}
strMergedHeaderContent.append(strHeaderContent);
}
a_util::filesystem::Path mergedHeader = a_util::filesystem::getTempDirectory().append("MergedHeader.h");
a_util::filesystem::writeTextFile(mergedHeader, strMergedHeaderContent);
strMergedHeaderFile = mergedHeader.toString();
return ERR_NOERROR.getCode();
}
int main(int argc, char* argv[])
{
ddl::Header2DDLCommandLine cmd_line;
if (a_util::result::isFailed(cmd_line.parseArgs(argc, argv)))
{
return ERR_INVALID_ARG.getCode();
}
if (cmd_line.isHelpRequested())
{
cmd_line.printHelp();
return ERR_NOERROR.getCode();
}
std::string strMergedHeader;
if (!cmd_line.getHeaderFileSet().empty())
{
a_util::result::Result res = HandleInputFileset(cmd_line.getHeaderFileSet(), strMergedHeader);
if (a_util::result::isFailed(res))
{
return res.getErrorCode();
}
cmd_line.setHeaderFile(strMergedHeader);
}
if (a_util::result::isFailed(cmd_line.checkMandatoryArguments()))
{
return ERR_INVALID_ARG.getCode();
}
DDLUtilsCore core;
a_util::result::Result res = core.generateDescriptionFile(cmd_line.getHeaderFile(),
cmd_line.getDescriptionFile(), cmd_line.getDDLVersion(), cmd_line.getStruct());
if (a_util::result::isFailed(res))
{
std::cerr << "Error: An error occured during generating of the description file.";
}
// delete temp file
if (!strMergedHeader.empty())
{
a_util::filesystem::remove(strMergedHeader);
}
return res.getErrorCode();
}