New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add usage samples #31
Labels
enhancement
New feature or request
Projects
Comments
@Manu343726 , would you like to add your cppast/tinyrefl template examples here? |
Whenever I make it work, sure ;) |
Thanks! |
BTW something like this should work right now: #include <cppast/libclang_parser.hpp>
#include <tinyrefl/tool/model/cppast/jinja2reflection.hpp>
#include <jinja2cpp/template.h>
using namespace tinyrefl::tool::model;
int main()
{
using parser_t = cppast::simple_file_parser<cppast::libclang_parser>;
cppast::cpp_entity_index index;
parser_t parser{type_safe::ref(index)};
parser_t::config config;
config.set_flags(cppast::cpp_standard::cpp_11);
auto file = parser.parse("my_enum.hpp", config);
jinja2::ValuesMap variables{
{"file", jinja2::Reflect(make_entity_ref(index, file.value()))}};
jinja2::Template tmpl;
tmpl.Load(R"(
{% for enum in file.enums %}
{{enum.fullname}} from_string(const std::string& str)
{
{% for value in enum.values %}
if((str == "{{value.name}}") ||
(str == "{{value.qualifiedname}}") ||
(str == "{{value.fullname}}"))
{
return {{value.fullname}};
}
{% endfor %}
throw std::logic_error{"Invalid {{enum.fullname}} value name"};
}
{% endfor %}
)");
std::ofstream output{"my_enum_from_string.cpp"};
tmpl.Render(output, variables);
} |
Contemporary classics. :D |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add usage samples for:
The text was updated successfully, but these errors were encountered: