473,387 Members | 3,821 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,387 software developers and data experts.

Streambuf with code conversion

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkh6waMACgkQq5h2IFR18WMFrwCgv/PNAC8FTZCErvc0KHnx0zpC
KhcAnjl/xFAEJb056UdQaCZqPfnGbqA+
=0Y8B
-----END PGP SIGNATURE-----

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkh6wfUACgkQq5h2IFR18WMyvwCgpB3u8wPbtI DQgtcMfs6FpvlN
cAQAniZAOEjbtRzm3//oDQiwYdgfVytn
=iS/l
-----END PGP SIGNATURE-----

Jul 14 '08 #1
2 2166
I'm not sure if that is related. That example of yours using wcout
certainly compiles and runs fine on linux but are you saying that my
code compiles and runs fine under msvc? I lack a windows test environment.

P.S. Why still the anti HTML in usenet thing? It's the 21st century,
what wrong with a little formatting? Who nowadays uses a newsreader that
doesn't support markup?

Thanks for the reply.
--
Arcturus

Alf P. Steinbach wrote:
* Arcturus:
>I have been following Langers book for some time and am trying a
simple code conversion example without much luck. Here is the code.

Don't post HTML please.

>>
#include <iostream>
#include <ostream>
#include <streambuf>

template <class charT, class traits>
class Fcgibuf: public std::basic_streambuf<charT, traits>
{
public:
Fcgibuf() { setp(buffer, buffer+buffSize); }
virtual ~Fcgibuf() { sync(); }

protected:
typedef typename std::basic_streambuf<charT, traits>::int_type
int_type;
typedef typename std::basic_streambuf<charT, traits>::char_type
char_type;
typedef typename std::basic_streambuf<charT,
traits>::traits_type traits_type;
int_type overflow(int_type c = traits_type::eof())
{
if(emptyBuffer() < 0)
return traits_type::eof();
if(!traits_type::eq_int_type(c, traits_type::eof()))
return sputc(c);
else
return traits_type::not_eof(c);
}
int sync() { return emptyBuffer(); }

int emptyBuffer();
static const int buffSize = 8192;
char_type buffer[buffSize];
};

template <class charT, class traits>
int Fcgibuf<charT, traits>::emptyBuffer()
{
char outBuffer[buffSize];

mbstate_t conversionState;
char_type* pStreamPos;
char* toNext;
std::use_facet<std::codecvt<char_type, char, mbstate_t>
>(this->getloc()).out(conversionState, this->pptr(), this->pbase(),
pStreamPos, (char*)outBuffer, outBuffer+buffSize, toNext);
*toNext='\0';

std::cerr << outBuffer;

pbump(-(this->pptr()-this->pbase()));
return 0;
}

int main()
{
Fcgibuf<wchar_t, std::char_traits<wchar_t theBuffer;
std::basic_ostream<wchar_ttheStream(&theBuffer);

theStream << L"This is a test";

return 0;
}

Upon compiling g++ gives me the following error:

tmp.cpp: In member function ‘int Fcgibuf<charT,
traits>::emptyBuffer() [with charT = wchar_t, traits =
std::char_traits<wchar_t>]’:
tmp.cpp:25: instantiated from ‘int Fcgibuf<charT, traits>::sync()
[with charT = wchar_t, traits = std::char_traits<wchar_t>]’
tmp.cpp:10: instantiated from ‘Fcgibuf<charT, traits>::~Fcgibuf()
[with charT = wchar_t, traits = std::char_traits<wchar_t>]’
tmp.cpp:51: instantiated from here
tmp.cpp:40: error: no matching function for call to
‘std::codecvt<wchar_t, char, __mbstate_t>::out(mbstate_t&, wchar_t*,
wchar_t*, wchar_t*&, char*, char*, char*&) const’

