Boost logo

Boost :

From: Robert Ramey (ramey_at_[hidden])
Date: 2002-11-23 01:28:16


> From: Alberto Barbati <abarbati_at_[hidden]>
> One note: the library, as it is, *does not* support Unicode output, as
> stated.
> [snip]

    Well I quadriple checked and ran your example and of course you are right.
    The text archive eliminated the high order byte. I have addressed the problem with the code below.
    Naturally there is an analogous alteration in the output archive.
    My reasoning is as follws
    text files created/read as part of serialzation are not designed to be read/interpreted by
    humans. The important thing is that the store all the data and recover it without
    alteration. Since archives might be passed accross locales, all serlialzation files
    should use the same locale. Of course that locale should correctly support
    wide characters and not alter the data. The text should be "embeddible" in
    other texts. So the system is:
    Open the archive
    save the current locale
    create a new locale
            classic + override for codecvt facet to supress code conversion

    use archive
    OnClose restore previous locale.
    
    This seems to me to address the issues of wide characters.
    
    Robert Ramey
    
    /////////////////////////////////////////////////////////////////////////
    // class text_iarchive - read serialized objects from a input text stream
    template<class Stream, class Elem>
    class text_iarchive : public basic_iarchive
    {
    private:
            class codecvt : public std::codecvt<Elem, char, mbstate_t>
            {
                    virtual bool do_always_noconv( ) const{
                            return true;
                    }
            public:
                    codecvt() : std::codecvt<Elem, char, mbstate_t>(1) {};
            } archive_codecvt;
            // locale when stream was passed here
            std::locale previous_locale;
            // use special local for serialization - no character conversion
            std::locale archive_locale;
            // stream which contains the archive
            Stream &is;
    public:
            virtual void init(){
                    basic_iarchive::init();
            }
            text_iarchive(Stream &_is) :
                    is(_is),
                    archive_locale(
                            std::locale::classic(),
                            &archive_codecvt
                    )
            {
                    // archives always use classic locale
                    #ifndef BOOST_NO_STD_LOCALE
                    previous_locale = is.imbue(archive_locale);
                    #endif
                    init();
            }
            ~text_iarchive(){
                    #ifndef BOOST_NO_STD_LOCALE
                    is.imbue(previous_locale);
                    #endif
            }
    

- Done.

 

attached mail follows:


Date: Tue, 12 Nov 2002 23:07:19 +0100
From: Alberto Barbati <abarbati_at_[hidden]>

One note: the library, as it is, *does not* support Unicode output, as
stated.
[snip]

Well I quadriple checked and ran your example and of course you are right.

The text archive eliminated the high order byte. I have addressed the problem with the code below.
Naturally there is an analogous alteration in the output archive.

My reasoning is as follws

text files created/read as part of serialzation are not designed to be read/interpreted by
humans. The important thing is that the store all the data and recover it without
alteration. Since archives might be passed accross locales, all serlialzation files
should use the same locale. Of course that locale should correctly support
wide characters and not alter the data. The text should be "embeddible" in
other texts. So the system is:

Open the archive
save the current locale
create a new locale
        classic + override for codecvt facet to supress code conversion
use archive
OnClose restore previous locale.

This seems to me to address the issues of wide characters.

Robert Ramey

/////////////////////////////////////////////////////////////////////////
// class text_iarchive - read serialized objects from a input text stream
template<class Stream, class Elem>
class text_iarchive : public basic_iarchive
{
private:
        class codecvt : public std::codecvt<Elem, char, mbstate_t>
        {
                virtual bool do_always_noconv( ) const{
                        return true;
                }
        public:
                codecvt() : std::codecvt<Elem, char, mbstate_t>(1) {};
        } archive_codecvt;
        // locale when stream was passed here
        std::locale previous_locale;
        // use special local for serialization - no character conversion
        std::locale archive_locale;
        // stream which contains the archive
        Stream &is;
public:
        virtual void init(){
                basic_iarchive::init();
        }
        text_iarchive(Stream &_is) :
                is(_is),
                archive_locale(
                        std::locale::classic(),
                        &archive_codecvt
                )
        {
                // archives always use classic locale
                #ifndef BOOST_NO_STD_LOCALE
                previous_locale = is.imbue(archive_locale);
                #endif
                init();
        }
        ~text_iarchive(){
                #ifndef BOOST_NO_STD_LOCALE
                is.imbue(previous_locale);
                #endif
        }


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk