Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Where can I find documentation about the internals of cout?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
DeMarcus  
View profile   Translate to Translated (View Original)
 More options 7 Nov, 15:21
Newsgroups: comp.lang.c++.moderated
From: DeMarcus <use_my_alias_h...@hotmail.com>
Date: Sat, 7 Nov 2009 09:21:46 CST
Local: Sat 7 Nov 2009 15:21
Subject: Where can I find documentation about the internals of cout?
Hi!

I'm writing my own codecvt but can't find out when (or if) cout is
calling codecvt.unshift().

I've vacuum cleaned the net and also tried to Google www.open-std.org
without any result.

Is there anyone that knows where to find documentation whether cout is
using codecvt.unshift() or if I can leave that method unimplemented in
my custom codecvt?

Thanks,
Daniel

--
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
dietmar_kuehl@yahoo.com  
View profile   Translate to Translated (View Original)
 More options 10 Nov, 02:43
Newsgroups: comp.lang.c++.moderated
From: "dietmar_ku...@yahoo.com" <dietmar.ku...@gmail.com>
Date: Mon, 9 Nov 2009 20:43:55 CST
Local: Tues 10 Nov 2009 02:43
Subject: Re: Where can I find documentation about the internals of cout?
Hi!

On 7 Nov, 15:21, DeMarcus <use_my_alias_h...@hotmail.com> wrote:

> I'm writing my own codecvt but can't find out when (or if) cout is
> calling codecvt.unshift().

Unsurprising, there isn't any response so far. So let me give a quick
one: the C++ standard doesn't require 'std::cout' to be implemented in
terms of 'std::filebuf'. 'std::filebuf' (or, to be more precise, the
class template 'std::basic_filbuf') is the only class which makes use
of the facet 'std::codecvt'. Hence, whether 'std::cout' uses
'std::codecvt' or not is already up in the air and I can see
reasonable implementations either way with some bias of implementing
the standard stream objects using specialized stream buffers (at
least, this is the way I did it).

That said, you need to understand what the 'unshift()' does and when
it used to determine whether you'll need to implement a non-default
behavior for it. The purpose of 'unshift()' is to return the stream to
some sort of initial shift state. This can mean multiple things but
typically it inserts a set of bytes which undo any kind of earlier
change setting the byte stream up to interpret bytes different than in
the initial state. For example, in an encoding the initial state may
represent Latin characters and a shift state may shift the
interpretation to use German characters instead. The current state
would be stored in some form in the 'mbstate_t' and 'unshift()' would
produce whatever byte sequence is needed to return the interpretation
of bytes back to Latin characters. This function is essentially used
in two situations:

1. When seeking on a stream, the current shift state is undone before actually
    seeking (and seeking into a byte sequence after the bytes moving it into a
    shift state is likely to cause havoc to the byte's interpretation).
2. When terminating a stream the shift state is undone to cleanly terminate the
    sequence.

> Is there anyone that knows where to find documentation whether cout is
> using codecvt.unshift() or if I can leave that method unimplemented in
> my custom codecvt?

The answer to this question is as above: I know that 'std::cout' is
not required to use 'std::codecvt' at all and hence isn't required to
use 'unshift()' at all. What this means for the standard C++ library
implementation you are using, nobody but the implementer of this
particular library can tell.

--
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
DeMarcus  
View profile   Translate to Translated (View Original)
 More options 10 Nov, 21:32
Newsgroups: comp.lang.c++.moderated
From: DeMarcus <use_my_alias_h...@hotmail.com>
Date: Tue, 10 Nov 2009 15:32:18 CST
Local: Tues 10 Nov 2009 21:32
Subject: Re: Where can I find documentation about the internals of cout?

>> I'm writing my own codecvt but can't find out when (or if) cout is
>> calling codecvt.unshift().

> Unsurprising, there isn't any response so far. So let me give a quick
> one: the C++ standard doesn't require 'std::cout' to be implemented in
> terms of 'std::filebuf'. 'std::filebuf' (or, to be more precise, the
> class template 'std::basic_filbuf') is the only class which makes use
> of the facet 'std::codecvt'. Hence, whether 'std::cout' uses
> 'std::codecvt' or not is already up in the air and I can see
> reasonable implementations either way with some bias of implementing
> the standard stream objects using specialized stream buffers (at
> least, this is the way I did it).

That doesn't sound too comfortable. May I just double check? If I write
code like this:

std::ios::sync_with_stdio( false );

std::locale myLocale( std::locale::classic(), new MyCodeCvt() );
std::cout.imbue( myLocale );

then does this still mean I cannot be sure MyCodeCvt will be used??

If the answer is; I still cannot be sure, then what's the simplest
solution? Is it to implement my own cout built on std::filebuf?

Thanks,
Daniel

--
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
dietmar_kuehl@yahoo.com  
View profile   Translate to Translated (View Original)
 More options 11 Nov, 05:14
Newsgroups: comp.lang.c++.moderated
From: "dietmar_ku...@yahoo.com" <dietmar.ku...@gmail.com>
Date: Tue, 10 Nov 2009 23:14:05 CST
Local: Wed 11 Nov 2009 05:14
Subject: Re: Where can I find documentation about the internals of cout?
On Nov 10, 9:32 pm, DeMarcus <use_my_alias_h...@hotmail.com> wrote:

Yes, this accurate: there is no guarantee that 'std::cout' uses a
'std::filebuf'. It may or it may not. It may use your code conversion
facet or it may not.

> If the answer is; I still cannot be sure, then what's the simplest
> solution? Is it to implement my own cout built on std::filebuf?

If you want to create a 'std::filebuf' which writes to the same
destination as 'std::cout' you will need to resort to platform
specific approaches. ... and even this can be interesting! For
example, if the 'std::filebuf' class doesn't have a constructor taking
a file descriptor and you are actually writing to pipe on a UNIX
system, you are pretty much out of luck. Once you have a
'std::streambuf' writing to the same destination as 'std::cout' you
can redirect 'std::cout' to write to this stream buffer instead. Even
this isn't entirely trivial, however, as you will either need to make
sure that your stream buffer lives long enough or the stream buffer
used originally by 'std::cout' is restored. A simple but non-portable
approach which may work could look like this:

   std::cout.rdbuf(new std::filebuf(1));

This would cause one file buffer not being reclaimed at the end of the
program but should otherwise work - assuming '1' is the file
descriptor referring to the standard output destination and
'std::filebuf' has a non-standard constructor.

--
      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google