diff --git a/examples/dotnet/csintegerprogramming.cs b/examples/dotnet/csintegerprogramming.cs index 2e44b304e9..0f2e4b3740 100644 --- a/examples/dotnet/csintegerprogramming.cs +++ b/examples/dotnet/csintegerprogramming.cs @@ -12,6 +12,7 @@ // limitations under the License. using System; +using Google.OrTools.Init; using Google.OrTools.LinearSolver; public class CsIntegerProgramming @@ -100,7 +101,11 @@ public class CsIntegerProgramming static void Main() { - Google.OrTools.Init.Init.InitCppLogging("csintegerprogramming.cs", true, false); + CppBridge.InitLogging("csintegerprogramming.cs"); + CppFlags flags = new CppFlags(); + flags.logtostderr = true; + flags.log_prefix = false; + CppBridge.SetFlags(flags); Console.WriteLine("---- Integer programming example with GLPK ----"); RunIntegerProgrammingExample("GLPK"); diff --git a/examples/python/integer_programming.py b/examples/python/integer_programming.py index 3785a85669..1e39440953 100644 --- a/examples/python/integer_programming.py +++ b/examples/python/integer_programming.py @@ -116,7 +116,9 @@ def main(): if __name__ == '__main__': - init.Init.InitCppLogging('integer_programming.py', - /*logtostderr=*/True, - /*log_prefix=*/False); + init.CppBridge.InitLogging('integer_programming.py') + cpp_flags = init.CppFlags() + cpp_flags.logtostderr = True + cpp_flags.log_prefix = False + init.CppBridge.SetFlags(cpp_flags) main() diff --git a/ortools/init/csharp/init.i b/ortools/init/csharp/init.i index 7771003116..afdbdcf65b 100644 --- a/ortools/init/csharp/init.i +++ b/ortools/init/csharp/init.i @@ -10,9 +10,16 @@ %unignore operations_research; -%unignore operations_research::Init; -%unignore operations_research::Init::InitCppLogging; -%unignore operations_research::Init::LoadGurobiSharedLibrary; +// Expose the flags structure. +%unignore operations_research::CppFlags; +%unignore operations_research::CppFlags::logtostderr; +%unignore operations_research::CppFlags::log_prefix; + +// Expose the static methods of the bridge class. +%unignore operations_research::CppBridge; +%unignore operations_research::CppBridge::InitLogging; +%unignore operations_research::CppBridge::SetFlags; +%unignore operations_research::CppBridge::LoadGurobiSharedLibrary; %include "ortools/init/init.h" diff --git a/ortools/init/init.h b/ortools/init/init.h index a8e0266414..61c4336272 100644 --- a/ortools/init/init.h +++ b/ortools/init/init.h @@ -8,19 +8,25 @@ namespace operations_research { +struct CppFlags { + bool logtostderr = false; + bool log_prefix = false; +}; + // This class performs various C++ initialization. // It is meant to be used once at the start of a program. -class Init { +class CppBridge { public: // Initialize the C++ logging layer. - // If logtostderr is false, all C++ logging will be ignored. - // If true, all logging will the displayed on stderr. - static void InitCppLogging(const std::string& program_name, bool logtostderr, - bool log_prefix) { - absl::SetFlag(&FLAGS_logtostderr, logtostderr); - absl::SetFlag(&FLAGS_log_prefix, log_prefix); + static void InitLogging(const std::string& program_name) { google::InitGoogleLogging(program_name.c_str()); } + + // Sets all the C++ flags contained in the CppFlags structure. + static void SetFlags(const CppFlags& flags) { + absl::SetFlag(&FLAGS_logtostderr, flags.logtostderr); + absl::SetFlag(&FLAGS_log_prefix, flags.log_prefix); + } // Load the gurobi shared library. // This is necessary if the library is installed in a non canonical diff --git a/ortools/init/java/init.i b/ortools/init/java/init.i index 9820e630ba..3be6a92eba 100644 --- a/ortools/init/java/init.i +++ b/ortools/init/java/init.i @@ -10,9 +10,16 @@ %unignore operations_research; -%unignore operations_research::Init; -%rename (initCppLogging) operations_research::Init::InitCppLogging; -%rename (logGurobiSharedLibrary) operations_research::Init::LoadGurobiSharedLibrary; +// Expose the flags structure. +%unignore operations_research::CppFlags; +%unignore operations_research::CppFlags::logtostderr; +%unignore operations_research::CppFlags::log_prefix; + +// Expose the static methods of the bridge class. +%unignore operations_research::CppBridge; +%rename (initLogging) operations_research::CppBridge::InitLogging; +%rename (setFlags) operations_research::CppBridge::SetFlags; +%rename (logGurobiSharedLibrary) operations_research::CppBridge::LoadGurobiSharedLibrary; %include "ortools/init/init.h" diff --git a/ortools/init/python/init.i b/ortools/init/python/init.i index 7771003116..afdbdcf65b 100644 --- a/ortools/init/python/init.i +++ b/ortools/init/python/init.i @@ -10,9 +10,16 @@ %unignore operations_research; -%unignore operations_research::Init; -%unignore operations_research::Init::InitCppLogging; -%unignore operations_research::Init::LoadGurobiSharedLibrary; +// Expose the flags structure. +%unignore operations_research::CppFlags; +%unignore operations_research::CppFlags::logtostderr; +%unignore operations_research::CppFlags::log_prefix; + +// Expose the static methods of the bridge class. +%unignore operations_research::CppBridge; +%unignore operations_research::CppBridge::InitLogging; +%unignore operations_research::CppBridge::SetFlags; +%unignore operations_research::CppBridge::LoadGurobiSharedLibrary; %include "ortools/init/init.h"