Skip to content

Commit 6a562b0

Browse files
committed
introduce struct to hold flags in cpp init code; rename classes
1 parent f9f4ab4 commit 6a562b0

6 files changed

Lines changed: 54 additions & 20 deletions

File tree

examples/dotnet/csintegerprogramming.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// limitations under the License.
1313

1414
using System;
15+
using Google.OrTools.Init;
1516
using Google.OrTools.LinearSolver;
1617

1718
public class CsIntegerProgramming
@@ -100,7 +101,11 @@ private static void RunIntegerProgrammingExampleNaturalApi(String solverType)
100101

101102
static void Main()
102103
{
103-
Google.OrTools.Init.Init.InitCppLogging("csintegerprogramming.cs", true, false);
104+
CppBridge.InitLogging("csintegerprogramming.cs");
105+
CppFlags flags = new CppFlags();
106+
flags.logtostderr = true;
107+
flags.log_prefix = false;
108+
CppBridge.SetFlags(flags);
104109

105110
Console.WriteLine("---- Integer programming example with GLPK ----");
106111
RunIntegerProgrammingExample("GLPK");

examples/python/integer_programming.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ def main():
116116

117117

118118
if __name__ == '__main__':
119-
init.Init.InitCppLogging('integer_programming.py',
120-
/*logtostderr=*/True,
121-
/*log_prefix=*/False);
119+
init.CppBridge.InitLogging('integer_programming.py')
120+
cpp_flags = init.CppFlags()
121+
cpp_flags.logtostderr = True
122+
cpp_flags.log_prefix = False
123+
init.CppBridge.SetFlags(cpp_flags)
122124
main()

ortools/init/csharp/init.i

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@
1010

1111
%unignore operations_research;
1212

13-
%unignore operations_research::Init;
14-
%unignore operations_research::Init::InitCppLogging;
15-
%unignore operations_research::Init::LoadGurobiSharedLibrary;
13+
// Expose the flags structure.
14+
%unignore operations_research::CppFlags;
15+
%unignore operations_research::CppFlags::logtostderr;
16+
%unignore operations_research::CppFlags::log_prefix;
17+
18+
// Expose the static methods of the bridge class.
19+
%unignore operations_research::CppBridge;
20+
%unignore operations_research::CppBridge::InitLogging;
21+
%unignore operations_research::CppBridge::SetFlags;
22+
%unignore operations_research::CppBridge::LoadGurobiSharedLibrary;
1623

1724
%include "ortools/init/init.h"
1825

ortools/init/init.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,25 @@
88

99
namespace operations_research {
1010

11+
struct CppFlags {
12+
bool logtostderr = false;
13+
bool log_prefix = false;
14+
};
15+
1116
// This class performs various C++ initialization.
1217
// It is meant to be used once at the start of a program.
13-
class Init {
18+
class CppBridge {
1419
public:
1520
// Initialize the C++ logging layer.
16-
// If logtostderr is false, all C++ logging will be ignored.
17-
// If true, all logging will the displayed on stderr.
18-
static void InitCppLogging(const std::string& program_name, bool logtostderr,
19-
bool log_prefix) {
20-
absl::SetFlag(&FLAGS_logtostderr, logtostderr);
21-
absl::SetFlag(&FLAGS_log_prefix, log_prefix);
21+
static void InitLogging(const std::string& program_name) {
2222
google::InitGoogleLogging(program_name.c_str());
2323
}
24+
25+
// Sets all the C++ flags contained in the CppFlags structure.
26+
static void SetFlags(const CppFlags& flags) {
27+
absl::SetFlag(&FLAGS_logtostderr, flags.logtostderr);
28+
absl::SetFlag(&FLAGS_log_prefix, flags.log_prefix);
29+
}
2430

2531
// Load the gurobi shared library.
2632
// This is necessary if the library is installed in a non canonical

ortools/init/java/init.i

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@
1010

1111
%unignore operations_research;
1212

13-
%unignore operations_research::Init;
14-
%rename (initCppLogging) operations_research::Init::InitCppLogging;
15-
%rename (logGurobiSharedLibrary) operations_research::Init::LoadGurobiSharedLibrary;
13+
// Expose the flags structure.
14+
%unignore operations_research::CppFlags;
15+
%unignore operations_research::CppFlags::logtostderr;
16+
%unignore operations_research::CppFlags::log_prefix;
17+
18+
// Expose the static methods of the bridge class.
19+
%unignore operations_research::CppBridge;
20+
%rename (initLogging) operations_research::CppBridge::InitLogging;
21+
%rename (setFlags) operations_research::CppBridge::SetFlags;
22+
%rename (logGurobiSharedLibrary) operations_research::CppBridge::LoadGurobiSharedLibrary;
1623

1724
%include "ortools/init/init.h"
1825

ortools/init/python/init.i

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@
1010

1111
%unignore operations_research;
1212

13-
%unignore operations_research::Init;
14-
%unignore operations_research::Init::InitCppLogging;
15-
%unignore operations_research::Init::LoadGurobiSharedLibrary;
13+
// Expose the flags structure.
14+
%unignore operations_research::CppFlags;
15+
%unignore operations_research::CppFlags::logtostderr;
16+
%unignore operations_research::CppFlags::log_prefix;
17+
18+
// Expose the static methods of the bridge class.
19+
%unignore operations_research::CppBridge;
20+
%unignore operations_research::CppBridge::InitLogging;
21+
%unignore operations_research::CppBridge::SetFlags;
22+
%unignore operations_research::CppBridge::LoadGurobiSharedLibrary;
1623

1724
%include "ortools/init/init.h"
1825

0 commit comments

Comments
 (0)