Unless there is something wrong with the following complete C++ file,
I think my quest to stream-ize our code will be at an end :(
#include <sstream>
#include <iostream>
using namespace std;
class linebuf : public streambuf
{
protected:
string buffer;
public:
virtual char overflow(char c) {if(c!=EOF) buffer+=c; return c;}
virtual streamsize xsputn(const char *s, streamsize num)
{
buffer.append(s ,num); return num;
}
virtual int sync()=0;
};
typedef unsigned int uint;
typedef bool (* FTYPE)(const void *,uint,uint,uin t);
class sendbuf : public linebuf
{
public:
virtual int sync() {cout << buffer << endl; buffer.erase(); return 0;}
};
class mystream : public std::ostream
{
protected:
sendbuf buf;
public:
mystream() : std::ostream(&b uf) {}
};
int main(void)
{
mystream s;
s << "Hello, " << "world!" << flush;
return 0;
}
g++, faithful and true companion that it is, compiles and runs this as
expected with all warnings enabled. Our Borland setup, however,
compiles this into an executable that crashes. So I figure either I'm
invoking some wicked implementation-defined (or undefined!) behavior
here, or our Borland setup is fatally flawed in ways that I cannot
begin to fathom. Thanks to everyone who provided assistance during my
travails - it was a great learning experience if nothing else!
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome. 3 2313
On Fri, 27 Feb 2004 18:40:03 +0000 (UTC), Christopher Benson-Manica
<at***@nospam.c yberspace.org> wrote: Unless there is something wrong with the following complete C++ file, I think my quest to stream-ize our code will be at an end :(
#include <sstream> #include <iostream>
using namespace std;
class linebuf : public streambuf { protected: string buffer;
public: virtual char overflow(char c) {if(c!=EOF) buffer+=c; return c;} virtual streamsize xsputn(const char *s, streamsize num) { buffer.append(s ,num); return num; } virtual int sync()=0; };
typedef unsigned int uint; typedef bool (* FTYPE)(const void *,uint,uint,uin t);
class sendbuf : public linebuf { public: virtual int sync() {cout << buffer << endl; buffer.erase(); return 0;} };
class mystream : public std::ostream { protected: sendbuf buf;
public: mystream() : std::ostream(&b uf) {} };
int main(void) { mystream s;
s << "Hello, " << "world!" << flush; return 0; }
g++, faithful and true companion that it is, compiles and runs this as expected with all warnings enabled. Our Borland setup, however, compiles this into an executable that crashes. So I figure either I'm invoking some wicked implementation-defined (or undefined!) behavior here, or our Borland setup is fatally flawed in ways that I cannot begin to fathom. Thanks to everyone who provided assistance during my travails - it was a great learning experience if nothing else!
Here's what Comeau says:
stream.cpp(13): warning: function "basic_streambu f<char,
char_traits<cha r>>::overflow(
basic_streambuf <char, char_traits<cha r>>::int_type) " is hidden by
"linebuf::overf low" --
virtual function override intended?
virtual char overflow(char c) {if(c!=EOF) buffer+=c; return
c;}
^
(the caret is pointing at the start of the word "overflowa" in the last
line). Any help?
-leor
Leor Zolman
BD Software le**@bdsoft.com www.bdsoft.com -- On-Site Training in C/C++, Java, Perl & Unix
C++ users: Download BD Software's free STL Error Message
Decryptor at www.bdsoft.com/tools/stlfilt.html
Leor Zolman <le**@bdsoft.co m> spoke thus: stream.cpp(13): warning: function "basic_streambu f<char, char_traits<cha r>>::overflow( basic_streambuf <char, char_traits<cha r>>::int_type) " is hidden by "linebuf::overf low" -- virtual function override intended? virtual char overflow(char c) {if(c!=EOF) buffer+=c; return c;} ^
(the caret is pointing at the start of the word "overflowa" in the last line). Any help?
It is int_type in the code compiled by Borland - I changed it because
g++ complained...
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Christopher Benson-Manica wrote: class linebuf : public streambuf { protected: string buffer;
There is no point in making member variables protected: you could as
well make them public they become part of your interface anyway (well,
given that the size changes with a type change, in some sense even
private variables are part of the interface...). However, this is not
really your problem...
public: virtual char overflow(char c) {if(c!=EOF) buffer+=c; return c;}
This is not an override but an overload! You should use 'int_type'
or, if this causes problems, 'std::char_trai ts<char>::int_t ype'.
Using 'char' will definitely cause problems. The 'overflow()'
function would look something like this:
int_type overflow(int_ty pe c) {
if (!traits::eq_in t_type(c, traits::eof()))
buffer += traits::to_char _type(c);
return traits::not_eof (c);
}
--
<mailto:di***** ******@yahoo.co m> <http://www.dietmar-kuehl.de/>
Phaidros eaSE - Easy Software Engineering: <http://www.phaidros.co m/> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Viktor Lundström |
last post by:
Hi!
I was planning to wrap a socket inside an iostream, to achieve
something like this:
TCPSocket s(..);
s << "Hello!" << endl;
Information on the web seems to be a bit scarce on how to do this.
I have understood that there is a relation between streambuf and
iostream, where one should be able to extend streambuf and override
the underflow/overflow functions (and do send()/recv() for example).
|
by: Christopher Benson-Manica |
last post by:
This is starting to seem ridiculous to me :(
#include <streambuf>
#include <iostream>
class
TWFileStream : public std::streambuf
{
private:
char cbuf;
|
by: Fred Ma |
last post by:
Hello,
I posted previously under the thread:
How to break this up into streambuf/ostream
I've asked our library to get "C++ IOStreams and Locales..." by A.
Langer et al. Meantime, I've looked at the C++ standard (ISO/IEC
14882) from the web to get a grip on the relationship between ostream
methods and streambuf methods: flush(), operator<<(), sputc(),
|
by: Marcin Kalicinski |
last post by:
Hi,
I have a set of C-like functions for file access (like fopen, fwrite, fread,
fseek etc.). But I want to access the files using C++ stream, not these
functions. What I probably need to do is to create custom streambuf class
(am I right?).
Is there any free source code or tutorial available on how to do that? I
have googled for it, but I only found partial and untested solutions. Worse,
the solutions were pretty complicated,...
|
by: Raf256 |
last post by:
Hello,
my custom streambuf works fine with output via <<
and with input via .get()
but fails to input via >> or getline... any idea why?
--------------------
A custom stream buffer (for encryption, currently it is doing "nothing")
| |
by: smith4894 |
last post by:
Hello all,
I'm working on writing my own streambuf classes (to use in my custom
ostream/isteam classes that will handle reading/writing data to a
mmap'd file).
When reading from the mmap file, I essentially have a char buffer in my
streambuf class, that I'm registering with setp(). on an overflow()
call, I simply copy the contents of the buffer into the mmap'd file via
memcpy().
|
by: tryptik |
last post by:
All-
I have been looking at all the info I can find on deriving streambuf
objects, but I need some advice. I wish to derive a custom streambuf
that filters out c++ style comments. I have looked at the boost libs
and have attempted to impliment their filtered streambuf, but it does
not seemt o support seekg() and tellg() operations that I need.
My query is, are there any good refrerences for deriving a streambuf
that will work with...
|
by: rakesh.usenet |
last post by:
For a particular application of mine - I need a simulation of byte
array output stream.
* write data onto a stream
* getback the contiguous content as an array later for network
transport.
My code looks as follows.
#include <iostream>
|
by: Raymond Martineau |
last post by:
I have the following code segment for a class intended to split output
between cout and a file:
class SplitStream : public std::streambuf
{
std::streambuf *x;
public:
SplitStream()
{
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |