473,406 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 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 2010

"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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.