Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:49

0001 // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
0002 // (C) Copyright 2003-2007 Jonathan Turkanis
0003 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0004 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
0005 
0006 // See http://www.boost.org/libs/iostreams for documentation.
0007 
0008 // Contains the definition of the template codecvt_helper, useful for
0009 // defining specializations of std::codecvt where state_type != mbstate_t.
0010 // Compensates for the fact that some standard library implementations 
0011 // do not derive the primiary codecvt template from locale::facet or 
0012 // provide the correct member types and functions.
0013 
0014 // Usage: 
0015 //
0016 // // In global namespace:
0017 // BOOST_IOSTREAMS_CODECVT_SPEC(mystate)
0018 //
0019 // // In user namespace:
0020 // template<typename Intern, typename Extern>
0021 // struct mycodecvt : codecvt_helper<Intern, Extern, State> { ... };
0022 //
0023 // // Or:
0024 // struct mycodecvt : codecvt_helper<wchar_t, char, State> { ... };
0025 // 
0026 // Etc.
0027 
0028 #ifndef BOOST_IOSTREAMS_DETAIL_CODECVT_HELPER_HPP_INCLUDED
0029 #define BOOST_IOSTREAMS_DETAIL_CODECVT_HELPER_HPP_INCLUDED
0030 
0031 #if defined(_MSC_VER)
0032 # pragma once
0033 #endif
0034 
0035 #include <boost/config.hpp>  // Put size_t in std, BOOST_MSVC, Dinkum.
0036 #include <boost/detail/workaround.hpp>
0037 #include <algorithm>         // min.
0038 #include <cstddef>           // size_t.
0039 #include <locale>            // locale, codecvt_base, codecvt.
0040 #include <boost/iostreams/detail/config/codecvt.hpp>
0041 
0042 //------------------Definition of traits--------------------------------------//
0043 
0044 namespace boost { namespace iostreams { namespace detail {
0045 
0046 #if !BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) //-----------------------//
0047 
0048 template<typename T>
0049 struct codecvt_intern { typedef typename T::intern_type type; };
0050 
0051 template<typename T>
0052 struct codecvt_extern { typedef typename T::extern_type type; };
0053 
0054 #else // #if !BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) //--------------//
0055 
0056 template<typename T>
0057 struct codecvt_intern { typedef typename T::from_type type; };
0058 
0059 template<typename T>
0060 struct codecvt_extern { typedef typename T::to_type type; };
0061 
0062 #endif // #if !BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1) //-------------//
0063 
0064 template<typename T>
0065 struct codecvt_state { typedef typename T::state_type type; };
0066 
0067 } } } // End namespaces detail, iostreams, boost.
0068 
0069 //------------------Definition of codecvt_impl--------------------------------//
0070 
0071 #if defined(BOOST_IOSTREAMS_NO_PRIMARY_CODECVT_DEFINITION) || \
0072     defined(BOOST_IOSTREAMS_EMPTY_PRIMARY_CODECVT_DEFINITION) || \
0073     defined(BOOST_IOSTREAMS_NO_LOCALE) \
0074     /**/
0075 
0076 namespace boost { namespace iostreams { namespace detail {
0077 
0078 template<typename Intern, typename Extern, typename State>
0079 struct codecvt_impl : std::locale::facet, std::codecvt_base {
0080 public:
0081     typedef Intern  intern_type;
0082     typedef Extern  extern_type;
0083     typedef State   state_type;
0084 
0085     codecvt_impl(std::size_t refs = 0) : std::locale::facet(refs) { } 
0086 
0087     std::codecvt_base::result
0088     in( State& state, const Extern* first1, const Extern* last1,
0089         const Extern*& next1, Intern* first2, Intern* last2,
0090         Intern*& next2 ) const
0091     {
0092         return do_in(state, first1, last1, next1, first2, last2, next2);
0093     }
0094 
0095     std::codecvt_base::result
0096     out( State& state, const Intern* first1, const Intern* last1,
0097          const Intern*& next1, Extern* first2, Extern* last2,
0098          Extern*& next2 ) const
0099     {
0100         return do_out(state, first1, last1, next1, first2, last2, next2);
0101     }
0102 
0103     std::codecvt_base::result
0104     unshift(State& state, Extern* first2, Extern* last2, Extern*& next2) const
0105     {
0106         return do_unshift(state, first2, last2, next2);
0107     }
0108 
0109     bool always_noconv() const throw() { return do_always_noconv(); }
0110 
0111     int max_length() const throw() { return do_max_length(); }
0112 
0113     int encoding() const throw() { return do_encoding(); }
0114 
0115     int length( BOOST_IOSTREAMS_CODECVT_CV_QUALIFIER State& state, 
0116                 const Extern* first1, const Extern* last1,
0117                 std::size_t len2 ) const throw()
0118     {
0119         return do_length(state, first1, last1, len2);
0120     }
0121 protected:
0122     std::codecvt_base::result
0123     virtual do_in( State&, const Extern*, const Extern*, const Extern*&, 
0124                    Intern*, Intern*, Intern*& ) const
0125     {
0126         return std::codecvt_base::noconv;
0127     }
0128 
0129     std::codecvt_base::result
0130     virtual do_out( State&, const Intern*, const Intern*, const Intern*&, 
0131                     Extern*, Extern*, Extern*& ) const
0132     {
0133         return std::codecvt_base::noconv;
0134     }
0135 
0136     std::codecvt_base::result
0137     virtual do_unshift(State&, Extern*, Extern*, Extern*&) const
0138     {
0139         return std::codecvt_base::ok;
0140     }
0141 
0142     virtual bool do_always_noconv() const throw() { return true; }
0143 
0144     virtual int do_max_length() const throw() { return 1; }
0145 
0146     virtual int do_encoding() const throw() { return 1; }
0147 
0148     virtual int do_length( BOOST_IOSTREAMS_CODECVT_CV_QUALIFIER State&, 
0149                            const Extern* first1, const Extern* last1,
0150                            std::size_t len2 ) const throw()
0151     {
0152         return (std::min)(static_cast<std::size_t>(last1 - first1), len2);
0153     }
0154 };
0155 
0156 } } } // End namespaces detail, iostreams, boost.
0157 
0158 #endif // no primary codecvt definition, empty definition.
0159 
0160 //------------------Definition of BOOST_IOSTREAMS_CODECVT_SPEC----------------//
0161 
0162 #if defined(BOOST_IOSTREAMS_NO_PRIMARY_CODECVT_DEFINITION) || \
0163     defined(BOOST_IOSTREAMS_EMPTY_PRIMARY_CODECVT_DEFINITION) \
0164     /**/
0165 #  define BOOST_IOSTREAMS_CODECVT_SPEC(state) \
0166     namespace std { \
0167         template<typename Intern, typename Extern> \
0168         class codecvt<Intern, Extern, state> \
0169             : public ::boost::iostreams::detail::codecvt_impl< \
0170                          Intern, Extern, state \
0171                      > \
0172         { \
0173         public: \
0174             codecvt(std::size_t refs = 0) \
0175                 : ::boost::iostreams::detail::codecvt_impl< \
0176                       Intern, Extern, state \
0177                   >(refs) \
0178                 { } \
0179             static std::locale::id id; \
0180         }; \
0181         template<typename Intern, typename Extern> \
0182         std::locale::id codecvt<Intern, Extern, state>::id; \
0183     } \
0184     /**/
0185 #else
0186 # define BOOST_IOSTREAMS_CODECVT_SPEC(state)
0187 #endif // no primary codecvt definition, or empty definition.
0188 
0189 namespace boost { namespace iostreams { namespace detail {
0190                     
0191 //------------------Definition of codecvt_helper------------------------------//
0192 
0193 template<typename Intern, typename Extern, typename State>
0194 struct codecvt_helper : std::codecvt<Intern, Extern, State> { 
0195     typedef Intern  intern_type;
0196     typedef Extern  extern_type;
0197     typedef State   state_type;
0198     codecvt_helper(std::size_t refs = 0) 
0199     #if !defined(BOOST_IOSTREAMS_NO_CODECVT_CTOR_FROM_SIZE_T)
0200         : std::codecvt<Intern, Extern, State>(refs)
0201     #else
0202         : std::codecvt<Intern, Extern, State>()
0203     #endif
0204         { }
0205 #ifdef BOOST_IOSTREAMS_NO_CODECVT_MAX_LENGTH
0206     int max_length() const throw() { return do_max_length(); }
0207 protected:
0208     virtual int do_max_length() const throw() { return 1; }
0209 #endif
0210 };
0211 
0212 } } } // End namespaces detail, iostreams, boost.
0213 
0214 #endif // #ifndef BOOST_IOSTREAMS_DETAIL_CODECVT_HELPER_HPP_INCLUDED