Skip to content

Commit b0c1650

Browse files
committed
Merge branch 'main' of github.com:google/or-tools
2 parents 6041f1d + d7da954 commit b0c1650

File tree

74 files changed

+7879
-1475
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+7879
-1475
lines changed

ortools/base/BUILD.bazel

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,8 @@ cc_library(
266266
name = "gmock",
267267
hdrs = ["gmock.h"],
268268
deps = [
269-
":message_matchers",
270-
":status_matchers",
269+
":protocol-buffer-matchers",
270+
":status-matchers",
271271
"@googletest//:gtest",
272272
],
273273
)
@@ -408,16 +408,6 @@ cc_library(
408408
],
409409
)
410410

411-
cc_library(
412-
name = "message_matchers",
413-
hdrs = ["message_matchers.h"],
414-
deps = [
415-
"@abseil-cpp//absl/strings",
416-
"@googletest//:gtest",
417-
"@protobuf",
418-
],
419-
)
420-
421411
cc_library(
422412
name = "murmur",
423413
hdrs = ["murmur.h"],
@@ -447,6 +437,7 @@ cc_library(
447437
name = "parse_text_proto",
448438
hdrs = ["parse_text_proto.h"],
449439
deps = [
440+
"//ortools/base:status_macros",
450441
"@abseil-cpp//absl/log:check",
451442
"@protobuf",
452443
],
@@ -477,6 +468,17 @@ cc_library(
477468
hdrs = ["protobuf_util.h"],
478469
)
479470

471+
cc_library(
472+
name = "protocol-buffer-matchers",
473+
hdrs = ["protocol-buffer-matchers.h"],
474+
deps = [
475+
"@abseil-cpp//absl/log:check",
476+
"@abseil-cpp//absl/strings",
477+
"@googletest//:gtest",
478+
"@protobuf",
479+
],
480+
)
481+
480482
cc_library(
481483
name = "protoutil",
482484
hdrs = ["protoutil.h"],
@@ -540,8 +542,8 @@ cc_library(
540542
)
541543

542544
cc_library(
543-
name = "status_matchers",
544-
hdrs = ["status_matchers.h"],
545+
name = "status-matchers",
546+
hdrs = ["status-matchers.h"],
545547
deps = [
546548
":base",
547549
"@abseil-cpp//absl/status",

ortools/base/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
# limitations under the License.
1313

1414
file(GLOB _SRCS "*.h" "*.cc")
15-
list(FILTER _SRCS EXCLUDE REGEX ".*/.*_test.cc")
16-
list(FILTER _SRCS EXCLUDE REGEX "/status_matchers\\.h")
15+
list(FILTER _SRCS EXCLUDE REGEX "/.*_test.cc")
16+
list(FILTER _SRCS EXCLUDE REGEX "/status-matchers\.h")
17+
list(FILTER _SRCS EXCLUDE REGEX "/protocol-buffer-matchers\.h")
18+
1719
set(NAME ${PROJECT_NAME}_base)
1820

1921
# Will be merge in libortools.so

ortools/base/gmock.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#define OR_TOOLS_BASE_GMOCK_H_
1616

1717
#include "gmock/gmock.h"
18-
#include "ortools/base/message_matchers.h"
19-
#include "ortools/base/status_matchers.h"
18+
#include "ortools/base/protocol-buffer-matchers.h" // IWYU pragma: export
19+
#include "ortools/base/status-matchers.h" // IWYU pragma: export
2020

2121
#endif // OR_TOOLS_BASE_GMOCK_H_

ortools/base/message_matchers.h

Lines changed: 0 additions & 177 deletions
This file was deleted.

ortools/base/parse_text_proto.h

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,48 @@
1111
// See the License for the specific language governing permissions and
1212
// limitations under the License.
1313

14-
#ifndef OR_TOOLS_BASE_PARSE_TEXT_PROTO_H_
15-
#define OR_TOOLS_BASE_PARSE_TEXT_PROTO_H_
14+
// emulates g3/net/proto2/contrib/parse_proto/parse_text_proto.h
15+
#ifndef ORTOOLS_BASE_PARSE_TEXT_PROTO_H_
16+
#define ORTOOLS_BASE_PARSE_TEXT_PROTO_H_
1617

1718
#include <string>
18-
#include <string_view>
1919

2020
#include "absl/log/check.h"
21+
#include "absl/status/status.h"
22+
#include "absl/strings/string_view.h"
2123
#include "google/protobuf/message.h"
2224
#include "google/protobuf/text_format.h"
25+
#include "ortools/base/status_macros.h"
2326

2427
namespace google::protobuf::contrib::parse_proto {
2528

2629
template <typename T>
27-
bool ParseTextProto(const std::string& input, T* proto) {
28-
return google::protobuf::TextFormat::ParseFromString(input, proto);
30+
absl::Status ParseTextProtoInto(absl::string_view input, T* proto) {
31+
if (google::protobuf::TextFormat::ParseFromString(input, proto))
32+
return absl::OkStatus();
33+
return absl::Status(absl::StatusCode::kInvalidArgument,
34+
"Could not parse the text proto\n");
2935
}
3036

3137
template <typename T>
32-
T ParseTextOrDie(const std::string& input) {
38+
absl::StatusOr<T> ParseTextProto(absl::string_view asciipb) {
39+
T msg;
40+
RETURN_IF_ERROR(ParseTextProtoInto(asciipb, &msg));
41+
return msg;
42+
}
43+
44+
template <typename T>
45+
T ParseTextOrDie(absl::string_view input) {
3346
T result;
34-
CHECK(ParseTextProto(input, &result));
47+
CHECK(google::protobuf::TextFormat::ParseFromString(input, &result));
3548
return result;
3649
}
3750

3851
namespace text_proto_internal {
3952

4053
class ParseProtoHelper {
4154
public:
42-
explicit ParseProtoHelper(std::string_view asciipb) : asciipb_(asciipb) {}
55+
explicit ParseProtoHelper(absl::string_view asciipb) : asciipb_(asciipb) {}
4356
template <class T>
4457
operator T() { // NOLINT(runtime/explicit)
4558
T result;
@@ -56,10 +69,10 @@ class ParseProtoHelper {
5669
} // namespace text_proto_internal
5770

5871
inline text_proto_internal::ParseProtoHelper ParseTextProtoOrDie(
59-
std::string_view input) {
72+
absl::string_view input) {
6073
return text_proto_internal::ParseProtoHelper(input);
6174
}
6275

6376
} // namespace google::protobuf::contrib::parse_proto
6477

65-
#endif // OR_TOOLS_BASE_PARSE_TEXT_PROTO_H_
78+
#endif // ORTOOLS_BASE_PARSE_TEXT_PROTO_H_

0 commit comments

Comments
 (0)