|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# Example pygccxml notebook on Binder\n", |
| 8 | + "\n", |
| 9 | + "Running this notebook on Binder allows you to execute the code online:", |
| 10 | + "<a target=\"_doc\" href=\"https://mybinder.org/v2/gh/EricCousineau-TRI/pygccxml/feature-py-notebook-example?urlpath=tree/pygccxml/docs/examples/notebook/example.ipynb\">\n", |
| 11 | + " <img src=\"https://mybinder.org/badge_logo.svg\"/>\n", |
| 12 | + "</a>\n", |
| 13 | + "\n", |
| 14 | + "Please note that provisioning may take about 1-2 minutes.\n", |
| 15 | + "\n", |
| 16 | + "\n", |
| 17 | + "The following example shows an example usage of `pygccxml` on Ubuntu\n", |
| 18 | + "Bionic, from within a Docker container, for a simple toy C++ API that\n", |
| 19 | + "uses both `std::vector` and `Eigen::Matrix<>`. The code is defined inline." |
| 20 | + ] |
| 21 | + }, |
| 22 | + { |
| 23 | + "cell_type": "code", |
| 24 | + "execution_count": null, |
| 25 | + "metadata": {}, |
| 26 | + "outputs": [], |
| 27 | + "source": [ |
| 28 | + "from pygccxml import declarations\n", |
| 29 | + "from pygccxml import utils\n", |
| 30 | + "from pygccxml import parser" |
| 31 | + ] |
| 32 | + }, |
| 33 | + { |
| 34 | + "cell_type": "code", |
| 35 | + "execution_count": null, |
| 36 | + "metadata": {}, |
| 37 | + "outputs": [], |
| 38 | + "source": [ |
| 39 | + "# Find out the c++ parser. This should resolve to the castxml\n", |
| 40 | + "# version installed in Docker.\n", |
| 41 | + "generator_path, generator_name = utils.find_xml_generator()\n", |
| 42 | + "\n", |
| 43 | + "# Configure the xml generator\n", |
| 44 | + "config = parser.xml_generator_configuration_t(\n", |
| 45 | + " xml_generator_path=generator_path,\n", |
| 46 | + " xml_generator=generator_name,\n", |
| 47 | + " include_paths=[\"/usr/include/eigen3\"],\n", |
| 48 | + " compiler_path=generator_path,\n", |
| 49 | + ")" |
| 50 | + ] |
| 51 | + }, |
| 52 | + { |
| 53 | + "cell_type": "code", |
| 54 | + "execution_count": null, |
| 55 | + "metadata": {}, |
| 56 | + "outputs": [], |
| 57 | + "source": [ |
| 58 | + "code = r\"\"\"\n", |
| 59 | + "#include <vector>\n", |
| 60 | + "\n", |
| 61 | + "#include <Eigen/Dense>\n", |
| 62 | + "\n", |
| 63 | + "namespace ns {\n", |
| 64 | + "\n", |
| 65 | + "template <typename T, typename U = int>\n", |
| 66 | + "class ExampleClass {\n", |
| 67 | + "public:\n", |
| 68 | + " std::vector<T> make_std_vector() const;\n", |
| 69 | + " Eigen::Matrix<U, 3, 3> make_matrix3();\n", |
| 70 | + "};\n", |
| 71 | + "\n", |
| 72 | + "// Analyze concrete instantiations of the given class.\n", |
| 73 | + "extern template class ExampleClass<int>;\n", |
| 74 | + "extern template class ExampleClass<float, float>;\n", |
| 75 | + "\n", |
| 76 | + "} // namespace ns\n", |
| 77 | + "\"\"\"\n", |
| 78 | + "\n", |
| 79 | + "(global_ns,) = parser.parse_string(code, config)" |
| 80 | + ] |
| 81 | + }, |
| 82 | + { |
| 83 | + "cell_type": "code", |
| 84 | + "execution_count": null, |
| 85 | + "metadata": { |
| 86 | + "scrolled": false |
| 87 | + }, |
| 88 | + "outputs": [], |
| 89 | + "source": [ |
| 90 | + "ns = global_ns.namespace(\"ns\")\n", |
| 91 | + "declarations.print_declarations([ns])" |
| 92 | + ] |
| 93 | + }, |
| 94 | + { |
| 95 | + "cell_type": "code", |
| 96 | + "execution_count": null, |
| 97 | + "metadata": {}, |
| 98 | + "outputs": [], |
| 99 | + "source": [ |
| 100 | + "# Retrieve an instantiation and show template parameters.\n", |
| 101 | + "cls, = ns.classes('ExampleClass<float, float>')\n", |
| 102 | + "declarations.templates.split(cls.name)" |
| 103 | + ] |
| 104 | + } |
| 105 | + ], |
| 106 | + "metadata": { |
| 107 | + "kernelspec": { |
| 108 | + "display_name": "Python 3", |
| 109 | + "language": "python", |
| 110 | + "name": "python3" |
| 111 | + }, |
| 112 | + "language_info": { |
| 113 | + "codemirror_mode": { |
| 114 | + "name": "ipython", |
| 115 | + "version": 3 |
| 116 | + }, |
| 117 | + "file_extension": ".py", |
| 118 | + "mimetype": "text/x-python", |
| 119 | + "name": "python", |
| 120 | + "nbconvert_exporter": "python", |
| 121 | + "pygments_lexer": "ipython3", |
| 122 | + "version": "3.6.9" |
| 123 | + } |
| 124 | + }, |
| 125 | + "nbformat": 4, |
| 126 | + "nbformat_minor": 4 |
| 127 | +} |
0 commit comments