|
Boost : |
Subject: Re: [boost] [iostreams][io_state_savers] Request for interest in some ios_base basic utilities
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2011-11-10 15:20:55
Le 10/11/11 20:44, Artyom Beilis a écrit :
> --- On Thu, 11/10/11, Vicente Botet<vicente.botet_at_[hidden]> wrote:
>
>> From: Vicente Botet<vicente.botet_at_[hidden]>
>>> This makes sure that if somebody links with the
>> library the
>>> static ids (facet's ids) and static variables
>> allocated
>>> with xalloc are installed.
>>>
>> Oh, I see. Unfortunately this technique can not be applied
>> when the library
>> is header-only, isn't it?
>>
>>
> Not... but you can use anonymous namespace
> and it would work but it is little big ugly.
>
>
>>> But you can fallback to default if facet is not
>> installed, i.e.:
>>> if(!have_facet<foo>(loc))
>>> // Do something as std::locale::classic
>> dooes
>>> else
>>> use_facet<foo>(loc).bar(...)
>>>
>>> Same for configuration. Ugly but useful for high level
>> functions.
>> Yes, this is a good technique so that imbuing is not done
>> by the library,
>> only by the user. However this technique doesn't solves the
>> multi-threaded imbuing issue.
> But I don't expect from user to change locale in a stream and use
> it in same time?!
>
> In any case you can do:
>
> try {
> foo const&f =use_facet<foo>(f);
> // do required
> }
> catch(std::bad_cast const&) {
> // do default
> }
I'm missing surely something. Recall, I'm a beginner. How do you ensure
that any stream has associated a locale that contains your facet?
>>> For non ICU based facets, there is no such problem.
>>>
>> I guess we can define always immutable facets that
>> reference a mutable
>> storage. Facet should be lightweight so that the creation
>> doesn't takes too
>> much time.
> No actually, it is not. facets are not generated frequently.
> locale is cheap to copy because facets are reference counted
> so you create facet once and use it for long time. For example
> messages facet can load dictionaries convert their encoding,
> it is by no means cheap. But you create it once and then
> reuse it.
>
>
How do you reach to reuse them.
For example if we use a string stream we will need to add the facet. I
guess that this operation will not take too much time, and in any case I
expect it to load a dictionary that has already been loaded. So I
suspect that the facet should only contain a key identifying the
dictionary or a reference to it.
Vicente
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk