Text templates: "embedded c++"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Markus Dehmann

    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 "LetterDataCont ainer.hpp"
    using namespace std;
    LetterDataConta iner 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.get Amount() >
    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
  • John Harrison

    #2
    Re: Text templates: &quot;embedd ed c++&quot;


    "Markus Dehmann" <markus.cl@gmx. de> wrote in message
    news:c1e48b51.0 405141547.3a312 fb9@posting.goo gle.com...[color=blue]
    > 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 "LetterDataCont ainer.hpp"
    > using namespace std;
    > LetterDataConta iner 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.get Amount() >
    > 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[/color]

    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


    Comment

    • Markus Dehmann

      #3
      Re: Text templates: &quot;embedd ed c++&quot;

      "John Harrison" <john_andronicu s@hotmail.com> wrote in message news:<2glt1mF45 f67U1@uni-berlin.de>...[color=blue]
      > "Markus Dehmann" <markus.cl@gmx. de> wrote in message
      > news:c1e48b51.0 405141547.3a312 fb9@posting.goo gle.com...[color=green]
      > > 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 "LetterDataCont ainer.hpp"
      > > using namespace std;
      > > LetterDataConta iner 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.get Amount() >
      > > 1000){cout << " considerable";} </C> amount of money. Please pay
      > > <C>cout << d.getUrgency(); </C>.
      > > --------TEXT TEMPLATE--------[/color][/color]
      [color=blue][color=green]
      > > 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";} }
      > >[/color][/color]
      [color=blue]
      > 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.[/color]

      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

      Comment

      Working...