Topic: deprocated streambuf class, please help
Author: surfunbear@yahoo.com (Larry)
Date: Sat, 17 Nov 2001 00:26:21 GMT Raw View
It appears that the streambuf class has changed. One of our modules
uses the following streambuf methods which appear to have been
deprocated:
allocate()
setb()
base()
out_waiting()
blen()
How can I find how to rework the code which makes quite
a number of calls to these methods ?
Will these be deporcated on aix 4.3.3 using either the visual age
compiler or xlc 3.6.6 ?
Thanks
Larry
Boston MA
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: Dietmar Kuehl <dietmar_kuehl@yahoo.com>
Date: Sat, 17 Nov 2001 23:29:32 GMT Raw View
Hi,
Larry wrote:
> It appears that the streambuf class has changed.
If you are switching from a "classical" stream buffer implementation
to a standard conforming one there are some fundatmental changes but
most of the stuff using classical streams should work nearly unchanged.
The most notable difference is that stream buffers are realised by the
class template 'std::basic_streambuf' but there is a typedef for
'std::basic_streambuf<char>' which gives it the familiar name
'std::streambuf'.
> One of our modules
> uses the following streambuf methods which appear to have been
> deprocated:
I don't know what you mean with "deprocate" (I'm not a native English
speaker and I can't find a translation of "deprocate" or "deporcate" -
you use the latter later in your article - to German). I guess you are
refering to "deprecated" features. However, none of the methods you
mentioned is deprecated in the C++ standard: A deprecated feature is
something which is present in the standard, eg. for backward
compatability with pre-standard implementation, but whose use in newly
written code is discouraged. None of the methods you list is present
in the standard or was part of the classical stream buffer interface,
AFAIK. However, some implementation has extensions using such functions.
> allocate()
> setb()
> base()
> out_waiting()
> blen()
>
>
> How can I find how to rework the code which makes quite
> a number of calls to these methods ?
The easiest approach is probably by defining an auxiliary stream buffer
class which actually defines these functions in terms of the standard
interface and derive from this class instead of from 'std::streambuf'.
Since I don't have a specification of these function, I cannot offer you
much guidance on how to replace these function. The only one I can guess
on is 'out_waiting()' assuming that it reports the number of characters
currently buffered waiting for being writting to the underlying
destination:
std::streamsize out_waiting() const { return pptr() - pbase(); }
Given a specification of the other methods it shouldn't be too hard to
come up with suitable replacements like this...
--
<mailto:dietmar_kuehl@yahoo.com> <http://www.dietmar-kuehl.de/>
Phaidros eaSE - Easy Software Engineering: <http://www.phaidros.com/>
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: surfunbear@yahoo.com (Larry)
Date: Tue, 20 Nov 2001 05:04:56 GMT Raw View
Thanks very much Dietmar,
I have found some documention on the older streambuf class which I
posted
here at the end of my code.
This is what it appears to me I have to do. We allready have
doallocate() defined. The only thing I'm not totaly sure on at the
moment is that the beggining of the reserve area returned by base()
would be my buffer, but
do the other buffer start pointers get moved by the streambuf class to
be different than the start of the reserve area. I imagine some sort
of wrapping
might happen inside the reserve area buffer and that the start
pointers could point anywhere inside of this buffer. If that's true
I'm not sure if my base()
and blen() methods would be correct.
void setb( char *base, char *ebuf)
{
setg(base,base,ebuf);
setp(base, ebuf);
};
int allocate() { return doallocate(); };
char * base() const
{
char * res;
res = eback();
if (!res)
{
res = pbase();
}
return res;
};
int out_waiting() const
{
return { pptr() - pbase(); };
}
int blen() const
{
int res;
char * ptr = eback();
char * eptr = egptr();
if (!ptr)
{
ptr = pbase();
eptr = epptr();
}
res = eptr - ptr;
return res;
};
// here's our doallocate() which is called by allocate() according to
// the streambuf documentation. the constructor of our class which
// inherts from streambuf, calls allocate().
int
EPMsgBuffer::doallocate()
{
int i;
if (iomode & ios::out)
{
if ( !(theMsg = dispatchQueue->get()) )
{
EPERROR_TAG(EP_MSG_TAG, "Dispatch queue empty.");
return 1;
}
}
else
if ( !(theMsg = receiveQueue->getFree()) )
{
EPERROR_TAG(EP_MSG_TAG, "Receive queue empty.");
return 1;
}
if (theMsg->isEOF())
{
eofPosted = TRUE;
setEOF(TRUE);
setb(theMsg->bufpt(), theMsg->bufpt());
}
else
// Set the buffer area pointers.
setb(theMsg->bufpt(), theMsg->bufpt() + theMsg->getLength());
return 0;
}
older streambuf documentation from:
http://www.pjwstk.edu.pl/~jms/qnx/help/watcom/cpplib/io_classes.html#streambuf_Class
Semantics:
The blen() protected member function reports the length of the reserve
area that the streambuf object is using.
Results:
The blen() protected member function returns the length of the reserve
area that the streambuf object is using. If the streambuf object
currently doesn't have a
reserve area, zero is returned.
Semantics:
The allocate() protected member function works in tandem with the
doallocate() protected virtual member function to manage allocation of
the streambuf
object reserve area.
Classes derived from the streambuf class should call the
allocate() protected member function, rather than the doallocate()
protected virtual
member function.
The allocate() protected member function determines whether or not the
streambuf object is allowed to allocate a buffer for use as the
reserve area. If a
reserve area already exists or if the streambuf object unbuffering
state is non-zero, the allocate() protected member function fails.
Otherwise, it calls the
doallocate() protected virtual member function.
Results:
The allocate() protected member function returns __NOT_EOF on success,
otherwise EOF is returned.
semantics:
The base() protected member function returns a pointer to the start of
the reserve area that the streambuf object is using.
Results:
The base() protected member function returns a pointer to the start of
the reserve area that the streambuf object is using. If the streambuf
object currently
doesn't have a reserve area, NULL is returned.
Semantics:
The out_waiting() public member function computes the number of
characters that have been buffered in the put area and not yet been
written to the output
device.
Results:
The out_waiting() public member function returns the number of
buffered output characters.
Semantics:
The setb() protected member function is used to set the pointers to
the reserve area that the streambuf object is using.
The base parameter is a pointer to the start of the reserve area, and
corresponds to the value that the base() member function returns.
The ebuf parameter is a pointer to the end of the reserve area, and
corresponds to the value that the ebuf() member function returns.
The autodel parameter indicates whether or not the streambuf object
can free the reserve area when the streambuf object is destroyed or
when a new
reserve area is set up in a subsequent call to the setb() protected
member function. If the autodel parameter is non-zero, the streambuf
object can delete the
reserve area, using the operator delete() intrinsic function. A zero
value indicates that the buffer will be deleted elsewhere.
If either of the base or ebuf parameters is NULL, or if ebuf <= base,
the streambuf object doesn't have a buffer, and input/output
operations are unbuffered,
unless another buffer is set up.
The setb() protected member function is used to set the
reserve area pointers, while the setbuf() protected member function is
used to offer a
buffer to the streambuf object.
Dietmar Kuehl <dietmar_kuehl@yahoo.com> wrote in message news:<3BF6C566.4010101@yahoo.com>...
> Hi,
> Larry wrote:
>
> > It appears that the streambuf class has changed.
>
>
> If you are switching from a "classical" stream buffer implementation
> to a standard conforming one there are some fundatmental changes but
> most of the stuff using classical streams should work nearly unchanged.
> The most notable difference is that stream buffers are realised by the
> class template 'std::basic_streambuf' but there is a typedef for
> 'std::basic_streambuf<char>' which gives it the familiar name
> 'std::streambuf'.
>
> > One of our modules
> > uses the following streambuf methods which appear to have been
> > deprocated:
>
>
> I don't know what you mean with "deprocate" (I'm not a native English
> speaker and I can't find a translation of "deprocate" or "deporcate" -
> you use the latter later in your article - to German). I guess you are
> refering to "deprecated" features. However, none of the methods you
> mentioned is deprecated in the C++ standard: A deprecated feature is
> something which is present in the standard, eg. for backward
> compatability with pre-standard implementation, but whose use in newly
> written code is discouraged. None of the methods you list is present
> in the standard or was part of the classical stream buffer interface,
> AFAIK. However, some implementation has extensions using such functions.
>
>
> > allocate()
> > setb()
> > base()
> > out_waiting()
> > blen()
> >
> >
> > How can I find how to rework the code which makes quite
> > a number of calls to these methods ?
>
>
> The easiest approach is probably by defining an auxiliary stream buffer
> class which actually defines these functions in terms of the standard
> interface and derive from this class instead of from 'std::streambuf'.
> Since I don't have a specification of these function, I cannot offer you
> much guidance on how to replace these function. The only one I can guess
> on is 'out_waiting()' assuming that it reports the number of characters
> currently buffered waiting for being writting to the underlying
> destination:
>
> std::streamsize out_waiting() const { return pptr() - pbase(); }
>
> Given a specification of the other methods it shouldn't be too hard to
> come up with suitable replacements like this...
> --
> <mailto:dietmar_kuehl@yahoo.com> <http://www.dietmar-kuehl.de/>
> Phaidros eaSE - Easy Software Engineering: <http://www.phaidros.com/>
>
> ---
> [ comp.std.c++ is moderated. To submit articles, try just posting with ]
> [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
> [ --- Please see the FAQ before posting. --- ]
> [ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]