Python in C++ or C++ pure for file templates manipulation?
<p>(I don't know if I can post such a question here)</p>

<p>I have a problem for which I need a suggestion. I've a C++ code that derive several parameters (which are numbers basically). Such numbers have to be used to generate further code, of which I have templates, as very trivial example a template could look as something like:</p>

<pre><code>#define PAR1 &lt;PAR1&gt;
#define PAR2 &lt;PAR2&gt;
//other parameters, function declaration, tables and so on...
</code></pre>

<p>In the example above ,  and all the possible others are derived by the C++ code mentioned above.</p>

<p>What would be, in your opinion, a good approach to achieve the parameter replacement?</p>

<p>I was thinking at two solutions, but I don't know which one would be the best:
1. I could write several python scripts (as many as I need) for string replacement for given parameters, such scripts has to be called in the C++ application once the parameters have been derived.
2. Reading the stream of the template file, look for the position of the parameters to be replaced and the replace it.</p>

<p>The first solution would require to call the pythons script from the C++ application and I don't know how to do that, I've been looking at some solution, and to be honest I don't know how simple it is.</p>

<p>The second solution is C++ file manipulation, which could be a bit of a pain in my specific case?</p>

<p>Since what I'm up to is the easiest way to achieve my goal which one would you suggest?</p>

<p>Thx</p>

<p>Update: I'm trying to be a bit more specific by posting a trivial example. A possible template, extremely minimal, could be the following:</p>

<pre><code>//header_template.h
#ifndef HEADER_H
#define HEADER_H
#include &lt;stdio.h&gt;

#define A &lt;A&gt;
#define B &lt;B&gt;
#define C &lt;C&gt;

void func1();
void func2();
void func3();

#endif
</code></pre>

<p>The source file
    //src.c
    #include "header.h"</p>

<pre><code>void func1() {
  int i, my_array1[A];
  for(i = 0; i &lt; A; i++) {
     my_array1[i] = do_something(i);
  }
  //other processing;
}

void func2() {
  int i, j, my_matrix[A][B];
  for(i = 0; i &lt; A; i++) {
     for(j = 0; j &lt; B; j++) {
        my_matrix[i][j] = do_something_2(i,j);
     }
  }
}

void func3() {
  int i;
  int my_array[A + B + C];
  for(i = 0; i &lt; A + B + C; i++) {
     my_array[i] = do_something_else(i);
  }
}
</code></pre>

<p>The parameters <code>A, B, C</code> are derived by some other processing operations prior the code generation, what I want to achieve is something like:</p>

<pre><code>//header.h
#ifndef HEADER_H
#define HEADER_H
#include &lt;stdio.h&gt;

#define A 17
#define B 9
#define C 37

void func1();
void func2();
void func3();

#endif
</code></pre>

<p>My question is: doing text replacement using python is very easy, in C++ is not that easy. The processing of the parameters A,B and C is done by something implemented in C++, I need to extend such program for for such replacement, given the fact I've been using C++ so far is it better to develop small python programs and then call such scripts in the C++ program or is it better just to implement functions in C++ for the replacement?</p>

<p>The example I made can sound trivial, which is true, however the actual code I'm dealing with, and I'm posting larger of course so what I'm asking is what you would do in such a case.</p>