/* * Copyright (c) Meta Platforms, Inc. and 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 #include #include #include #include #include #include #include #include using namespace apache::thrift; using namespace static_reflection::demo; struct creator { template void operator()(fatal::tag, Out& out) { out.template emplace(); } }; template struct activator { using module = reflect_module; using structs = fatal::transform; // fatal::list using reflected_structs = fatal::transform>; // fatal::list< // reflect_struct, // reflect_struct, // ..., // reflect_struct // > using variant = fatal::apply_to; // fatal::auto_variant static variant create(folly::StringPiece name) { variant out; bool found = fatal::trie_find( name.begin(), name.end(), creator(), out); if (!found) { std::cerr << "no type named " << name << '\n'; } return out; } }; int main(int argc, char** argv) { folly::init(&argc, &argv); using factory = activator; auto prompt = [](std::string& out) { std::cout << "type to instantiate: "; std::cin >> out; return static_cast(std::cin); }; for (std::string name; prompt(name);) { auto instance = factory::create(name); instance.visit([](const auto& what) { detail::pretty_print(std::cout, what); std::cout << std::endl; }); } return 0; }