Streambuf with code conversion

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Arcturus

    Streambuf with code conversion

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

    iEYEARECAAYFAkh 6waMACgkQq5h2IF R18WMFrwCgv/PNAC8FTZCErvc0K Hnx0zpC
    KhcAnjl/xFAEJb056UdQaCZ qPfnGbqA+
    =0Y8B
    -----END PGP SIGNATURE-----

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

    iEYEARECAAYFAkh 6wfUACgkQq5h2IF R18WMyvwCgpB3u8 wPbtIDQgtcMfs6F pvlN
    cAQAniZAOEjbtRz m3//oDQiwYdgfVytn
    =iS/l
    -----END PGP SIGNATURE-----

  • Arcturus

    #2
    Re: Streambuf with code conversion

    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_stre ambuf<charT, traits>
    > {
    > public:
    > Fcgibuf() { setp(buffer, buffer+buffSize ); }
    > virtual ~Fcgibuf() { sync(); }
    >>
    > protected:
    > typedef typename std::basic_stre ambuf<charT, traits>::int_ty pe
    >int_type;
    > typedef typename std::basic_stre ambuf<charT, traits>::char_t ype
    >char_type;
    > typedef typename std::basic_stre ambuf<charT,
    >traits>::trait s_type traits_type;
    > int_type overflow(int_ty pe c = traits_type::eo f())
    > {
    > if(emptyBuffer( ) < 0)
    > return traits_type::eo f();
    > if(!traits_type ::eq_int_type(c , traits_type::eo f()))
    > return sputc(c);
    > else
    > return traits_type::no t_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>::emptyB uffer()
    > {
    > char outBuffer[buffSize];
    >>
    > mbstate_t conversionState ;
    > char_type* pStreamPos;
    > char* toNext;
    > std::use_facet< std::codecvt<ch ar_type, char, mbstate_t>
    >(this->getloc()).out( conversionState , this->pptr(), this->pbase(),
    >pStreamPos, (char*)outBuffe r, outBuffer+buffS ize, toNext);
    > *toNext='\0';
    >>
    > std::cerr << outBuffer;
    >>
    > pbump(-(this->pptr()-this->pbase()));
    > return 0;
    > }
    >>
    > int main()
    > {
    > Fcgibuf<wchar_t , std::char_trait s<wchar_t theBuffer;
    > std::basic_ostr eam<wchar_ttheS tream(&theBuffe r);
    >>
    > 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>::emptyB uffer() [with charT = wchar_t, traits =
    > std::char_trait s<wchar_t>]’:
    > tmp.cpp:25: instantiated from ‘int Fcgibuf<charT, traits>::sync()
    > [with charT = wchar_t, traits = std::char_trait s<wchar_t>]’
    > tmp.cpp:10: instantiated from ‘Fcgibuf<charT, traits>::~Fcgib uf()
    > [with charT = wchar_t, traits = std::char_trait s<wchar_t>]’
    > tmp.cpp:51: instantiated from here
    > tmp.cpp:40: error: no matching function for call to
    > ‘std::codecvt<w char_t, char, __mbstate_t>::o 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_ba se::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>::emptyB uffer()
    [with charT = wchar_t, traits = std::char_trait s<wchar_t>]':
    x.cpp:25: instantiated from `int Fcgibuf<charT, traits>::sync() [with
    charT = wchar_t, traits = std::char_trait s<wchar_t>]'
    x.cpp:10: instantiated from `Fcgibuf<charT, traits>::~Fcgib uf() [with
    charT = wchar_t, traits = std::char_trait s<wchar_t>]'
    x.cpp:51: instantiated from here
    x.cpp:40: error: no matching function for call to `std::codecvt<w char_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_ba se::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
    >
    >

    Comment

    • Arcturus

      #3
      Re: Streambuf with code conversion

      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

      Comment

      Working...