473,327 Members | 2,074 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,327 software developers and data experts.

fstreams and rolling files

bob
Hi,

I have a requirement to "roll" a logfile in a GUI. Namely as each
write to the file occurs, I need to do some filtering (not relevant
here) and then stream the message contents to a graphical user
interface.

Ideally, I would like a callback object/function be to be called each
time a write occurs to the file associated with the stream. Ive
checked about and I cant really see anything out of the box.

I see that there is a "ios_base::register_callback" method available
however i don't think thats what I'm looking for. It provides the
following events, copyfmt_event, erase_event and imbue_event. I don't
think any of these trigger the registered function to be called when a
"write" to the stream occurs.

Perhaps I need to look at a different structure/object. In any case,
I'd be grateful if anybody could direct me to the correct approach for
getting notified each time a write to the file occurs.

thanks much and have a nice day

GrahamO

Nov 14 '07 #1
2 1537
bo*@blah.com wrote:
I have a requirement to "roll" a logfile in a GUI. Namely as each
write to the file occurs, I need to do some filtering (not relevant
here) and then stream the message contents to a graphical user
interface.

Ideally, I would like a callback object/function be to be called each
time a write occurs to the file associated with the stream. Ive
checked about and I cant really see anything out of the box.

I see that there is a "ios_base::register_callback" method available
however i don't think thats what I'm looking for. It provides the
following events, copyfmt_event, erase_event and imbue_event. I don't
think any of these trigger the registered function to be called when a
"write" to the stream occurs.

Perhaps I need to look at a different structure/object. In any case,
I'd be grateful if anybody could direct me to the correct approach for
getting notified each time a write to the file occurs.
if istream (or ifstream) doesn't provide it can't you wrap
a stream up in a class that does do what you want?

Assuming Filter and Gui_writer are function pointers
or functors. This also means you don't have to
splatter platform specific code all over your application.

class Log_decorator
{
public:
Log_decorator (std::ostream& file, Filter& filter, Gui_writer&
gui_writer):
file_(file), filter_(filter), gui_writer_(gui_writer)
{}

ostream& operator<< (const std::string& txt)
{
file_ << txt;
if (filter_(txt))
gui_writer(txt);
}

private:
std::ostream& file_;
Filter& filter_;
Gui_writer& gui_writer_;
}
--
Nick Keighley
Nov 15 '07 #2
On Nov 14, 12:32 pm, "b...@blah.com" <GrahamJWa...@gmail.comwrote:
I have a requirement to "roll" a logfile in a GUI. Namely as each
write to the file occurs, I need to do some filtering (not relevant
here) and then stream the message contents to a graphical user
interface.
Ideally, I would like a callback object/function be to be called each
time a write occurs to the file associated with the stream. Ive
checked about and I cant really see anything out of the box.
I see that there is a "ios_base::register_callback" method available
however i don't think thats what I'm looking for. It provides the
following events, copyfmt_event, erase_event and imbue_event. I don't
think any of these trigger the registered function to be called when a
"write" to the stream occurs.
Perhaps I need to look at a different structure/object. In any
case, I'd be grateful if anybody could direct me to the
correct approach for getting notified each time a write to the
file occurs.
The usual solution here is to use some sort of ostream wrapper.
Basically, a class which contains some sort of ostream, and has
template operator<< members to forward all operations to the
ostream, but which can be used as a temporary, and whose
destructor will do whatever actions you want on "write".

If you're targetting a GUI, the object would probably contain an
std::ostringstream to collect the information, with the
destructor then doing whatever is necessary to cause it to
display on the screen. More generally, however, I'd use a
standard ostream, with a custom streambuf, whose sync() function
did the necessary work; the destructor of your wrapper object
would then call sync.

Most of the time, you'll want to return the wrapper object from
a function, so the user can write something like:
log( severity ) << "a = " << a ;
In that case, the wrapper needs to be copiable, and you'll need
some sort of counting so that only the last destructor does
anything.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Nov 15 '07 #3

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

Similar topics

0
by: deko | last post by:
I use this script to keep count of visits to my site - it's on every page in the site. <?php $file = '/home/post/public_html/viscount'; if ($counter = @file ($file)) { $line = each($counter);...
5
by: traga_2_whiskys | last post by:
Weel i want do make a box with text rolling down to up, i've make-it wiht <marquee> in html, byt the text isn't always rolling. can anibody help me?
1
by: Gaurav Sharma | last post by:
Hi Is there an upper limit to the number of file streams that can simultaneously be open? Pointers to resources will be welcome. Thank you. --Gaurav
2
by: Lilith | last post by:
I've been working on a program in VC++. The basic operation of the system I'm working with is that I create a file in on directory, the system picks it up and generates a report in another...
3
by: DB2 Convert | last post by:
Hi, Correct me if I am wrong? Why should I specify at the restore statement such as Restore Database ABC ... "WITHOUT ROLLING FOWARD"? My understand is when I am using circular logging,...
3
by: db2group88 | last post by:
we are using db2 udb v8.2 on windows. All our tables are created with "not logged initially" parameter. Our application with auto commit on. I would like to do an online backup and rolling forward...
0
by: PeteCresswell | last post by:
The one I would up was a pivot table presentation" Fund Year ReturnForYear ReturnForYearPlusPreceedingYear, ReturnForYearPlusTwoPreceedingYears.....and so-forth. But that design compromise...
101
by: Elijah Cardon | last post by:
Let's say I have m dice having n sides, such that n^m is not going to bust int as a datatype. With m=4 and n=6, an outcome might be {2, 5, 1, 2}. What is a good way to represent this in c so that...
17
by: Jose Durazo | last post by:
Hello, I'm doing an exercise to simulate rolling a pair of dice 36,000 times, then count and display how many times the simulation rolls each possible sum. For some reason each time I run my...
3
by: farhadtarapore | last post by:
I have a very large C++ application that has been converted into a windows service. This application writes a lot of statements to the console i.e. cout and cerr. I have used std::ofstream...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.