-
Notifications
You must be signed in to change notification settings - Fork 612
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add
module-visitation.h
to include all visitation headers in a tran…
…sitive manner Summary: `module-visitation.h` is a convenient header that includes all visitation APIs, along with dependent thrift visitation headers transitively. This is useful for implementing general code since existing reflection is transitive. If user doesn't need transitivity, they can still include each individual header to reduce build-time. Reviewed By: yfeldblum Differential Revision: D23253246 fbshipit-source-id: ac4c07ffa71ccd849756dccaaf44b70d5d391b76
- Loading branch information
1 parent
f38c234
commit 5d84040
Showing
4 changed files
with
86 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
23 changes: 23 additions & 0 deletions
23
thrift/compiler/generate/templates/cpp2/module_visitation.h.mustache
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,23 @@ | ||
<%! | ||
|
||
Copyright (c) Facebook, Inc. and its affiliates. | ||
|
||
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. | ||
|
||
%><% > Autogen%> | ||
#pragma once | ||
<%#program:thrift_includes%> | ||
#include "<%program:include_prefix%><%program:name%>_visitation.h" | ||
<%/program:thrift_includes%> | ||
#include "<%program:include_prefix%><%program:name%>_for_each_field.h" | ||
#include "<%program:include_prefix%><%program:name%>_visit_union.h" |
11 changes: 11 additions & 0 deletions
11
thrift/compiler/test/fixtures/visitation/gen-cpp2/module_visitation.h
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,11 @@ | ||
/** | ||
* Autogenerated by Thrift | ||
* | ||
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING | ||
* @generated | ||
*/ | ||
#pragma once | ||
#include "thrift/compiler/test/fixtures/visitation/gen-cpp2/reflection_dep_B_visitation.h" | ||
#include "thrift/compiler/test/fixtures/visitation/gen-cpp2/reflection_dep_C_visitation.h" | ||
#include "thrift/compiler/test/fixtures/visitation/gen-cpp2/module_for_each_field.h" | ||
#include "thrift/compiler/test/fixtures/visitation/gen-cpp2/module_visit_union.h" |
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,49 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* 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 <thrift/test/gen-cpp2/reflection_visitation.h> // @manual=:reflection_if-cpp2-visitation | ||
|
||
#include <folly/Overload.h> | ||
#include <folly/portability/GTest.h> | ||
|
||
using namespace apache::thrift; | ||
using namespace std; | ||
|
||
namespace test_cpp2 { | ||
namespace cpp_reflection { | ||
TEST(dep_C_struct, test_transitivity) { | ||
dep_C_struct s; | ||
s.i_c_ref() = 10; | ||
s.d_ref()->i_d_ref() = 20; | ||
for_each_field(s, [](auto&&, auto&& ref) { | ||
folly::overload( | ||
[](int32_t i) { EXPECT_EQ(i, 10); }, | ||
[](dep_D_struct d) { | ||
for_each_field(d, [](auto&&, auto&& ref) { EXPECT_EQ(*ref, 20); }); | ||
})(*ref); | ||
}); | ||
} | ||
TEST(union1, test_union) { | ||
union1 s; | ||
s.us_ref() = "foo"; | ||
visit_union(s, [](auto&&, auto&& value) { | ||
folly::overload( | ||
[](string& s) { EXPECT_EQ(s, "foo"); }, | ||
[](auto&&) { EXPECT_TRUE(false); })(value); | ||
}); | ||
} | ||
} // namespace cpp_reflection | ||
} // namespace test_cpp2 |