Skip to content

Commit

Permalink
fix type, fix doc
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos committed Oct 21, 2024
1 parent d7cedc7 commit 94aea93
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux_llvm_cov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
./struct_pb_test
./reflection_test
llvm-profdata merge -sparse test_ylt-*.profraw -o test_ylt.profdata
llvm-cov show coro_io_test -object coro_rpc_test -object easylog_test -object struct_pack_test -object struct_pack_test_with_optimize ./metric_test ./struct_pb_test ./reflection_test -instr-profile=test_ylt.profdata -format=html -output-dir=../../.coverage_llvm_cov -ignore-filename-regex="thirdparty|asio|src" -show-instantiations=false
llvm-cov show coro_io_test -object coro_rpc_test -object easylog_test -object struct_pack_test -object struct_pack_test_with_optimize -object metric_test -object struct_pb_test -object reflection_test -instr-profile=test_ylt.profdata -format=html -output-dir=../../.coverage_llvm_cov -ignore-filename-regex="thirdparty|asio|src" -show-instantiations=false
echo "Done!"
- name: Upload Coverage Results
Expand Down
18 changes: 18 additions & 0 deletions include/ylt/standalone/iguana/pb_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,24 @@ IGUANA_INLINE constexpr std::string_view get_type_string() {
}
}
}
else if constexpr (std::is_same_v<T, iguana::sint32_t>) {
return "sint32";
}
else if constexpr (std::is_same_v<T, iguana::sint64_t>) {
return "sint64";
}
else if constexpr (std::is_same_v<T, iguana::fixed32_t>) {
return "fixed32";
}
else if constexpr (std::is_same_v<T, iguana::fixed64_t>) {
return "fixed64";
}
else if constexpr (std::is_same_v<T, iguana::sfixed32_t>) {
return "sfixed32";
}
else if constexpr (std::is_same_v<T, iguana::sfixed64_t>) {
return "sfixed64";
}
else if constexpr (std::is_same_v<T, std::string> ||
std::is_same_v<T, std::string_view>) {
return "string";
Expand Down
18 changes: 9 additions & 9 deletions src/reflection/tests/test_reflection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void test_pt() {
CHECK(y == 4);

#if __cplusplus >= 202002L
constexpr auto x = get<"x"_ylts>(pt);
constexpr auto x = get<"x">(pt);
static_assert(x == 2);
#endif
}
Expand Down Expand Up @@ -119,10 +119,10 @@ TEST_CASE("test member value") {
CHECK(age1 == 6);

#if __cplusplus >= 202002L
auto& age2 = get<"age"_ylts>(p);
auto& age2 = get<"age">(p);
CHECK(age2 == 6);

auto& var1 = get<"str"_ylts>(p);
auto& var1 = get<"str">(p);
CHECK(var1 == "hello reflection");
#endif

Expand Down Expand Up @@ -179,10 +179,10 @@ TEST_CASE("test member value") {
CHECK(name2 == "str");

#if __cplusplus >= 202002L
constexpr size_t idx = index_of<simple, "str"_ylts>();
constexpr size_t idx = index_of<simple, "str">();
CHECK(idx == 2);

constexpr size_t idx2 = index_of<simple, "no_such"_ylts>();
constexpr size_t idx2 = index_of<simple, "no_such">();
CHECK(idx2 == 4);
#endif

Expand Down Expand Up @@ -360,16 +360,16 @@ TEST_CASE("test macros") {
CHECK(*std::get<3>(var) == 6);

#if __cplusplus >= 202002L
auto& age2 = get<"age"_ylts>(t);
auto& age2 = get<"age">(t);
CHECK(age2 == 6);

auto& var1 = get<"str"_ylts>(t);
auto& var1 = get<"str">(t);
CHECK(var1 == "hello reflection");

constexpr size_t idx = index_of<simple2, "str"_ylts>();
constexpr size_t idx = index_of<simple2, "str">();
CHECK(idx == 2);

constexpr size_t idx2 = index_of<simple2, "no_such"_ylts>();
constexpr size_t idx2 = index_of<simple2, "no_such">();
CHECK(idx2 == 4);
#endif

Expand Down
7 changes: 7 additions & 0 deletions src/struct_pb/tests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,10 @@ TEST_CASE("test reflection") {
}

TEST_CASE("test struct_pb") {
{
uint8_t c = 0x1;
printf("%x", ~c);
}
{
my_space::inner_struct inner{41, 42, 43};

Expand Down Expand Up @@ -1197,6 +1201,9 @@ TEST_CASE("struct to proto") {
}
{
std::string str;
auto s1 = iguana::detail::get_type_string1<iguana::sint32_t>();
auto s2 = iguana::detail::get_type_string1<iguana::sint64_t>();

iguana::to_proto<test_pb_st1>(str, "pb");
std::cout << str;
CHECK(str.find("sint64 z = 3;") != std::string::npos);
Expand Down
6 changes: 3 additions & 3 deletions website/docs/zh/reflection/reflection_introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ int main() {
static_assert(name_of<simple, 1>()== "id");
// 根据编译期字段名获取字段值
CHECK(get<"age"_ylts>(p) == 6);
CHECK(get<"str"_ylts>(p) == "hello reflection");
CHECK(get<"age">(p) == 6);
CHECK(get<"str">(p) == "hello reflection");
// 根据编译期字段名获取字段索引
static_assert(index_of<simple2, "str"_ylts>() == 2);
static_assert(index_of<simple2, "str">() == 2);
// 遍历对象的字段、字段名、字段索引, 并打印
for_each(p, [](auto& field, auto name, auto index) {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/zh/struct_pb/struct_pb_intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct person {
std::string name;
int age;
};
#if __cplusplus >= 202002L
#if __cplusplus < 202002L
YLT_REFL(person, id, name, age);
#endif
```
Expand Down

0 comments on commit 94aea93

Please sign in to comment.