Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Deakon997 committed Oct 21, 2021
2 parents c86fab5 + c574bd5 commit 54132b2
Show file tree
Hide file tree
Showing 35 changed files with 3,599 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ int main(int argc, char** argv)
}
catch (std::exception& e)
{
(void) e;
result = 1;
}
return result;
Expand Down
2 changes: 1 addition & 1 deletion cpp/applications/indexerTester/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ add_custom_command( TARGET ${PROJECT_NAME} POST_BUILD
################################################################
# Visual Studio solution settings
if( MSVC )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4251" ) # ${osc_extra_static_compile_flags}" )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4251 /utf-8 /we4828" ) # ${osc_extra_static_compile_flags}" )
set_target_properties( ${PROJECT_NAME} PROPERTIES FOLDER Apps )
set_target_properties( ${PROJECT_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/$(Configuration)" )
endif()
3 changes: 2 additions & 1 deletion cpp/applications/openScenarioReader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/src )
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../../common )
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../../externalLibs/TinyXML2 )
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../../externalLibs/Filesystem )
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../../externalLibs/UtfCpp )


include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../../openScenarioLib/src/v1_0/checker )
Expand Down Expand Up @@ -173,7 +174,7 @@ target_link_libraries( ${PROJECT_NAME} OpenScenarioLib )
################################################################
# Visual Studio solution settings
if( MSVC )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" ) # ${osc_extra_static_compile_flags}" )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8 /we4828" ) # ${osc_extra_static_compile_flags}" )
set_target_properties( ${PROJECT_NAME} PROPERTIES FOLDER Apps )
set_target_properties(
${PROJECT_NAME} PROPERTIES
Expand Down
197 changes: 170 additions & 27 deletions cpp/applications/openScenarioReader/src/OpenScenarioReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,23 @@ int CheckFile(std::string& inputFileName, std::string& paramFileName, std::strin
{
try
{

#ifdef WIN32
std::wstring wparamFileName;

if (!NET_ASAM_OPENSCENARIO::FileResourceLocator::Utf8ToWstring(paramFileName, wparamFileName))
{
auto msg = "Conversion from utf8 string to wstring failed: " + paramFileName;
return ERROR_RESULT;
}

std::ifstream paramFile(wparamFileName);
#elif defined (__linux__) || defined (__APPLE__)
std::ifstream paramFile(paramFileName);
#else
# error "Operating system not supported."
#endif

std::string line;

if (paramFile.bad() || paramFile.fail())
Expand Down Expand Up @@ -158,7 +174,22 @@ int CheckFile(std::string& inputFileName, std::string& paramFileName, std::strin
if (result == ERROR_RESULT)
return result;

#ifdef WIN32
std::wstring winputFileName;

if (!NET_ASAM_OPENSCENARIO::FileResourceLocator::Utf8ToWstring(inputFileName, winputFileName))
{
auto msg = "Conversion from utf8 string to wstring failed: " + inputFileName;
return ERROR_RESULT;
}
std::ifstream inputFile(winputFileName);

#elif defined (__linux__) || defined (__APPLE__)
std::ifstream inputFile(inputFileName);
#else
# error "Operating system not supported."
#endif


if (inputFile.bad() || inputFile.fail())
{
Expand All @@ -175,13 +206,13 @@ int CheckFile(std::string& inputFileName, std::string& paramFileName, std::strin

try
{
if (version == VERSION_1_1)
{
ExecuteImportParsingV1_1(inputFileName, messageLogger, catalogMessageLogger, injectedParamters);
} else
{
ExecuteImportParsing(inputFileName, messageLogger, catalogMessageLogger, injectedParamters);
}
if (version == VERSION_1_1)
{
ExecuteImportParsingV1_1(inputFileName, messageLogger, catalogMessageLogger, injectedParamters);
} else
{
ExecuteImportParsing(inputFileName, messageLogger, catalogMessageLogger, injectedParamters);
}

for (auto&& message : messageLogger->GetMessagesFilteredByWorseOrEqualToErrorLevel(logLevel))
{
Expand Down Expand Up @@ -225,9 +256,13 @@ int CheckFile(std::string& inputFileName, std::string& paramFileName, std::strin
return result;
}

int main(int argc, char** argv)
#ifdef WIN32
int wmain(int argc, wchar_t** argv)
{
#if defined(_DEBUG) && defined(WIN32)
SetConsoleOutputCP(CP_UTF8);
setvbuf(stdout, nullptr, _IOFBF, 1000);

#if defined(_DEBUG)
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif

Expand All @@ -249,7 +284,109 @@ int main(int argc, char** argv)
std::string inputFileName;
std::string paramFileName;
std::string inputDirectoryName;
std::string version = VERSION_1_0;
std::string version = VERSION_1_0;

if (argc > 1 && std::wstring(argv[1]) == L"-v")
{
std::cout << "Program version " << kVersion << std::endl;
return VERSION_RESULT;
}

if (argc > 2 && (std::wstring(argv[1]) == L"-i" || std::wstring(argv[1]) == L"-d"))
{
if (std::wstring(argv[1]) == L"-i")
{
if (!NET_ASAM_OPENSCENARIO::FileResourceLocator::WstringToUtf8(argv[2], inputFileName))
{
std::cout << "wstring to string conversion failed: inputFileName " << std::endl;
return ERROR_RESULT;
}
}
else
{
if (!NET_ASAM_OPENSCENARIO::FileResourceLocator::WstringToUtf8(argv[2], inputDirectoryName))
{
std::cout << "wstring to string conversion failed: inputDirectoryName " << std::endl;
return ERROR_RESULT;
}
}

if (argc >= 5 && std::wstring(argv[3]) == L"-p")
{
if (!NET_ASAM_OPENSCENARIO::FileResourceLocator::WstringToUtf8(argv[4], paramFileName))
{
std::cout << "wstring to string conversion failed: paramFileName " << std::endl;
return ERROR_RESULT;
}
if (argc == 6 && std::wstring(argv[5]) == L"-v1_1")
{
version = VERSION_1_1;
}
}
else if (argc == 4 && std::wstring(argv[3]) == L"-v1_1")
{
version = VERSION_1_1;
}

isCommandLineParsable = true;
}

if (!isCommandLineParsable)
{
std::cout << "OpenScenarioChecker [[{-i <filename>|-d <dirname>} [-p <paramfilename>] [-v1_1]] | -v]" << std::endl;
std::cout << "Options:" << std::endl;
std::cout << "-i\t<filename> file to be validated" << std::endl;
std::cout << "-d\t<directory> directory to be validated" << std::endl;
std::cout << "-p\t<paramfilename> a file with name/value pairs. One line per name/value pair. tab separated" << std::endl;
std::cout << "-v1_1\tUse standard version 1.1" << std::endl;
std::cout << "-v\tprint program version" << std::endl;

return USAGE_RESULT;
}

if (!inputFileName.empty())
{
result = CheckFile(inputFileName, paramFileName, version);
}
else
{
try
{
NET_ASAM_OPENSCENARIO::FileResourceLocator fileLocator;
auto filePaths = fileLocator.GetSymbolicFilenamesInSymbolicDir(inputDirectoryName);
for (auto file : filePaths)
result = CheckFile(file, paramFileName) == SUCCESS_RESULT ? result : ERROR_RESULT;
}
catch (NET_ASAM_OPENSCENARIO::ResourceNotFoundException& e)
{
(void)e;
std::cout << "'" << inputDirectoryName << "' does not exists or is not a directory." << std::endl;
result = ERROR_RESULT;
}
}

return result;
}
#elif defined (__linux__) || defined (__APPLE__)
int main(int argc, char** argv)
{
std::stringstream versionStream;
versionStream << MAJORVERSION << "." << MINORVERSION << "." << PATCHNUMBER;
const std::string kVersion = versionStream.str();
const std::string kHeader = "* ASAM OpenSCENARIO 1.0 Checker (2020) *";
const std::string kHeaderFillString = GetFilledString(kHeader.length(), '*');

std::cout << kHeaderFillString << std::endl;
std::cout << kHeader << std::endl;
std::cout << kHeaderFillString << std::endl;

bool isCommandLineParsable = false;
int result = SUCCESS_RESULT;

std::string inputFileName;
std::string paramFileName;
std::string inputDirectoryName;
std::string version = VERSION_1_0;

if (argc > 1 && std::string(argv[1]) == "-v")
{
Expand All @@ -264,18 +401,19 @@ int main(int argc, char** argv)
else
inputDirectoryName = argv[2];

if (argc >= 5 && std::string(argv[3]) == "-p")
if (argc >= 5 && std::string(argv[3]) == "-p")
{
paramFileName = argv[4];
if (argc == 6 && std::string(argv[5]) == "-v1_1")
{
version = VERSION_1_1;
}
}else if (argc == 4 && std::string(argv[3]) == "-v1_1")
{
version = VERSION_1_1;
}

if (argc == 6 && std::string(argv[5]) == "-v1_1")
{
version = VERSION_1_1;
}
}
else if (argc == 4 && std::string(argv[3]) == "-v1_1")
{
version = VERSION_1_1;
}

isCommandLineParsable = true;
}

Expand All @@ -284,10 +422,10 @@ int main(int argc, char** argv)
std::cout << "OpenScenarioChecker [[{-i <filename>|-d <dirname>} [-p <paramfilename>] [-v1_1]] | -v]" << std::endl;
std::cout << "Options:" << std::endl;
std::cout << "-i\t<filename> file to be validated" << std::endl;
std::cout << "-d\t<directory> directory to be validated" << std::endl;
std::cout << "-p\t<paramfilename> a file with name/value pairs. One line per name/value pair. tab separated" << std::endl;
std::cout << "-v1_1\tUse standard version 1.1" << std::endl;
std::cout << "-v\tprint program version" << std::endl;
std::cout << "-d\t<directory> directory to be validated" << std::endl;
std::cout << "-p\t<paramfilename> a file with name/value pairs. One line per name/value pair. tab separated" << std::endl;
std::cout << "-v1_1\tUse standard version 1.1" << std::endl;
std::cout << "-v\tprint program version" << std::endl;

return USAGE_RESULT;
}
Expand All @@ -302,16 +440,21 @@ int main(int argc, char** argv)
{
NET_ASAM_OPENSCENARIO::FileResourceLocator fileLocator;
auto filePaths = fileLocator.GetSymbolicFilenamesInSymbolicDir(inputDirectoryName);
for (auto file : filePaths)
for (auto file : filePaths)
result = CheckFile(file, paramFileName) == SUCCESS_RESULT ? result : ERROR_RESULT;
}
catch ( NET_ASAM_OPENSCENARIO::ResourceNotFoundException& e)
catch (NET_ASAM_OPENSCENARIO::ResourceNotFoundException& e)
{
(void)e;
std::cout << "'" << inputDirectoryName <<"' does not exists or is not a directory." << std::endl;
std::cout << "'" << inputDirectoryName << "' does not exists or is not a directory." << std::endl;
result = ERROR_RESULT;
}
}

return result;
}
#else
# error "Operating system not supported."
#endif


5 changes: 3 additions & 2 deletions cpp/applications/openScenarioTester/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/src/helper )
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../../common)
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../../externalLibs/TinyXML2 )
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../../externalLibs/Filesystem)
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../../externalLibs/UtfCpp )


include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../../openScenarioLib/src/v1_0/checker )
Expand Down Expand Up @@ -192,7 +193,7 @@ endif()

################################################################
# Generate executable
add_executable( ${PROJECT_NAME} ${SOURCES} ${SOURCES_HELPER}
add_executable( ${PROJECT_NAME} ${SOURCES} ${SOURCES_HELPER}
${RESOURCE_FILES} )

if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
Expand All @@ -217,7 +218,7 @@ add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
################################################################
# Visual Studio solution settings
if( MSVC )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj" ) # ${osc_extra_static_compile_flags}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj /utf-8 /we4828" ) # ${osc_extra_static_compile_flags}")
set_target_properties( ${PROJECT_NAME} PROPERTIES FOLDER Apps )
set_target_properties(
${PROJECT_NAME} PROPERTIES
Expand Down
Loading

0 comments on commit 54132b2

Please sign in to comment.