Is there a way to create a relatively clean C ++ class from a python class and link it at compile time?
For example, if I have this python class:
class CarDef: acceleration = 1000.0 brake = 1500.0 inertia = acceleration * 0.1 * brake def __init__(self): pass
I would like to have an appropriate C ++ class:
class CarDef { public: double acceleration; double brake; double inertia; CarDef() : acceleration( 1000.0 ) , brake( 1500.0 ) , inertia ( 150000.0 ) {}; };
The resulting C ++ class may be different, as well as the original python class: I can use the "getter methods" paradigm instead of the class attributes.
I am trying to create resource files in python that I can use in my C ++ application. The goal is to minimize the amount of code that the end user will need to write to add and use parameters; and he should avoid string comparisons during the "startup phase" (this is allowed during the "initialization phase").
I would like the user to enter the name of the resource only twice: once in the python class and once in the place where the resource will be used in C ++, assuming that the βmagicβ will bind two elements (or at runtime (which , I doubt it can be done without comparing strings), or at compile time (an intermediate step generates a C ++ class before compiling the project)). This is why I am moving from python to C ++; I believe that the transition from C ++ to python will require at least two python files: one that is generated and one that inherits from the latter (so as not to overwrite the resources already specified).
End-user usage will look like this:
With this in mind, python code is strictly outside of C ++ code.
One obvious problem I see is finding out what type the python attribute or method returns. I saw a few examples of Cython , and it looks like it can use types (that's great!), But I have not seen any examples where it could do what I need. In addition, the c generated code seems to still need Python.h and thus the cpython api library when compiling.
Are there any ways to achieve this? Is there a better way to do this?
- I am using python 3.2+.
- I am using MS Visual Studio 2010 (we plan to switch to 2013 soon).
- I am on a 32-bit system (but we plan to switch to 64 bit, OS and developed software soon).
c ++ python
Alexandre Vaillancourt
source share