epoc32/include/stdapis/stlportv5/stl/_codecvt.h
author William Roberts <williamr@symbian.org>
Wed, 31 Mar 2010 12:33:34 +0100
branchSymbian3
changeset 4 837f303aceeb
parent 3 e1b950c65cb4
permissions -rw-r--r--
Current Symbian^3 public API header files (from PDK 3.0.h)
This is the epoc32/include tree with the "platform" subtrees removed, and
all but a selected few mbg and rsg files removed.
     1 /*
     2  * Portions Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
     3  *
     4  * Copyright (c) 1999
     5  * Silicon Graphics Computer Systems, Inc.
     6  *
     7  * Copyright (c) 1999
     8  * Boris Fomitchev
     9  *
    10  * This material is provided "as is", with absolutely no warranty expressed
    11  * or implied. Any use is at your own risk.
    12  *
    13  * Permission to use or copy this software for any purpose is hereby granted
    14  * without fee, provided the above notices are retained on all copies.
    15  * Permission to modify the code and to distribute modified code is granted,
    16  * provided the above notices are retained, and a notice that the code was
    17  * modified is included with the above copyright notice.
    18  *
    19  */
    20 // WARNING: This is an internal header file, included by other C++
    21 // standard library headers.  You should not attempt to use this header
    22 // file directly.
    23 
    24 
    25 #ifndef _STLP_INTERNAL_CODECVT_H
    26 #define _STLP_INTERNAL_CODECVT_H
    27 
    28 #ifndef _STLP_C_LOCALE_H
    29 #  include <stl/c_locale.h>
    30 #endif
    31 
    32 #ifndef _STLP_INTERNAL_LOCALE_H
    33 #  include <stl/_locale.h>
    34 #endif
    35 
    36 #ifndef _STLP_INTERNAL_ALGOBASE_H
    37 #  include <stl/_algobase.h>
    38 #endif
    39 
    40 _STLP_BEGIN_NAMESPACE
    41 
    42 class _STLP_CLASS_DECLSPEC codecvt_base {
    43 public:
    44   enum result {ok, partial, error, noconv};
    45 };
    46 
    47 template <class _InternT, class _ExternT, class _StateT>
    48 class codecvt : public locale::facet, public codecvt_base {
    49 public:
    50   typedef _InternT intern_type;
    51   typedef _ExternT extern_type;
    52   typedef _StateT state_type;
    53 
    54 #if defined (_STLP_MSVC) && (_STLP_MSVC < 1300)
    55   /* For the moment VC6 do not support this facet default implementation
    56    * because of the static locale::id instance. When VC6 see this definition
    57    * it goes crasy with locale::id static instances and all the has_facet tests
    58    * unit tests are failing.
    59    */
    60 };
    61 #else
    62   explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}
    63 
    64   result out(state_type&          __state,
    65              const intern_type*   __from,
    66              const intern_type*   __from_end,
    67              const intern_type*&  __from_next,
    68              extern_type*         __to,
    69              extern_type*         __to_limit,
    70              extern_type*&        __to_next) const {
    71     return do_out(__state,
    72                   __from, __from_end, __from_next,
    73                   __to,   __to_limit, __to_next);
    74   }
    75 
    76   result unshift(state_type&    __state,
    77                  extern_type*   __to,
    78                  extern_type*   __to_limit,
    79                  extern_type*&  __to_next) const {
    80     return do_unshift(__state, __to, __to_limit, __to_next);
    81   }
    82 
    83   result in(state_type&         __state,
    84             const extern_type*  __from,
    85             const extern_type*  __from_end,
    86             const extern_type*& __from_next,
    87             intern_type*        __to,
    88             intern_type*        __to_limit,
    89             intern_type*&       __to_next) const {
    90     return do_in(__state,
    91                  __from, __from_end, __from_next,
    92                  __to,  __to_limit, __to_next);
    93   }
    94 
    95   int encoding() const _STLP_NOTHROW { return do_encoding(); }
    96 
    97   bool always_noconv() const _STLP_NOTHROW { return do_always_noconv(); }
    98 
    99   int length(const state_type&  __state,
   100              const extern_type* __from,
   101              const extern_type* __end,
   102              size_t             __max) const {
   103     return do_length(__state, __from, __end, __max);
   104   }
   105 
   106   int max_length() const _STLP_NOTHROW { return do_max_length(); }
   107 
   108 #if defined(__SYMBIAN32__WSD__) 
   109     static _STLP_STATIC_MEMBER_DECLSPEC locale::id& GetFacetLocaleId();
   110 #elif defined (__SYMBIAN32__NO_STATIC_IMPORTS__)    
   111     static _STLP_STATIC_MEMBER_DECLSPEC locale::id& GetFacetLocaleId();
   112     static locale::id id;   
   113 #else        
   114     // NOTE: Symbian doesn't support exporting static data.  
   115     // Users of this class should use GetFacetLocaleId() to access the data member id    
   116     static _STLP_STATIC_MEMBER_DECLSPEC locale::id id;
   117 #endif
   118 
   119     
   120 protected:
   121   ~codecvt() {}
   122 
   123   virtual result do_out(state_type&,
   124                         const intern_type*  __from,
   125                         const intern_type*,
   126                         const intern_type*& __from_next,
   127                         extern_type*        __to,
   128                         extern_type*,
   129                         extern_type*&       __to_next) const
   130   { __from_next = __from; __to_next   = __to; return noconv; }
   131 
   132   virtual result do_in (state_type&,
   133                         const extern_type*  __from,
   134                         const extern_type*,
   135                         const extern_type*& __from_next,
   136                         intern_type*        __to,
   137                         intern_type*,
   138                         intern_type*&       __to_next) const
   139   { __from_next = __from; __to_next = __to; return noconv; }
   140 
   141   virtual result do_unshift(state_type&,
   142                             extern_type* __to,
   143                             extern_type*,
   144                             extern_type*& __to_next) const
   145   { __to_next = __to; return noconv; }
   146 
   147   virtual int do_encoding() const _STLP_NOTHROW
   148   { return 1; }
   149 
   150   virtual bool do_always_noconv() const _STLP_NOTHROW
   151   { return true; }
   152 
   153   virtual int do_length(const state_type&,
   154                         const extern_type* __from,
   155                         const extern_type* __end,
   156                         size_t __max) const
   157   { return (int)(min) ( __STATIC_CAST(size_t, (__end - __from)), __max); }
   158 
   159   virtual int do_max_length() const _STLP_NOTHROW
   160   { return 1; }
   161 
   162 private:
   163   codecvt(const codecvt<intern_type, extern_type, state_type>&);
   164   codecvt<intern_type, extern_type, state_type>& operator = (const codecvt<intern_type, extern_type, state_type>&);
   165 };
   166 
   167 #  if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
   168 #    if (_STLP_STATIC_TEMPLATE_DATA > 0)
   169 #      if !defined (__BORLANDC__) && !defined(__SYMBIAN32__WSD__)
   170 template <class _InternT, class _ExternT, class _StateT>
   171 locale::id codecvt<_InternT, _ExternT, _StateT>::id;
   172 #      endif
   173 #    endif
   174 #  endif
   175 #endif
   176 
   177 template <class _InternT, class _ExternT, class _StateT>
   178 class codecvt_byname : public codecvt<_InternT, _ExternT, _StateT> {};
   179 
   180 _STLP_TEMPLATE_NULL
   181 class _STLP_CLASS_DECLSPEC codecvt<char, char, mbstate_t>
   182   : public locale::facet, public codecvt_base
   183 {
   184   friend class _Locale_impl;
   185 
   186 public:
   187   typedef char       intern_type;
   188   typedef char       extern_type;
   189   typedef mbstate_t  state_type;
   190 
   191   explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}
   192 
   193   result out(mbstate_t&   __state,
   194              const char*  __from,
   195              const char*  __from_end,
   196              const char*& __from_next,
   197              char*        __to,
   198              char*        __to_limit,
   199              char*&       __to_next) const {
   200     return do_out(__state,
   201                   __from, __from_end, __from_next,
   202                   __to,   __to_limit, __to_next);
   203   }
   204 
   205   result unshift(mbstate_t& __state,
   206                  char* __to, char* __to_limit, char*& __to_next) const
   207     { return do_unshift(__state, __to, __to_limit, __to_next); }
   208 
   209   result in(state_type&   __state,
   210             const char*  __from,
   211             const char*  __from_end,
   212             const char*& __from_next,
   213             char*        __to,
   214             char*        __to_limit,
   215             char*&       __to_next) const {
   216     return do_in(__state,
   217                  __from, __from_end, __from_next,
   218                  __to,   __to_limit, __to_next);
   219   }
   220 
   221   int encoding() const _STLP_NOTHROW { return do_encoding(); }
   222 
   223   bool always_noconv() const _STLP_NOTHROW { return do_always_noconv(); }
   224 
   225   int length(const state_type& __state,
   226              const char* __from, const char* __end,
   227              size_t __max) const
   228     { return do_length(__state, __from, __end, __max); }
   229 
   230   int max_length() const _STLP_NOTHROW { return do_max_length(); }
   231 #if defined(__SYMBIAN32__WSD__) 
   232   static _STLP_STATIC_MEMBER_DECLSPEC locale::id& GetFacetLocaleId();
   233 #elif defined (__SYMBIAN32__NO_STATIC_IMPORTS__)    
   234     static _STLP_STATIC_MEMBER_DECLSPEC locale::id& GetFacetLocaleId();
   235     static locale::id id;     
   236 #else
   237   // NOTE: Symbian doesn't support exporting static data.  
   238   // Users of this class should use GetFacetLocaleId() to access the data member id    
   239   static _STLP_STATIC_MEMBER_DECLSPEC locale::id id;
   240 #endif
   241 protected:
   242   _STLP_DECLSPEC ~codecvt();
   243 
   244   _STLP_DECLSPEC virtual result do_out(mbstate_t&   /* __state */,
   245                         const char*  __from,
   246                         const char*  /* __from_end */,
   247                         const char*& __from_next,
   248                         char*        __to,
   249                         char*        /* __to_limit */,
   250                         char*&       __to_next) const;
   251 
   252   _STLP_DECLSPEC virtual result do_in (mbstate_t&   /* __state */ ,
   253                         const char*  __from,
   254                         const char*  /* __from_end */,
   255                         const char*& __from_next,
   256                         char*        __to,
   257                         char*        /* __to_end */,
   258                         char*&       __to_next) const;
   259 
   260   _STLP_DECLSPEC virtual result do_unshift(mbstate_t& /* __state */,
   261                             char*      __to,
   262                             char*      /* __to_limit */,
   263                             char*&     __to_next) const;
   264 
   265   _STLP_DECLSPEC virtual int do_encoding() const _STLP_NOTHROW;
   266   _STLP_DECLSPEC virtual bool do_always_noconv() const _STLP_NOTHROW;
   267   _STLP_DECLSPEC virtual int do_length(const mbstate_t&         __state,
   268                         const  char* __from,
   269                         const  char* __end,
   270                         size_t __max) const;
   271   _STLP_DECLSPEC virtual int do_max_length() const _STLP_NOTHROW;
   272 private:
   273   codecvt(const codecvt<char, char, mbstate_t>&);
   274   codecvt<char, char, mbstate_t>& operator =(const codecvt<char, char, mbstate_t>&);
   275 };
   276 
   277 # ifndef _STLP_NO_WCHAR_T
   278 
   279 _STLP_TEMPLATE_NULL
   280 class _STLP_CLASS_DECLSPEC codecvt<wchar_t, char, mbstate_t>
   281   : public locale::facet, public codecvt_base
   282 {
   283   friend class _Locale_impl;
   284 public:
   285   typedef wchar_t    intern_type;
   286   typedef char       extern_type;
   287   typedef mbstate_t  state_type;
   288 
   289   explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}
   290 
   291   result out(mbstate_t&      __state,
   292              const wchar_t*  __from,
   293              const wchar_t*  __from_end,
   294              const wchar_t*& __from_next,
   295              char*           __to,
   296              char*           __to_limit,
   297              char*&          __to_next) const {
   298     return do_out(__state,
   299                   __from, __from_end, __from_next,
   300                   __to,   __to_limit, __to_next);
   301   }
   302 
   303   result unshift(mbstate_t& __state,
   304                  char*  __to, char*  __to_limit, char*& __to_next) const {
   305     return do_unshift(__state, __to, __to_limit, __to_next);
   306   }
   307 
   308   result in(mbstate_t&   __state,
   309             const char*  __from,
   310             const char*  __from_end,
   311             const char*& __from_next,
   312             wchar_t*     __to,
   313             wchar_t*     __to_limit,
   314             wchar_t*&    __to_next) const {
   315     return do_in(__state,
   316                  __from, __from_end, __from_next,
   317                  __to,   __to_limit, __to_next);
   318   }
   319 
   320   int encoding() const _STLP_NOTHROW { return do_encoding(); }
   321 
   322   bool always_noconv() const _STLP_NOTHROW { return do_always_noconv(); }
   323 
   324   int length(const mbstate_t& __state,
   325              const char* __from, const char* __end,
   326              size_t __max) const
   327     { return do_length(__state, __from, __end, __max); }
   328 
   329   int max_length() const _STLP_NOTHROW { return do_max_length(); }
   330 #if defined(__SYMBIAN32__WSD__) 
   331   static _STLP_STATIC_MEMBER_DECLSPEC locale::id& GetFacetLocaleId();
   332 #elif defined (__SYMBIAN32__NO_STATIC_IMPORTS__)    
   333   static _STLP_STATIC_MEMBER_DECLSPEC locale::id& GetFacetLocaleId();
   334   static locale::id id;   
   335 #else
   336   // NOTE: Symbian doesn't support exporting static data.  
   337   // Users of this class should use GetFacetLocaleId() to access the data member id  
   338   static _STLP_STATIC_MEMBER_DECLSPEC locale::id id;
   339 #endif
   340 protected:
   341   _STLP_DECLSPEC ~codecvt();
   342 
   343   _STLP_DECLSPEC virtual result do_out(mbstate_t&         __state,
   344                         const wchar_t*  __from,
   345                         const wchar_t*  __from_end,
   346                         const wchar_t*& __from_next,
   347                         char*        __to,
   348                         char*        __to_limit,
   349                         char*&       __to_next) const;
   350 
   351   _STLP_DECLSPEC virtual result do_in (mbstate_t&         __state,
   352                         const char*  __from,
   353                         const char*  __from_end,
   354                         const char*& __from_next,
   355                         wchar_t*        __to,
   356                         wchar_t*        __to_limit,
   357                         wchar_t*&       __to_next) const;
   358 
   359   _STLP_DECLSPEC virtual result do_unshift(mbstate_t&   __state,
   360                             char*  __to,
   361                             char*  __to_limit,
   362                             char*& __to_next) const;
   363 
   364   _STLP_DECLSPEC virtual int do_encoding() const _STLP_NOTHROW;
   365 
   366   _STLP_DECLSPEC virtual bool do_always_noconv() const _STLP_NOTHROW;
   367 
   368   _STLP_DECLSPEC virtual int do_length(const mbstate_t& __state,
   369                         const  char* __from,
   370                         const  char* __end,
   371                         size_t __max) const;
   372 
   373   _STLP_DECLSPEC virtual int do_max_length() const _STLP_NOTHROW;
   374 
   375 private:
   376   codecvt(const codecvt<wchar_t, char, mbstate_t>&);
   377   codecvt<wchar_t, char, mbstate_t>& operator = (const codecvt<wchar_t, char, mbstate_t>&);
   378 };
   379 
   380 # endif
   381 
   382 _STLP_TEMPLATE_NULL
   383 class _STLP_CLASS_DECLSPEC codecvt_byname<char, char, mbstate_t>
   384   : public codecvt<char, char, mbstate_t> {
   385 public:
   386   _STLP_DECLSPEC explicit codecvt_byname(const char* __name, size_t __refs = 0);
   387   _STLP_DECLSPEC ~codecvt_byname();
   388 private:
   389   codecvt_byname(const codecvt_byname<char, char, mbstate_t>&);
   390   codecvt_byname<char, char, mbstate_t>& operator =(const codecvt_byname<char, char, mbstate_t>&);
   391 };
   392 
   393 # ifndef _STLP_NO_WCHAR_T
   394 _STLP_TEMPLATE_NULL
   395 class _STLP_CLASS_DECLSPEC codecvt_byname<wchar_t, char, mbstate_t>
   396   : public codecvt<wchar_t, char, mbstate_t>
   397 {
   398 public:
   399   _STLP_DECLSPEC explicit codecvt_byname(const char * __name, size_t __refs = 0, _Locale_name_hint* __hint = 0);
   400 
   401 protected:
   402   _STLP_DECLSPEC ~codecvt_byname();
   403 
   404   _STLP_DECLSPEC virtual result do_out(mbstate_t&         __state,
   405                         const wchar_t*  __from,
   406                         const wchar_t*  __from_end,
   407                         const wchar_t*& __from_next,
   408                         char*        __to,
   409                         char*        __to_limit,
   410                         char*&       __to_next) const;
   411 
   412   _STLP_DECLSPEC virtual result do_in (mbstate_t&         __state,
   413                         const char*  __from,
   414                         const char*  __from_end,
   415                         const char*& __from_next,
   416                         wchar_t*        __to,
   417                         wchar_t*        __to_limit,
   418                         wchar_t*&       __to_next) const;
   419 
   420   _STLP_DECLSPEC virtual result do_unshift(mbstate_t&   __state,
   421                             char*  __to,
   422                             char*  __to_limit,
   423                             char*& __to_next) const;
   424 
   425   _STLP_DECLSPEC virtual int do_encoding() const _STLP_NOTHROW;
   426 
   427   _STLP_DECLSPEC virtual bool do_always_noconv() const _STLP_NOTHROW;
   428 
   429   _STLP_DECLSPEC virtual int do_length(const mbstate_t&         __state,
   430                         const  char* __from,
   431                         const  char* __end,
   432                         size_t __max) const;
   433 
   434   _STLP_DECLSPEC virtual int do_max_length() const _STLP_NOTHROW;
   435 
   436 private:
   437   _Locale_ctype* _M_ctype;
   438   codecvt_byname(const codecvt_byname<wchar_t, char, mbstate_t>&);
   439   codecvt_byname<wchar_t, char, mbstate_t>& operator =(const codecvt_byname<wchar_t, char, mbstate_t>&);
   440 };
   441 
   442 # endif
   443 
   444 _STLP_END_NAMESPACE
   445 
   446 #endif /* _STLP_INTERNAL_CODECVT_H */
   447 
   448 // Local Variables:
   449 // mode:C++
   450 // End:
   451