xref: /netbsd-src/external/gpl3/gcc.old/dist/libstdc++-v3/include/std/codecvt (revision 8feb0f0b7eaff0608f8350bbfa3098827b4bb91b)
11debfc3dSmrg// <codecvt> -*- C++ -*-
21debfc3dSmrg
3*8feb0f0bSmrg// Copyright (C) 2015-2020 Free Software Foundation, Inc.
41debfc3dSmrg//
51debfc3dSmrg// This file is part of the GNU ISO C++ Library.  This library is free
61debfc3dSmrg// software; you can redistribute it and/or modify it under the
71debfc3dSmrg// terms of the GNU General Public License as published by the
81debfc3dSmrg// Free Software Foundation; either version 3, or (at your option)
91debfc3dSmrg// any later version.
101debfc3dSmrg
111debfc3dSmrg// This library is distributed in the hope that it will be useful,
121debfc3dSmrg// but WITHOUT ANY WARRANTY; without even the implied warranty of
131debfc3dSmrg// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
141debfc3dSmrg// GNU General Public License for more details.
151debfc3dSmrg
161debfc3dSmrg// Under Section 7 of GPL version 3, you are granted additional
171debfc3dSmrg// permissions described in the GCC Runtime Library Exception, version
181debfc3dSmrg// 3.1, as published by the Free Software Foundation.
191debfc3dSmrg
201debfc3dSmrg// You should have received a copy of the GNU General Public License and
211debfc3dSmrg// a copy of the GCC Runtime Library Exception along with this program;
221debfc3dSmrg// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
231debfc3dSmrg// <http://www.gnu.org/licenses/>.
241debfc3dSmrg
251debfc3dSmrg// ISO C++ 14882: 22.5  Standard code conversion facets
261debfc3dSmrg
271debfc3dSmrg/** @file include/codecvt
281debfc3dSmrg *  This is a Standard C++ Library header.
291debfc3dSmrg */
301debfc3dSmrg
311debfc3dSmrg#ifndef _GLIBCXX_CODECVT
321debfc3dSmrg#define _GLIBCXX_CODECVT 1
331debfc3dSmrg
341debfc3dSmrg#pragma GCC system_header
351debfc3dSmrg
361debfc3dSmrg#if __cplusplus < 201103L
371debfc3dSmrg# include <bits/c++0x_warning.h>
381debfc3dSmrg#else
391debfc3dSmrg
401debfc3dSmrg#include <bits/locale_classes.h>
411debfc3dSmrg#include <bits/codecvt.h>
421debfc3dSmrg
431debfc3dSmrgnamespace std _GLIBCXX_VISIBILITY(default)
441debfc3dSmrg{
451debfc3dSmrg_GLIBCXX_BEGIN_NAMESPACE_VERSION
461debfc3dSmrg
471debfc3dSmrg  enum codecvt_mode
481debfc3dSmrg  {
491debfc3dSmrg    consume_header = 4,
501debfc3dSmrg    generate_header = 2,
511debfc3dSmrg    little_endian = 1
521debfc3dSmrg  };
531debfc3dSmrg
541debfc3dSmrg  template<typename _Elem, unsigned long _Maxcode = 0x10ffff,
551debfc3dSmrg	   codecvt_mode _Mode = (codecvt_mode)0>
561debfc3dSmrg    class codecvt_utf8 : public codecvt<_Elem, char, mbstate_t>
571debfc3dSmrg    {
581debfc3dSmrg    public:
591debfc3dSmrg      explicit
601debfc3dSmrg      codecvt_utf8(size_t __refs = 0);
611debfc3dSmrg
621debfc3dSmrg      ~codecvt_utf8();
631debfc3dSmrg    };
641debfc3dSmrg
651debfc3dSmrg  template<typename _Elem, unsigned long _Maxcode = 0x10ffff,
661debfc3dSmrg	   codecvt_mode _Mode = (codecvt_mode)0>
671debfc3dSmrg    class codecvt_utf16 : public codecvt<_Elem, char, mbstate_t>
681debfc3dSmrg    {
691debfc3dSmrg    public:
701debfc3dSmrg      explicit
711debfc3dSmrg      codecvt_utf16(size_t __refs = 0);
721debfc3dSmrg
731debfc3dSmrg      ~codecvt_utf16();
741debfc3dSmrg    };
751debfc3dSmrg
761debfc3dSmrg  template<typename _Elem, unsigned long _Maxcode = 0x10ffff,
771debfc3dSmrg	   codecvt_mode _Mode = (codecvt_mode)0>
781debfc3dSmrg    class codecvt_utf8_utf16 : public codecvt<_Elem, char, mbstate_t>
791debfc3dSmrg    {
801debfc3dSmrg    public:
811debfc3dSmrg      explicit
821debfc3dSmrg      codecvt_utf8_utf16(size_t __refs = 0);
831debfc3dSmrg
841debfc3dSmrg      ~codecvt_utf8_utf16();
851debfc3dSmrg    };
861debfc3dSmrg
871debfc3dSmrg#define _GLIBCXX_CODECVT_SPECIALIZATION2(_NAME, _ELEM) \
881debfc3dSmrg  template<> \
891debfc3dSmrg    class _NAME<_ELEM> \
901debfc3dSmrg    : public codecvt<_ELEM, char, mbstate_t> \
911debfc3dSmrg    { \
921debfc3dSmrg    public: \
931debfc3dSmrg      typedef _ELEM			intern_type; \
941debfc3dSmrg      typedef char			extern_type; \
951debfc3dSmrg      typedef mbstate_t			state_type; \
961debfc3dSmrg \
971debfc3dSmrg    protected: \
981debfc3dSmrg      _NAME(unsigned long __maxcode, codecvt_mode __mode, size_t __refs) \
991debfc3dSmrg      : codecvt(__refs), _M_maxcode(__maxcode), _M_mode(__mode) { } \
1001debfc3dSmrg \
1011debfc3dSmrg      virtual \
1021debfc3dSmrg      ~_NAME(); \
1031debfc3dSmrg \
1041debfc3dSmrg      virtual result \
1051debfc3dSmrg      do_out(state_type& __state, const intern_type* __from, \
1061debfc3dSmrg	     const intern_type* __from_end, const intern_type*& __from_next, \
1071debfc3dSmrg	     extern_type* __to, extern_type* __to_end, \
1081debfc3dSmrg	     extern_type*& __to_next) const; \
1091debfc3dSmrg \
1101debfc3dSmrg      virtual result \
1111debfc3dSmrg      do_unshift(state_type& __state, \
1121debfc3dSmrg		 extern_type* __to, extern_type* __to_end, \
1131debfc3dSmrg		 extern_type*& __to_next) const; \
1141debfc3dSmrg \
1151debfc3dSmrg      virtual result \
1161debfc3dSmrg      do_in(state_type& __state, \
1171debfc3dSmrg	     const extern_type* __from, const extern_type* __from_end, \
1181debfc3dSmrg	     const extern_type*& __from_next, \
1191debfc3dSmrg	     intern_type* __to, intern_type* __to_end, \
1201debfc3dSmrg	     intern_type*& __to_next) const; \
1211debfc3dSmrg \
1221debfc3dSmrg      virtual \
1231debfc3dSmrg      int do_encoding() const throw(); \
1241debfc3dSmrg \
1251debfc3dSmrg      virtual \
1261debfc3dSmrg      bool do_always_noconv() const throw(); \
1271debfc3dSmrg \
1281debfc3dSmrg      virtual \
1291debfc3dSmrg      int do_length(state_type&, const extern_type* __from, \
1301debfc3dSmrg		    const extern_type* __end, size_t __max) const; \
1311debfc3dSmrg \
1321debfc3dSmrg      virtual int \
1331debfc3dSmrg      do_max_length() const throw(); \
1341debfc3dSmrg \
1351debfc3dSmrg    private: \
1361debfc3dSmrg      unsigned long	_M_maxcode; \
1371debfc3dSmrg      codecvt_mode	_M_mode; \
1381debfc3dSmrg    }
1391debfc3dSmrg
1401debfc3dSmrg#define _GLIBCXX_CODECVT_SPECIALIZATION(_NAME, _ELEM) \
1411debfc3dSmrg  _GLIBCXX_CODECVT_SPECIALIZATION2(__ ## _NAME ## _base, _ELEM); \
1421debfc3dSmrg  template<unsigned long _Maxcode, codecvt_mode _Mode> \
1431debfc3dSmrg    class _NAME<_ELEM, _Maxcode, _Mode> \
1441debfc3dSmrg    : public __ ## _NAME ## _base<_ELEM> \
1451debfc3dSmrg    { \
1461debfc3dSmrg    public: \
1471debfc3dSmrg      explicit \
1481debfc3dSmrg      _NAME(size_t __refs = 0) \
1491debfc3dSmrg      : __ ## _NAME ## _base<_ELEM>(std::min(_Maxcode, 0x10fffful), \
1501debfc3dSmrg				    _Mode, __refs) \
1511debfc3dSmrg      { } \
1521debfc3dSmrg    }
1531debfc3dSmrg
1541debfc3dSmrg  template<typename _Elem> class __codecvt_utf8_base;
1551debfc3dSmrg  template<typename _Elem> class __codecvt_utf16_base;
1561debfc3dSmrg  template<typename _Elem> class __codecvt_utf8_utf16_base;
1571debfc3dSmrg
1581debfc3dSmrg  _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8, char16_t);
1591debfc3dSmrg  _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf16, char16_t);
1601debfc3dSmrg  _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8_utf16, char16_t);
1611debfc3dSmrg
1621debfc3dSmrg  _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8, char32_t);
1631debfc3dSmrg  _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf16, char32_t);
1641debfc3dSmrg  _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8_utf16, char32_t);
1651debfc3dSmrg
1661debfc3dSmrg#ifdef _GLIBCXX_USE_WCHAR_T
1671debfc3dSmrg  _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8, wchar_t);
1681debfc3dSmrg  _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf16, wchar_t);
1691debfc3dSmrg  _GLIBCXX_CODECVT_SPECIALIZATION(codecvt_utf8_utf16, wchar_t);
1701debfc3dSmrg#endif
1711debfc3dSmrg
1721debfc3dSmrg_GLIBCXX_END_NAMESPACE_VERSION
1731debfc3dSmrg} // namespace
1741debfc3dSmrg
175c0a68be4Smrg#endif // C++11
1761debfc3dSmrg
1771debfc3dSmrg#endif /* _GLIBCXX_CODECVT */
178