I'd like to create a "custom output facility". In other words, I want
an object whose use is similar to std::cout/std::cerr, but offers more
flexibility. Instead of simply writing the parameter to stdout/stderr,
I'd like it to write to stdout, to a file, and/or call a logging
function.
So my output function might look something like this:
OutputFacility& OutputFacility: :put(const std::string& s) {
cout << s; // print to stdout
write_to_logfil e(s); // also calling logging function
return *this;
}
Now I can define the << operator to be an alias for put().
My question is: do I have to define put() for every type of input I
expect to print? I.e., I'd like this to work with all primitive types,
int, char, double, float, etc.
Right now I'm thinking that the OutputFacility class could have a
std::ostringstr eam as a private member; every version of
OutputFacility: :put() would just in turn call the ostringstream put()
method, THEN call the actual output functions (e.g. write_to_logfil e()).
It seems like there should be a simpler method of defining my put
method, i.e. instead of overloading it and defining it multiple times,
if I could just define it once with a "magical" parameter that means
"take anything that can be converted to a string".
Thanks for any advice!
Matt
--
Matt Garman
email at: http://raw-sewage.net/index.php?file=email