473,396 Members | 1,768 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,396 software developers and data experts.

templates & reporting

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?

Thanks!
Matt

--
Matt Garman
email at: http://raw-sewage.net/index.php?file=email
Jul 23 '05 #1
1 1822
not sure if you can make use of following code,

if possible give some feedback/
Thanks
#ifndef REPORTGEN_H
#define REPORTGEN_H

#include <stdio.h>
#include <stdlib.h>

class Report {
private:
static const int MAXREPORTSTACK = 32;

static FILE *rfd[MAXREPORTSTACK];
static int tos;
static FILE *createTmp(const char *name);
Report();
public:
// Creates a new report file. Notice that if the name has the syntax
// .XXXXXX it would modify the XXXXXX for the final file name.
static void openFile(char *name);
static void field(int fn, const char *format,...);
static void field(const char *format,...);
static void close();
static void flush();
};

// Report::field("bla bla bla:",a);

#endif // REPORTGEN_H
////////================= report.cpp ================

#include <alloca.h>
#include <string.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdarg.h>
#include <ctype.h>
#include <unistd.h>

#include "nanassert.h"
#include "ReportGen.h"

FILE *Report::rfd[MAXREPORTSTACK];
int Report::tos=0;

Report::Report()
{
rfd[0]=stdout;
tos=1;
}

void Report::openFile(char *name)
{
I(tos<MAXREPORTSTACK);

FILE *ffd;

if(strstr(name, "XXXXXX")) {
int fd;

fd = mkstemp(name);

ffd = fdopen(fd, "a");
}else{
ffd = fopen(name, "a");
}

if(ffd == 0) {
fprintf(stderr, "NANASSERT::REPORT could not open temporal file [%s]\n",
name);
exit(-3);
}

rfd[tos++]=ffd;
}

void Report::close()
{
if( tos ) {
tos--;
fclose(rfd[tos]);
}
}

void Report::field(int fn, const char *format,...)
{
va_list ap;

I( fn < tos );
FILE *ffd = rfd[fn];

va_start(ap, format);

vfprintf(ffd, format, ap);

va_end(ap);

fprintf(ffd, "\n");
}

void Report::field(const char *format, ...)
{
va_list ap;

I( tos );
FILE *ffd = rfd[tos-1];

va_start(ap, format);

vfprintf(ffd, format, ap);

va_end(ap);

fprintf(ffd, "\n");
}

void Report::flush()
{
if( tos == 0 )
return;

fflush(rfd[tos-1]);
}







"Matt Garman" <fa**@not-real.bogus> wrote in message
news:sl*****************@sewage.raw-sewage.fake...
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?

Thanks!
Matt

--
Matt Garman
email at: http://raw-sewage.net/index.php?file=email

Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: SK | last post by:
Hello group, I happened to check the review of C++ Templates & Tools (By Scott Robert Ladd) at http://accu.org. The book is in the "Not recommended" category. I will like to hear if you anyone...
0
by: Amber | last post by:
I found a sample on dynamic reporting to a datagrid and exporting to excel. For those who are into reporting into Excel. This web tool allows for adhoc select statements and reports. ...
1
by: Matt Garman | last post by:
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...
5
by: Glen Richards | last post by:
I've had no success in trying to dynamically set images at runtime in a Crystal Reports 9 report using C# 2005 Beta. I've been doing research along these lines & all the posts I've read say this...
2
by: Martin Widmer | last post by:
Hi guys I am looking for the best way to generate new reports with reporting services for SQL server 2005. The reports will be generated programmatically from a .Net VB application. So far I see...
0
by: rmk | last post by:
How can I get the 2000 and 2005 versions of SQL Server Reporting Services both working on my development laptop ????? I have ASP.NET 1.1 and 2.0 installed on my laptop. I have Visual Studio...
0
by: YellowFin Announcements | last post by:
Introduction Usability and relevance have been identified as the major factors preventing mass adoption of Business Intelligence applications. What we have today are traditional BI tools that...
3
by: Szabolcs | last post by:
Consider the attached example. When I try to compile it (with g++ 4.1.2), I get the error message error: no matching function for call to 'fun(A<int>&)' However, if I do not use templates, it...
3
by: Blasting Cap | last post by:
I'm using VS 2005, SQL 2005 reporting services. SQL reporting services is working, and I have it both on my local computer, as well as on a server. I've created a report in the SQL Business...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.