472,780 Members | 1,416 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,780 software developers and data experts.

Text templates: "embedded c++"

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
2 1976

"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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Michael Ransburg | last post by:
Hello! I've got the following XML "template" (for example). <personalData> <address> <name>$var1</name> <zip>$var2</name> </address> <telephone type=$var3>$var4</telephone>
7
by: Jukka K. Korpela | last post by:
No, I'm not making this up, this is what http://www.w3.org/ says when accessed with a text browser, or in any decent browser in no-images mode: "Tim Berners-Lee smiling 2003-12-31: Buckingham...
3
by: Generic Usenet Account | last post by:
This is a two-part question. (1) I have implemented a "Datastructure Registry" template class. I am getting no compiler warnings with older compilers, but newer compilers are generating the...
0
by: Morten Overgaard | last post by:
Hi Anybody knows how to save an "embedded object" from the clipboard to a file with the correct filename ( can it be extracted from the clipboard ??) And How do I do it vice versa... ...
5
by: Kivak Wolf | last post by:
Hey everyone, I have a textbox in my web page that is going to be used to enter an E-mail into (just plain text, no HTML). Now, this will interact with a SQL database where the contents of the...
4
by: sods | last post by:
Hi, I write a test code about template used for strategy. it's very similar to sample code in TC++PL 13.4.1. #include <iostream> #include <string> using std::basic_string;
4
by: Sacha | last post by:
I'm aware, that up to date, "typedef templates" are not defined within the C++ standard. The seemingly common workaround is this: template <class T> struct MyTypeDef { /* ultimately I need...
6
by: Bruce Adcock | last post by:
Hi, I have run across the some strange syntax, to which I do not understand the meaning: const char* xmlHeader = {"<?xml"}; (specifically, this can be found in "tinyxmlparse.cpp", Line 828,...
0
by: Steven Prasil | last post by:
When I start my VisualStudio 2005 it creates automatically new folders: D:\work\Visual Studio 2005 D:\work\Visual Studio 2005\Projects D:\work\Visual Studio 2005\Templates Yes, in VS menu ...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.