Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
Message from discussion Should I derive from ostrstream?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Jerry Coffin  
View profile  
 More options Nov 13 1995, 3:00 am
Newsgroups: comp.lang.c++
From: jcof...@rmii.com (Jerry Coffin)
Date: 1995/11/13
Subject: Re: Should I derive from ostrstream?

ad...@rzaix13.uni-hamburg.de (Bernd Eggink) wrote:

[ ... ]

>>  the original poster wants to do two very simple things:
>>    - assemble a database query using the shift operators
>>    - read the result provided from the database using the shift operators
>Maybe you can read thoughts; I can't. From the posters first article,
>I can only see that he wants his class to behave like an ostrstream.
>Apparently there is a reason for it: He already has a function
>'execute' which interprets a string as a database query. He didn't
>say a word about reading the result from the database. If he really
>means what you said, deriving from streambuf is clearly the right
>thing. If he just means what he said, notice that my approach is
>MUCH shorter than yours. There are at maximum 20 shift operator
>functions to write (in fact, I think he'll need less than 10),
>and by using a macro this can be done in about 1 minute.

If size of implementation enters into the question, I think simply
implementing this as a manipulator for ostrstream would be by far the
shortest code:

ostrstream &execute(ostrstream &s)
{
    do_execute(s.str());
    s.rdbuf()->freeze(0);
    return s;

}

ostrstream &operator<<(ostrstream &s,ostrstream &(*m)(ostrstream &s))
{
    return m(s);

}

used something like:

ostrstream x;
// Please forgive me if  my SQL is wrong...
x << "select " << fields << "from " << database << execute;

I'm not sure I'd consider this _better_ than deriving a new class, but
I'm quite certain it's shorter than any derivation based approach can
hope to be.  I guess I'd consider it an open question whether derivation
provided any advantages to justify the extra work.
    Later,
    Jerry.

/* I can barely express my own opinions; I certainly can't
 * express anybody else's.
 *
 * The universe is a figment of its own imagination.
 */


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.