Streambuf with code conversion

A

Arcturus

-----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

iEYEARECAAYFAkh6wfUACgkQq5h2IFR18WMyvwCgpB3u8wPbtIDQgtcMfs6FpvlN
cAQAniZAOEjbtRzm3//oDQiwYdgfVytn
=iS/l
-----END PGP SIGNATURE-----
 
A

Arcturus

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
* 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 said:
(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_t> theStream(&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>::eek:ut(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>::eek:ut(_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:\test> gnuc 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>::eek:ut(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>::eek:ut(_StateT&,
const _InternT*,
const _InternT*, const _InternT*&, _ExternT*, _ExternT*, _ExternT*&)
const [with _InternT = wchar_t, _ExternT = char, _StateT = mbstate_t]

V:\test> msvc 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
 
A

Arcturus

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top