/usr/lib/gcc/x86_64-pc-linux-gnu/4.1.2/include/g++-v4/bits/codecvt.h:121:
note: candidates are: std::codecvt_base::result
std::__codecvt_abstract_base<_InternT, _ExternT,
_StateT>::out(_StateT&, const _InternT*, const _InternT*, const
_InternT*&, _ExternT*, _ExternT*, _ExternT*&) const [with _InternT =
wchar_t, _ExternT = char, _StateT = __mbstate_t]

This error message doesn't make very much sense to me as the candidate
seems identical to the actual function call. Can anybody shed some
light on this?

Hm.

<example>
V:\testgnuc x.cpp
x.cpp: In member function `int Fcgibuf<charT, traits>::emptyBuffer()
[with charT = wchar_t, traits = std::char_traits<wchar_t>]':
x.cpp:25: instantiated from `int Fcgibuf<charT, traits>::sync() [with
charT = wchar_t, traits = std::char_traits<wchar_t>]'
x.cpp:10: instantiated from `Fcgibuf<charT, traits>::~Fcgibuf() [with
charT = wchar_t, traits = std::char_traits<wchar_t>]'
x.cpp:51: instantiated from here
x.cpp:40: error: no matching function for call to `std::codecvt<wchar_t,
char, mbstate_t>::out(mbstate_t&, wchar_t*, wchar_t*, wchar_t*&, char*,
char*, char*&) const'
c:/program
files/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/3.4.5/bits/codecvt.h:125:
note: candidates are: std::codecvt_base::result
std::__codecvt_abstract_base<_InternT, _ExternT, _StateT>::out(_StateT&,
const _InternT*,
const _InternT*, const _InternT*&, _ExternT*, _ExternT*, _ExternT*&)
const [with _InternT = wchar_t, _ExternT = char, _StateT = mbstate_t]

V:\testmsvc x.cpp
x.cpp

V:\test_
</example>

Dunno, but I suspect it's the same reason or related reason that

#include <iostream>
int main()
{
std::wcout << L"Bah" << std::endl;
}

fails with MinGW g++ for Windows.
Cheers, & hth.,

- Alf

Jul 14 '08 #2
Regarding the issue. I have solved it by changing char_type* pStreamPos;
to const char_type* pStreamPos; The call was casting a non-const
reference to a const reference which obviously shouldn't work which
makes it even more interesting that it compiled under msvc.
That's curious, remarkable, since you're top-posting and using HTML,
which is only acceptable and common in Microsoft groups, the microsoft.*
hierarchy. One would tend to think that you're coming from a Microsoft
environment, brainwashed by that culture. Anyways, don't top-post, and
also please don't post HTML, don't quote extraneous material, don't
quote signatures, and please read the FAQ.
My lack of usenet skills is a result of my rarely using it; not my
operating system choice. I've been in the nix world as long as I can
remember and honestly have never even been exposed to this culture you
speak of. For both of our benefits I will return to staying away from
usenet. This experience is strangely reminiscent of my past experiences
here: no one capable of answering real questions but plenty of people
capable of criticizing posting style. I personally like reading syntax
highlighted code and thought others might appreciate it. That opinion
may ostracize me but it appears as though I'm not missing much. I
thought I might have something to contribute here but it seems usenet is
still ruled but the same arcane bunch as 20 years past. Thanks for the
help and see you in ~five years.
--
Arcturus
Jul 15 '08 #3

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

Similar topics

5
by: Christopher Benson-Manica | last post by:
Yes, it's me again, with my dear, dear friends std::streambuf and std::ostream... On the bright side, the code compiles. On the gloomy side, I can't seem to get overflow() or xsputn() called... ...
9
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...
9
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...
2
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...
7
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...
4
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. ...
4
by: mathieu | last post by:
Hello, Browsing the archive of this group I see that the c++ iostream wrapper that are shipped with zlib are not satisfying : ...
10
by: hsmit.home | last post by:
Hi everyone, I'm having some difficulty with the following piece of code. I have stripped it to it's bare minimum to demonstrate the problem at hand. Compiler: MS Visual C++ 2005 Express...
3
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() {
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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...

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.