/project/jni/stlport/src/message_facets.h

https://github.com/aichunyu/FFPlayer · C Header · 168 lines · 100 code · 29 blank · 39 comment · 3 complexity · 05880c74bce53efe64a76100d1dd4b50 MD5 · raw file

  1. /*
  2. * Copyright (c) 1999
  3. * Silicon Graphics Computer Systems, Inc.
  4. *
  5. * Copyright (c) 1999
  6. * Boris Fomitchev
  7. *
  8. * This material is provided "as is", with absolutely no warranty expressed
  9. * or implied. Any use is at your own risk.
  10. *
  11. * Permission to use or copy this software for any purpose is hereby granted
  12. * without fee, provided the above notices are retained on all copies.
  13. * Permission to modify the code and to distribute modified code is granted,
  14. * provided the above notices are retained, and a notice that the code was
  15. * modified is included with the above copyright notice.
  16. *
  17. */
  18. #ifndef MESSAGE_FACETS_H
  19. #define MESSAGE_FACETS_H
  20. #include <string>
  21. #include <locale>
  22. #include <typeinfo>
  23. #include <hash_map>
  24. #include "c_locale.h"
  25. #include "acquire_release.h"
  26. _STLP_BEGIN_NAMESPACE
  27. _STLP_MOVE_TO_PRIV_NAMESPACE
  28. // Class _Catalog_locale_map. The reason for this is that, internally,
  29. // a message string is always a char*. We need a ctype facet to convert
  30. // a string to and from wchar_t, and the user is permitted to provide such
  31. // a facet when calling open().
  32. struct _Catalog_locale_map {
  33. _Catalog_locale_map() : M(0) {}
  34. ~_Catalog_locale_map() { if (M) delete M; }
  35. void insert(nl_catd_type key, const locale& L);
  36. locale lookup(nl_catd_type key) const;
  37. void erase(nl_catd_type key);
  38. typedef hash_map<nl_catd_type, locale, hash<nl_catd_type>, equal_to<nl_catd_type> > map_type;
  39. map_type *M;
  40. private: // Invalidate copy constructor and assignment
  41. _Catalog_locale_map(const _Catalog_locale_map&);
  42. void operator=(const _Catalog_locale_map&);
  43. };
  44. /*
  45. * In glibc nl_catd type is void *, but messages_base::catalog is defined as int
  46. * by ISO/IEC 14882; The int may be too short to store pointer on 64-bit platforms;
  47. * Another problem, is that do_open() may return negative value to indicate that no
  48. * catalog open---this case can't be represented with pointers.
  49. * The class _Catalog_nl_catd_map intended to make relation between
  50. * messages_base::catalog and nl_catd handler.
  51. *
  52. */
  53. #if defined (_STLP_REAL_LOCALE_IMPLEMENTED) && (defined (_STLP_USE_GLIBC) && !defined (__CYGWIN__))
  54. # define _STLP_USE_NL_CATD_MAPPING
  55. #else
  56. /* If no mapping a message_base::catalog entry, int typedef according C++ Standard 22.2.7.1,
  57. * has to be large enough to contain a nl_catd_type value.
  58. */
  59. _STLP_STATIC_ASSERT(sizeof(nl_catd_type) <= sizeof(int))
  60. #endif
  61. class _STLP_CLASS_DECLSPEC _Catalog_nl_catd_map {
  62. public:
  63. _Catalog_nl_catd_map()
  64. {}
  65. ~_Catalog_nl_catd_map()
  66. {}
  67. typedef hash_map<messages_base::catalog, nl_catd_type, hash<messages_base::catalog>, equal_to<messages_base::catalog> > map_type;
  68. typedef hash_map<nl_catd_type, messages_base::catalog, hash<nl_catd_type>, equal_to<nl_catd_type> > rmap_type;
  69. // typedef map<messages_base::catalog,nl_catd_type> map_type;
  70. // typedef map<nl_catd_type,messages_base::catalog> rmap_type;
  71. messages_base::catalog insert(nl_catd_type cat)
  72. #if !defined (_STLP_USE_NL_CATD_MAPPING)
  73. { return (messages_base::catalog)cat; }
  74. #else
  75. ;
  76. #endif
  77. void erase(messages_base::catalog)
  78. #if !defined (_STLP_USE_NL_CATD_MAPPING)
  79. {}
  80. #else
  81. ;
  82. #endif
  83. nl_catd_type operator [] ( messages_base::catalog cat ) const
  84. #if !defined (_STLP_USE_NL_CATD_MAPPING)
  85. { return cat; }
  86. #else
  87. { return cat < 0 ? 0 : M[cat]; }
  88. #endif
  89. private:
  90. _Catalog_nl_catd_map(const _Catalog_nl_catd_map&);
  91. _Catalog_nl_catd_map& operator =(const _Catalog_nl_catd_map&);
  92. #if defined (_STLP_USE_NL_CATD_MAPPING)
  93. mutable map_type M;
  94. mutable rmap_type Mr;
  95. static _STLP_VOLATILE __stl_atomic_t _count;
  96. #endif
  97. };
  98. class _STLP_CLASS_DECLSPEC _Messages {
  99. public:
  100. typedef messages_base::catalog catalog;
  101. _Messages();
  102. virtual catalog do_open(const string& __fn, const locale& __loc) const;
  103. virtual string do_get(catalog __c, int __set, int __msgid,
  104. const string& __dfault) const;
  105. #if !defined (_STLP_NO_WCHAR_T)
  106. virtual wstring do_get(catalog __c, int __set, int __msgid,
  107. const wstring& __dfault) const;
  108. #endif
  109. virtual void do_close(catalog __c) const;
  110. virtual ~_Messages();
  111. bool _M_delete;
  112. };
  113. class _STLP_CLASS_DECLSPEC _Messages_impl : public _Messages {
  114. public:
  115. _Messages_impl(bool, _Locale_name_hint* hint = 0);
  116. _Messages_impl(bool, _Locale_messages*);
  117. catalog do_open(const string& __fn, const locale& __loc) const;
  118. string do_get(catalog __c, int __set, int __msgid,
  119. const string& __dfault) const;
  120. #if !defined (_STLP_NO_WCHAR_T)
  121. wstring do_get(catalog __c, int __set, int __msgid,
  122. const wstring& __dfault) const;
  123. #endif
  124. void do_close(catalog __c) const;
  125. ~_Messages_impl();
  126. private:
  127. _Locale_messages* _M_message_obj;
  128. _Catalog_locale_map* _M_map;
  129. mutable _Catalog_nl_catd_map _M_cat;
  130. //private definition to avoid warning (with ICL)
  131. _Messages_impl(const _Messages_impl&);
  132. _Messages_impl& operator=(const _Messages_impl&);
  133. };
  134. _STLP_MOVE_TO_STD_NAMESPACE
  135. _STLP_END_NAMESPACE
  136. #endif
  137. // Local Variables:
  138. // mode:C++
  139. // End: