-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: dentiny <dentinyhao@gmail.com>
- Loading branch information
Showing
23 changed files
with
1,478 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
load("//bazel:ray.bzl", "ray_cc_library", "ray_cc_test") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
ray_cc_library( | ||
name = "type_printer", | ||
hdrs = ["type_printer.h"], | ||
deps = [ | ||
":get_type_name", | ||
"@boost//:core", | ||
], | ||
) | ||
|
||
ray_cc_library( | ||
name = "std_printer", | ||
hdrs = ["std_printer.h"], | ||
deps = [ | ||
":ostream_printer", | ||
], | ||
) | ||
|
||
ray_cc_test( | ||
name = "std_printer_test", | ||
srcs = ["std_printer_test.cc"], | ||
tags = ["team:core"], | ||
deps = [ | ||
":std_printer", | ||
"@com_google_absl//absl/strings:str_format", | ||
"@com_google_googletest//:gtest_main", | ||
], | ||
) | ||
|
||
ray_cc_library( | ||
name = "debug_string_printer", | ||
hdrs = ["debug_string_printer.h"], | ||
) | ||
|
||
ray_cc_test( | ||
name = "debug_string_printer_test", | ||
srcs = ["debug_string_printer_test.cc"], | ||
tags = ["team:core"], | ||
deps = [ | ||
":debug_string_printer", | ||
"@com_google_googletest//:gtest_main", | ||
], | ||
) | ||
|
||
ray_cc_library( | ||
name = "absl_stringify_printer", | ||
hdrs = ["absl_stringify_printer.h"], | ||
deps = [ | ||
"@com_google_absl//absl/strings", | ||
], | ||
) | ||
|
||
ray_cc_test( | ||
name = "absl_stringify_printer_test", | ||
srcs = ["absl_stringify_printer_test.cc"], | ||
tags = ["team:core"], | ||
deps = [ | ||
":absl_stringify_printer", | ||
"@com_google_absl//absl/strings:str_format", | ||
"@com_google_googletest//:gtest_main", | ||
], | ||
) | ||
|
||
ray_cc_library( | ||
name = "container_printer", | ||
hdrs = ["container_printer.h"], | ||
deps = [ | ||
":ostream_printer", | ||
"//src/ray/util:type_traits", | ||
], | ||
) | ||
|
||
ray_cc_test( | ||
name = "container_printer_test", | ||
srcs = ["container_printer_test.cc"], | ||
tags = ["team:core"], | ||
deps = [ | ||
":container_printer", | ||
"//src/ray/util:type_traits", | ||
"//src/ray/util:visitor", | ||
"@com_google_googletest//:gtest_main", | ||
], | ||
) | ||
|
||
ray_cc_library( | ||
name = "ostream_printer", | ||
hdrs = ["ostream_printer.h"], | ||
) | ||
|
||
ray_cc_test( | ||
name = "ostream_printer_test", | ||
srcs = ["ostream_printer_test.cc"], | ||
tags = ["team:core"], | ||
deps = [ | ||
":ostream_printer", | ||
"@com_google_googletest//:gtest_main", | ||
], | ||
) | ||
|
||
ray_cc_library( | ||
name = "enum_printer", | ||
hdrs = ["enum_printer.h"], | ||
) | ||
|
||
ray_cc_test( | ||
name = "enum_printer_test", | ||
srcs = ["enum_printer_test.cc"], | ||
tags = ["team:core"], | ||
deps = [ | ||
":enum_printer", | ||
"@com_google_googletest//:gtest_main", | ||
], | ||
) | ||
|
||
ray_cc_library( | ||
name = "debug_printer", | ||
hdrs = ["debug_printer.h"], | ||
deps = [ | ||
":absl_stringify_printer", | ||
":container_printer", | ||
":debug_string_printer", | ||
":enum_printer", | ||
":ostream_printer", | ||
":std_printer", | ||
":type_printer", | ||
"//src/ray/util:visitor", | ||
], | ||
) | ||
|
||
ray_cc_test( | ||
name = "debug_printer_test", | ||
srcs = ["debug_printer_test.cc"], | ||
tags = ["team:core"], | ||
deps = [ | ||
":debug_printer", | ||
"@com_google_googletest//:gtest_main", | ||
], | ||
) | ||
|
||
ray_cc_library( | ||
name = "get_type_name", | ||
hdrs = ["get_type_name.h"], | ||
) | ||
|
||
ray_cc_test( | ||
name = "get_type_name_test", | ||
srcs = ["get_type_name_test.cc"], | ||
tags = ["team:core"], | ||
deps = [ | ||
":get_type_name", | ||
"@com_google_googletest//:gtest_main", | ||
], | ||
) |
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,47 @@ | ||
// Copyright 2025 The Ray Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Printer for types which defines `AbslStringify`. | ||
|
||
#pragma once | ||
|
||
#include <iostream> | ||
#include <type_traits> | ||
|
||
#include "absl/strings/str_cat.h" | ||
|
||
namespace ray { | ||
|
||
// TODO(hjiang): Later version of abseil contains abseil string defined trait. | ||
template <typename T, typename = void, typename = void> | ||
struct is_stringifyable : std::false_type {}; | ||
|
||
template <typename T, typename SinkType> | ||
struct is_stringifyable<T, | ||
SinkType, | ||
std::void_t<decltype(AbslStringify(std::declval<SinkType &>(), | ||
std::declval<const T &>()))>> | ||
: std::true_type {}; | ||
|
||
template <typename T> | ||
inline constexpr bool is_stringifyable_v = is_stringifyable<T, std::ostream>::value; | ||
|
||
struct AbslStringifyPrinter { | ||
template <typename T, std::enable_if_t<is_stringifyable_v<T>, int> = 0> | ||
void operator()(std::ostream &os, const T &obj) const { | ||
os << absl::StrCat(obj); | ||
} | ||
}; | ||
|
||
} // namespace ray |
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,47 @@ | ||
// Copyright 2025 The Ray Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "ray/util/strings/absl_stringify_printer.h" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include "absl/strings/str_format.h" | ||
|
||
namespace ray { | ||
|
||
namespace { | ||
|
||
struct Point { | ||
template <typename Sink> | ||
friend void AbslStringify(Sink &sink, const Point &p) { | ||
absl::Format(&sink, "(%d, %d)", p.x, p.y); | ||
} | ||
|
||
int x; | ||
int y; | ||
}; | ||
|
||
TEST(AbslStringifyTest, BasicTest) { | ||
Point point; | ||
point.x = 10; | ||
point.y = 20; | ||
|
||
std::stringstream ss; | ||
AbslStringifyPrinter{}(ss, point); | ||
EXPECT_EQ(ss.str(), "(10, 20)"); | ||
} | ||
|
||
} // namespace | ||
|
||
} // namespace ray |
Oops, something went wrong.