compile time (template or preprocessor) text processing

Hello, My question is c++ related (I like to call the topic extreme c++ programming). We all know the excellent boost python framework, which exports c++ functions to python with spectacular elegance. As for the documentation of those functions boost offers a string parameter, which can contain the description of the particular function. Sometimes this documentation is already written (for example in doxygen). It would be good to import this documentation somehow to python. Is there a possibility to generate a std::string from a FILE following some rules using template meta-programming (or possibly the preprocessor)? For example my_function.cpp ///************* // this is the documentation of my_function // void my_function() { cout << "I've been called.\n" } boost_export.cpp def( "my_function", &my_function, (args()), generate_the_doc_in_compile_time_from<>("my_function.cpp") ) Here the generate_the_doc_in_compile_time_from<>("my_function.cpp") would hard-wire the docs into def at compile time, so it would no longer depend on my_function.cpp. Any ideas would be greatly appreciated. UJ

On 05.12.2010 22:04, Laszlo Marak wrote:
Is there a possibility to generate a std::string from a FILE following some rules using template meta-programming (or possibly the preprocessor)? Sorry, absolutely not. Reading files is completely beyond the template system, and the preprocessor will interpret it as C++ code, so even if you could come up with amazingly clever macros to hide all the code (you can't), you still wouldn't have access to the contents of comments.
Sebastian

Hi Lsazio,
On 5 December 2010 21:04, Laszlo Marak
Is there a possibility to generate a std::string from a FILE following some rules using template meta-programming (or possibly the preprocessor)?
Are you familiar with makefiles? the preprocessor? This might be a suitable recipe for you. 1. Write a program to turn the contents of a text file into, say, a C or C++ file that contains the text of the file in question. Something like a program that takes this (sample.txt) :- This is the first line of sample.txt This is the second line of sample.txt And outputs something like this as something like sample.c:- char *MessageArray[] = { "This is the first line of sample.txt", "This is the second line of sample.txt" }; Which can then be #included into your source code, ready to be compiled along with the rest of your code, The role of the makefile would be to generate the C source code before it gets compiled, invoking a utility program (written by you) to turn sample.txt into sample.c. HTH, Ian -- -- ACCU - Professionalism in programming - http://www.accu.org/
participants (3)
-
Ian Bruntlett
-
Laszlo Marak
-
Sebastian Redl