-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove dependency to UI, use RAII to handle resources (#1678)
* Remove dependency to UI : removal from solver * Remove dependency to UI : calling the main arguments pre-processing from outside * Remove dependency to UI : removal from analyzer * Remove dependency to UI : replace the dependency to UI in other stand alone targets + correct new target include files paths * Remove dependency to UI : forgot to add header file to repository * Remove dependency to UI : introduce a RAII to automatically destroy the allocated memory * Add & use IntoUTF8ArgsTranslator::convert (#1684) * Add & use IntoUTF8ArgsTranslator::convert * Fix header inclusion * Fix windows build * Fix build * Fix build (bis) * Remove ref to argc, make IntoUTF8ArgsTranslator's API homogenous * Apply clang-format --------- Co-authored-by: Florian Omnès <[email protected]>
- Loading branch information
1 parent
3b8c7b7
commit c79f00e
Showing
25 changed files
with
122 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
|
||
OMESSAGE("Antares Core library") | ||
|
||
add_subdirectory(args) | ||
add_subdirectory(writer) | ||
add_subdirectory(memory) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
set(SRC_ARGS_HELPER | ||
include/antares/args/args_to_utf8.h | ||
args_to_utf8.cpp | ||
) | ||
|
||
source_group("misc\\args_helper" FILES ${SRC_ARGS_HELPER}) | ||
|
||
add_library(args_helper | ||
${SRC_ARGS_HELPER} | ||
) | ||
|
||
add_library(Antares::args_helper ALIAS args_helper) | ||
|
||
target_link_libraries(args_helper | ||
PRIVATE | ||
yuni-static-core | ||
) | ||
|
||
target_include_directories(args_helper | ||
PUBLIC | ||
${CMAKE_CURRENT_SOURCE_DIR}/include | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
#include <yuni/yuni.h> | ||
#include "antares/args/args_to_utf8.h" | ||
|
||
#ifdef YUNI_OS_WINDOWS | ||
#include <string.h> | ||
#include <cstdlib> | ||
#ifndef WIN32_LEAN_AND_MEAN | ||
#define WIN32_LEAN_AND_MEAN 1 | ||
#endif // WIN32_LEAN_AND_MEAN | ||
#include <windows.h> | ||
#include <shellapi.h> | ||
#endif // YUNI_OS_WINDOWS | ||
|
||
IntoUTF8ArgsTranslator::IntoUTF8ArgsTranslator(int argc, char** argv) : argc_(argc), argv_(argv) | ||
{ | ||
} | ||
|
||
std::pair<int, char**> IntoUTF8ArgsTranslator::convert() | ||
{ | ||
#ifdef YUNI_OS_WINDOWS | ||
wchar_t** wargv = CommandLineToArgvW(GetCommandLineW(), &argc_); | ||
argv_ = (char**)malloc(argc_ * sizeof(char*)); | ||
for (int i = 0; i != argc_; ++i) | ||
{ | ||
const uint len = (uint)wcslen(wargv[i]); | ||
const uint newLen = WideCharToMultiByte(CP_UTF8, 0, wargv[i], len, NULL, 0, NULL, NULL); | ||
argv_[i] = (char*)malloc((newLen + 1) * sizeof(char)); | ||
memset(argv_[i], 0, (newLen + 1) * sizeof(char)); | ||
WideCharToMultiByte(CP_UTF8, 0, wargv[i], len, argv_[i], newLen, NULL, NULL); | ||
argv_[i][newLen] = '\0'; | ||
} | ||
#endif | ||
return {argc_, argv_}; | ||
} | ||
|
||
IntoUTF8ArgsTranslator::~IntoUTF8ArgsTranslator() | ||
{ | ||
#ifdef YUNI_OS_WINDOWS | ||
for (int i = 0; i != argc_; ++i) | ||
free(argv_[i]); | ||
free(argv_); | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
|
||
#include <utility> | ||
|
||
class IntoUTF8ArgsTranslator | ||
{ | ||
public: | ||
IntoUTF8ArgsTranslator(int argc, char** argv); | ||
std::pair<int, char**> convert(); | ||
~IntoUTF8ArgsTranslator(); | ||
|
||
private: | ||
int argc_; | ||
char** argv_; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.