By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,889 Members | 1,297 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,889 IT Pros & Developers. It's quick & easy.

Text templates: "embedded c++"

P: n/a
I'd like to process text or document templates that use "embedded
C++". Here is a constructed example (the texts I have in mind are much
longer and contain relatively few code blocks):

--------TEXT TEMPLATE--------
<CI>#include <iostream>
#include "LetterDataContainer.hpp"
using namespace std;
LetterDataContainer d;</CI>
Dear <C>if(d.isMale()) cout << "Sir";
else cout << "Madam";</C>
as you may have noticed, you still owe me some<C>if(d.getAmount() >
1000){cout << " considerable";}</C> amount of money. Please pay
<C>cout << d.getUrgency();</C>.
--------TEXT TEMPLATE--------

So, it's a text template containing several C++ code blocks that refer
to some data in an object. Every block of code is within <C></C> tags.
The <CI></CI> tags contain header code that is needed as a header for
every code block file.

Now, a program could extract each code block and compile it into an .o
file. Each .o file would contain the header code and one method, for
example sth like
void block_001(){if(d.getAmount() > 1000){cout << " considerable";}}

Then, it would alternately print a piece of text and execute a code
block, print the next piece of text, execute the next code block and
so on.

Is there a better way to process document templates? Or is there a
library that does sth like this? Of course, it's easier to do such a
processing and eval thing in Perl (see
http://perl.plover.com/Template), but the data I have is gathered by a
C++ object.

Thanks!
Markus
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Markus Dehmann" <ma*******@gmx.de> wrote in message
news:c1**************************@posting.google.c om...
I'd like to process text or document templates that use "embedded
C++". Here is a constructed example (the texts I have in mind are much
longer and contain relatively few code blocks):

--------TEXT TEMPLATE--------
<CI>#include <iostream>
#include "LetterDataContainer.hpp"
using namespace std;
LetterDataContainer d;</CI>
Dear <C>if(d.isMale()) cout << "Sir";
else cout << "Madam";</C>
as you may have noticed, you still owe me some<C>if(d.getAmount() >
1000){cout << " considerable";}</C> amount of money. Please pay
<C>cout << d.getUrgency();</C>.
--------TEXT TEMPLATE--------

So, it's a text template containing several C++ code blocks that refer
to some data in an object. Every block of code is within <C></C> tags.
The <CI></CI> tags contain header code that is needed as a header for
every code block file.

Now, a program could extract each code block and compile it into an .o
file. Each .o file would contain the header code and one method, for
example sth like
void block_001(){if(d.getAmount() > 1000){cout << " considerable";}}

Then, it would alternately print a piece of text and execute a code
block, print the next piece of text, execute the next code block and
so on.

Is there a better way to process document templates? Or is there a
library that does sth like this? Of course, it's easier to do such a
processing and eval thing in Perl (see
http://perl.plover.com/Template), but the data I have is gathered by a
C++ object.

Thanks!
Markus


Despite the fact that your code blocks are C++, I think it would still be
best to use perl or some other scripting language to do the processing. Its
just the sort of thing scripting languages are good at.

john
Jul 22 '05 #2

P: n/a
"John Harrison" <jo*************@hotmail.com> wrote in message news:<2g************@uni-berlin.de>...
"Markus Dehmann" <ma*******@gmx.de> wrote in message
news:c1**************************@posting.google.c om...
I'd like to process text or document templates that use "embedded
C++". Here is a constructed example (the texts I have in mind are much
longer and contain relatively few code blocks):

--------TEXT TEMPLATE--------
<CI>#include <iostream>
#include "LetterDataContainer.hpp"
using namespace std;
LetterDataContainer d;</CI>
Dear <C>if(d.isMale()) cout << "Sir";
else cout << "Madam";</C>
as you may have noticed, you still owe me some<C>if(d.getAmount() >
1000){cout << " considerable";}</C> amount of money. Please pay
<C>cout << d.getUrgency();</C>.
--------TEXT TEMPLATE-------- Now, a program could extract each code block and compile it into an .o
file. Each .o file would contain the header code and one method, for
example sth like
void block_001(){if(d.getAmount() > 1000){cout << " considerable";}}
Despite the fact that your code blocks are C++, I think it would still be
best to use perl or some other scripting language to do the processing. Its
just the sort of thing scripting languages are good at.


I think you are aright. I thought about it again, and I think with
perl I could transform the template into one C++ file. The separate
compilation for each code block is just prohibitive. Instead, a perl
script could turn the text blocks into cout commands and in this way
transform the whole text template file into one source file that can
be compiled and exevuted.

Thanks
Markus
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.