From 10905b90c8935569f787573167a990a1d7c227d2 Mon Sep 17 00:00:00 2001 From: xglook Date: Sun, 14 Dec 2025 18:02:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8vs2022=EF=BC=8Cc++17=20=E4=B8=8A?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E9=80=9A=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmake/Config.cmake | 13 ++++++++++ deprecated/eo/src/utils/eoRNG.h | 5 +++- eo/src/do/make_checkpoint.h | 2 -- eo/src/es/CMAState.cpp | 5 ++-- eo/src/utils/eoRNG.h | 7 +++++- eo/src/utils/eoSignal.h | 42 +++++++++++++++++++++++++++++++-- 6 files changed, 66 insertions(+), 8 deletions(-) diff --git a/cmake/Config.cmake b/cmake/Config.cmake index 02593bac3..945b8e134 100644 --- a/cmake/Config.cmake +++ b/cmake/Config.cmake @@ -42,6 +42,19 @@ if(SMP) add_definitions(-D_GLIBCXX_USE_NANOSLEEP) endif(SMP) +###################################################################################### +### MSVC specific compiler options +###################################################################################### + +if(MSVC) + # Add /Zc:__cplusplus compiler option to enable correct __cplusplus macro + add_compile_options(/Zc:__cplusplus) + # Add utf8 + add_compile_options(/utf-8) + # Add HAVE_UINT32_T=1 preprocessor definition + add_definitions(-DHAVE_UINT32_T=1) +endif(MSVC) + ###################################################################################### ### 1) Define installation type ###################################################################################### diff --git a/deprecated/eo/src/utils/eoRNG.h b/deprecated/eo/src/utils/eoRNG.h index 984e76271..4e6d33dab 100644 --- a/deprecated/eo/src/utils/eoRNG.h +++ b/deprecated/eo/src/utils/eoRNG.h @@ -1,4 +1,4 @@ -/** Random number generator adapted from (see comments below) +/** Random number generator adapted from (see comments below) The random number generator is modified into a class by Maarten Keijzer (mak@dhi.dk). Also added the Box-Muller @@ -37,7 +37,10 @@ Old contact information: todos@geneura.ugr.es, http://geneura.ugr.es optimization levels so feel free to try your options and see what's best for you. */ +#if HAVE_UINT32_T typedef unsigned long uint32_t; +#endif // HAVE_UINT32_T + #else #if (! defined __sun) // The C99-standard defines uint32_t to be declared in stdint.h, but some diff --git a/eo/src/do/make_checkpoint.h b/eo/src/do/make_checkpoint.h index 2c2385524..d508845cb 100644 --- a/eo/src/do/make_checkpoint.h +++ b/eo/src/do/make_checkpoint.h @@ -63,7 +63,6 @@ eoCheckPoint& do_make_checkpoint(eoParser& _parser, eoState& _state, eoValu // Signal monitoring //////////////////// -#ifndef _MSC_VER // the CtrlC monitoring interception eoSignal *mon_ctrlCCont = nullptr; eoValueParam& mon_ctrlCParam = _parser.createParam(false, "monitor-with-CtrlC", "Monitor current generation upon Ctrl C",0, "Stopping criterion"); @@ -75,7 +74,6 @@ eoCheckPoint& do_make_checkpoint(eoParser& _parser, eoState& _state, eoValu // add to checkpoint checkpoint->add(*mon_ctrlCCont); } -#endif /////////////////// // Counters diff --git a/eo/src/es/CMAState.cpp b/eo/src/es/CMAState.cpp index 897b32f0f..2ff025cac 100644 --- a/eo/src/es/CMAState.cpp +++ b/eo/src/es/CMAState.cpp @@ -1,4 +1,4 @@ -/* +/* * C++ification of Nikolaus Hansen's original C-source code for the * CMA-ES * @@ -66,7 +66,8 @@ using namespace std; namespace eo { -struct CMAStateImpl { +class CMAStateImpl { + public: CMAParams p; diff --git a/eo/src/utils/eoRNG.h b/eo/src/utils/eoRNG.h index e91c6af5f..5131de597 100644 --- a/eo/src/utils/eoRNG.h +++ b/eo/src/utils/eoRNG.h @@ -1,4 +1,4 @@ -/** Random number generator adapted from (see comments below) +/** Random number generator adapted from (see comments below) The random number generator is modified into a class by Maarten Keijzer (mak@dhi.dk). Also added the Box-Muller @@ -37,7 +37,12 @@ Old contact information: todos@geneura.ugr.es, http://geneura.ugr.es optimization levels so feel free to try your options and see what's best for you. */ +#if HAVE_UINT32_T +#include +#else typedef unsigned long uint32_t; +#endif // HAVE_UINT32_T + #else #if (! defined __sun) // The C99-standard defines uint32_t to be declared in stdint.h, but some diff --git a/eo/src/utils/eoSignal.h b/eo/src/utils/eoSignal.h index c9f7ecf57..228b3c1b3 100644 --- a/eo/src/utils/eoSignal.h +++ b/eo/src/utils/eoSignal.h @@ -33,6 +33,11 @@ #include #include +#ifdef _WINDOWS +#define NOMINMAX +#include +#endif // _WINDOWS + /** * @addtogroup Continuators * @{ @@ -40,6 +45,25 @@ extern std::map< int, bool > signals_called; +#ifdef _WINDOWS +// Windows console control handler - process level handler +// Returns TRUE if the signal was handled, FALSE otherwise +inline BOOL WINAPI ConsoleCtrlHandler(DWORD dwCtrlType) +{ + if (dwCtrlType == CTRL_C_EVENT || dwCtrlType == CTRL_BREAK_EVENT) + { + // Map Windows control event to SIGINT for compatibility + ::signals_called[SIGINT] = true; + eo::log << eo::logging << "Signal wished…" << std::endl; + return TRUE; // Signal handled, don't terminate the process + } + return FALSE; +} + +// Track if console handler is already installed +static bool console_handler_installed = false; +#endif // _WINDOWS + /** eoSignal inherits from eoCheckPoint including signals handling (see signal(7)) * * @ingroup Utilities @@ -53,7 +77,14 @@ public : { ::signals_called[_sig] = false; -#ifndef _WINDOWS +#ifdef _WINDOWS + // Install Windows console control handler (only once per process) + if (!console_handler_installed) + { + SetConsoleCtrlHandler(ConsoleCtrlHandler, TRUE); + console_handler_installed = true; + } +#else #ifdef SIGQUIT ::signal( _sig, handler ); #endif // !SIGQUIT @@ -64,7 +95,14 @@ public : { ::signals_called[_sig] = false; -#ifndef _WINDOWS +#ifdef _WINDOWS + // Install Windows console control handler (only once per process) + if (!console_handler_installed) + { + SetConsoleCtrlHandler(ConsoleCtrlHandler, TRUE); + console_handler_installed = true; + } +#else #ifdef SIGQUIT ::signal( _sig, handler ); #endif // !SIGQUIT