build/stlport/src/message_facets.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/build/stlport/src/message_facets.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,152 @@
     1.4 +/*
     1.5 + * Copyright (c) 1999
     1.6 + * Silicon Graphics Computer Systems, Inc.
     1.7 + *
     1.8 + * Copyright (c) 1999
     1.9 + * Boris Fomitchev
    1.10 + *
    1.11 + * This material is provided "as is", with absolutely no warranty expressed
    1.12 + * or implied. Any use is at your own risk.
    1.13 + *
    1.14 + * Permission to use or copy this software for any purpose is hereby granted
    1.15 + * without fee, provided the above notices are retained on all copies.
    1.16 + * Permission to modify the code and to distribute modified code is granted,
    1.17 + * provided the above notices are retained, and a notice that the code was
    1.18 + * modified is included with the above copyright notice.
    1.19 + *
    1.20 + */
    1.21 +#ifndef MESSAGE_FACETS_H
    1.22 +#define MESSAGE_FACETS_H
    1.23 +
    1.24 +#include <string>
    1.25 +#include <locale>
    1.26 +#include <hash_map>
    1.27 +
    1.28 +#include "c_locale.h"
    1.29 +
    1.30 +_STLP_BEGIN_NAMESPACE
    1.31 +_STLP_MOVE_TO_PRIV_NAMESPACE
    1.32 +
    1.33 +// Class _Catalog_locale_map.  The reason for this is that, internally,
    1.34 +// a message string is always a char*.  We need a ctype facet to convert
    1.35 +// a string to and from wchar_t, and the user is permitted to provide such
    1.36 +// a facet when calling open().
    1.37 +
    1.38 +struct _Catalog_locale_map {
    1.39 +  _Catalog_locale_map() : M(0) {}
    1.40 +  ~_Catalog_locale_map() { if (M) delete M; }
    1.41 +
    1.42 +  void insert(nl_catd_type key, const locale& L);
    1.43 +  locale lookup(nl_catd_type key) const;
    1.44 +  void erase(nl_catd_type key);
    1.45 +
    1.46 +  typedef hash_map<nl_catd_type, locale, hash<nl_catd_type>, equal_to<nl_catd_type>, 
    1.47 +                   allocator<pair<_STLP_CONST nl_catd_type, locale> > > map_type;
    1.48 +  map_type *M;
    1.49 +
    1.50 +private:                        // Invalidate copy constructor and assignment
    1.51 +  _Catalog_locale_map(const _Catalog_locale_map&);
    1.52 +  void operator=(const _Catalog_locale_map&);
    1.53 +};
    1.54 +
    1.55 +/*
    1.56 + * In glibc nl_catd type is void *, but messages_base::catalog is defined as int
    1.57 + * by ISO/IEC 14882; The int may be too short to store pointer on 64-bit platforms;
    1.58 + * Another problem, is that do_open() may return negative value to indicate that no
    1.59 + * catalog open---this case can't be represented with pointers.
    1.60 + * The class _Catalog_nl_catd_map intended to make relation between
    1.61 + * messages_base::catalog and nl_catd handler.
    1.62 + *
    1.63 + */
    1.64 +
    1.65 +#if defined (_STLP_USE_GLIBC2_LOCALIZATION)
    1.66 +#  define _STLP_USE_NL_CATD_MAPPING
    1.67 +#else
    1.68 +/* If no mapping a message_base::catalog entry, int typedef according C++ Standard 22.2.7.1,
    1.69 + * has to be large enough to contain a nl_catd_type value.
    1.70 + */
    1.71 +_STLP_STATIC_ASSERT(sizeof(nl_catd_type) <= sizeof(int))
    1.72 +#endif
    1.73 +
    1.74 +class _STLP_CLASS_DECLSPEC _Catalog_nl_catd_map {
    1.75 +public:
    1.76 +  _Catalog_nl_catd_map()
    1.77 +  {}
    1.78 +  ~_Catalog_nl_catd_map()
    1.79 +  {}
    1.80 +
    1.81 +  typedef hash_map<messages_base::catalog, nl_catd_type, hash<messages_base::catalog>, equal_to<messages_base::catalog>,
    1.82 +                   allocator<pair<_STLP_CONST messages_base::catalog, nl_catd_type> > > map_type;
    1.83 +  typedef hash_map<nl_catd_type, messages_base::catalog, hash<nl_catd_type>, equal_to<nl_catd_type>,
    1.84 +                   allocator<pair<_STLP_CONST nl_catd_type, messages_base::catalog> > > rmap_type;
    1.85 +  // typedef map<messages_base::catalog,nl_catd_type> map_type;
    1.86 +  // typedef map<nl_catd_type,messages_base::catalog> rmap_type;
    1.87 +
    1.88 +  messages_base::catalog insert(nl_catd_type cat)
    1.89 +#if !defined (_STLP_USE_NL_CATD_MAPPING)
    1.90 +  { return (messages_base::catalog)cat; }
    1.91 +#else
    1.92 +  ;
    1.93 +#endif
    1.94 +
    1.95 +  void erase(messages_base::catalog)
    1.96 +#if !defined (_STLP_USE_NL_CATD_MAPPING)
    1.97 +  {}
    1.98 +#else
    1.99 +  ;
   1.100 +#endif
   1.101 +
   1.102 +  nl_catd_type operator [] ( messages_base::catalog cat )
   1.103 +#if !defined (_STLP_USE_NL_CATD_MAPPING)
   1.104 +  { return cat; }
   1.105 +#else
   1.106 +  { return cat < 0 ? 0 : M[cat]; }
   1.107 +#endif
   1.108 +
   1.109 +private:
   1.110 +  _Catalog_nl_catd_map(const _Catalog_nl_catd_map&);
   1.111 +  _Catalog_nl_catd_map& operator =(const _Catalog_nl_catd_map&);
   1.112 +
   1.113 +#if defined (_STLP_USE_NL_CATD_MAPPING)
   1.114 +  map_type M;
   1.115 +  rmap_type Mr;
   1.116 +  static _STLP_VOLATILE __stl_atomic_t _count;
   1.117 +#endif
   1.118 +};
   1.119 +
   1.120 +class _Messages {
   1.121 +public:
   1.122 +  typedef messages_base::catalog catalog;
   1.123 +
   1.124 +  _Messages(bool, const char *name);
   1.125 +  _Messages(bool, _Locale_messages*);
   1.126 +
   1.127 +  catalog do_open(const string& __fn, const locale& __loc) const;
   1.128 +  string do_get(catalog __c, int __set, int __msgid,
   1.129 +                const string& __dfault) const;
   1.130 +#if !defined (_STLP_NO_WCHAR_T)
   1.131 +  wstring do_get(catalog __c, int __set, int __msgid,
   1.132 +                 const wstring& __dfault) const;
   1.133 +#endif
   1.134 +  void do_close(catalog __c) const; 
   1.135 +  ~_Messages(); 
   1.136 +
   1.137 +private:
   1.138 +  _Locale_messages* _M_message_obj;
   1.139 +  _Catalog_locale_map* _M_map;
   1.140 +  mutable _Catalog_nl_catd_map _M_cat;
   1.141 +
   1.142 +  //private definition to avoid warning (with ICL)
   1.143 +  _Messages(const _Messages&);
   1.144 +  _Messages& operator=(const _Messages&);
   1.145 +};
   1.146 +
   1.147 +_STLP_MOVE_TO_STD_NAMESPACE
   1.148 +
   1.149 +_STLP_END_NAMESPACE
   1.150 +
   1.151 +#endif
   1.152 +
   1.153 +// Local Variables:
   1.154 +// mode:C++
   1.155 +// End:

mercurial