Creating code at compile time using scripts

Ideally, I would like to be able to add (very repeatable) C / C ++ code to my actual code, but at compile time, the code that comes out, like the stdout python script, is the same as one does with macros.

For example, suppose I have functions that depend on the public attributes of this class, the ability to write the following in my C ++ code would be a boon:

generate_boring_functions(FooBarClass,"FooBarClass.cpp")

Is this possible using conventional means? Or should I hack makefiles and temporary source files?

Thank.

+5
source share
6 answers

, Makefile. (Python) script, , generate_boring_functions ( script -macro) , generate_boring_functions.py , .

, - .

: , , make , . .

%.o : %.cpp
    python macros.py $< | g++ -x cpp -c - -o $@
+3

make , .

class FooBarClass
{
    DEFINE_BORING_METHODS( FooBarClass )

    /* interesting functions begin here */
}

, COM.

-, make, , , .

+3

make ( ) "" !

+2

, , - Ned Batchelder Cog.

Python ++, cog ++ ++. , , cog ++ ++.

+2

Preprocessor Boost. , , - .

0
0

All Articles