templates & reporting

Discussion in 'C Programming' started by Matt Garman, Apr 7, 2005.

  1. Matt Garman

    Matt Garman Guest

    Is there a generally accepted means of generating reports in C
    and/or C++?

    In particular, I have an application with many parameterized text
    strings that get displayed to a user. These could be as simple as
    "The value of x is 19.2134", to a lengthy paragraph describing
    something in detail.

    The strings may appear in plain text form, or need to be put into a
    structured document for nicer formatting (e.g. HTML).

    The quick and dirty way to accomplish what I want is to just have
    inline code, ala

    fprintf(report_file, "The value of x is %lf\n", x);

    Obviously, if there are any number of these types of reports, it
    becomes a maintenance nightmare.

    I'd like to keep my raw verbage (e.g. "The value of x is ") in some
    type of separate data source (i.e. not part of the source code). Be
    it individual plain text files, XML data or even a database, is
    fine---it's the mechanism that cleanly (and flexibly) ties the
    verbage to the parameters generated by the program.

    Scripting languages tend to support this type of thing very
    well---particularly PHP, where I can imbed variables in HTML
    templates pretty easily.

    I'd like this to be relatively simple as well. Some ideas I've had
    are along the lines of having a "store" (database, flat files, XML,
    etc) of strings, and the strings have special codes to represent
    variable data.

    For example, I might have a file that contains this:

    The value of x is ::VARIABLE_X::

    And write some function or class that would know to replace
    "::VARIABLE_X::" with something appropriate.

    But even with this "solution", the text store has to know something
    about the code and/or the code has to know something about the info
    contained in the text store.

    I'd like as clean a separation between the text store and the code
    as possible.

    Anyone have any suggestions on ways to achieve something like this?


    Matt Garman
    email at: http://raw-sewage.net/index.php?file=email
    Matt Garman, Apr 7, 2005
    1. Advertisements

  2. Matt Garman wrote:
    > Is there a generally accepted means of generating reports in C
    > and/or C++?

    <snip />

    > I'd like to keep my raw verbage (e.g. "The value of x is ") in some
    > type of separate data source (i.e. not part of the source code).

    This is OT and so I shouldn't reply here, but I can't find the
    OPs personal email addr.

    I don't know about "generally accepted", but here's a method that
    works for me:

    Assuming you are writing a web-based program (ie. it communicates
    with an http server and outputs (x)html), you can use a simple
    templating engine such as Flate[1] to produce the desired effect.

    This involves inserting specially marked comments and text into
    the html to produce a "template". Flate allows variables to be
    defined as follows:


    After loading the template with a call to templateSetFile (),
    you can set var using templateSetVar (). However, as you point
    out, the code then has to know about the variables defined in
    the template. To overcome this, I use a shell script and some
    m4 macro definitions that replace dummy variable names with the
    real ones in both code and template.


    [1] http://flate.dead-inside.org
    Ralph A. Moeritz, Apr 8, 2005
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fred
    Sep 26, 2005
  2. John Harrison

    using templates in templates

    John Harrison, Jul 31, 2003, in forum: C++
    Torsten Curdt
    Jul 31, 2003
  3. JKop
  4. Matt Garman

    templates & reporting

    Matt Garman, Apr 7, 2005, in forum: C++
    Jianli Shen
    Apr 8, 2005
  5. recover
    Jul 25, 2006

Share This Page