ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

message_facets.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1999
00003  * Silicon Graphics Computer Systems, Inc.
00004  *
00005  * Copyright (c) 1999
00006  * Boris Fomitchev
00007  *
00008  * This material is provided "as is", with absolutely no warranty expressed
00009  * or implied. Any use is at your own risk.
00010  *
00011  * Permission to use or copy this software for any purpose is hereby granted
00012  * without fee, provided the above notices are retained on all copies.
00013  * Permission to modify the code and to distribute modified code is granted,
00014  * provided the above notices are retained, and a notice that the code was
00015  * modified is included with the above copyright notice.
00016  *
00017  */
00018 #ifndef MESSAGE_FACETS_H
00019 #define MESSAGE_FACETS_H
00020 
00021 #include <string>
00022 #include <locale>
00023 #include <hash_map>
00024 
00025 #include "c_locale.h"
00026 
00027 _STLP_BEGIN_NAMESPACE
00028 _STLP_MOVE_TO_PRIV_NAMESPACE
00029 
00030 // Class _Catalog_locale_map.  The reason for this is that, internally,
00031 // a message string is always a char*.  We need a ctype facet to convert
00032 // a string to and from wchar_t, and the user is permitted to provide such
00033 // a facet when calling open().
00034 
00035 struct _Catalog_locale_map {
00036   _Catalog_locale_map() : M(0) {}
00037   ~_Catalog_locale_map() { if (M) delete M; }
00038 
00039   void insert(nl_catd_type key, const locale& L);
00040   locale lookup(nl_catd_type key) const;
00041   void erase(nl_catd_type key);
00042 
00043   typedef hash_map<nl_catd_type, locale, hash<nl_catd_type>, equal_to<nl_catd_type>, 
00044                    allocator<pair<_STLP_CONST nl_catd_type, locale> > > map_type;
00045   map_type *M;
00046 
00047 private:                        // Invalidate copy constructor and assignment
00048   _Catalog_locale_map(const _Catalog_locale_map&);
00049   void operator=(const _Catalog_locale_map&);
00050 };
00051 
00052 /*
00053  * In glibc nl_catd type is void *, but messages_base::catalog is defined as int
00054  * by ISO/IEC 14882; The int may be too short to store pointer on 64-bit platforms;
00055  * Another problem, is that do_open() may return negative value to indicate that no
00056  * catalog open---this case can't be represented with pointers.
00057  * The class _Catalog_nl_catd_map intended to make relation between
00058  * messages_base::catalog and nl_catd handler.
00059  *
00060  */
00061 
00062 #if defined (_STLP_USE_GLIBC2_LOCALIZATION)
00063 #  define _STLP_USE_NL_CATD_MAPPING
00064 #else
00065 /* If no mapping a message_base::catalog entry, int typedef according C++ Standard 22.2.7.1,
00066  * has to be large enough to contain a nl_catd_type value.
00067  */
00068 _STLP_STATIC_ASSERT(sizeof(nl_catd_type) <= sizeof(int))
00069 #endif
00070 
00071 class _STLP_CLASS_DECLSPEC _Catalog_nl_catd_map {
00072 public:
00073   _Catalog_nl_catd_map()
00074   {}
00075   ~_Catalog_nl_catd_map()
00076   {}
00077 
00078   typedef hash_map<messages_base::catalog, nl_catd_type, hash<messages_base::catalog>, equal_to<messages_base::catalog>,
00079                    allocator<pair<_STLP_CONST messages_base::catalog, nl_catd_type> > > map_type;
00080   typedef hash_map<nl_catd_type, messages_base::catalog, hash<nl_catd_type>, equal_to<nl_catd_type>,
00081                    allocator<pair<_STLP_CONST nl_catd_type, messages_base::catalog> > > rmap_type;
00082   // typedef map<messages_base::catalog,nl_catd_type> map_type;
00083   // typedef map<nl_catd_type,messages_base::catalog> rmap_type;
00084 
00085   messages_base::catalog insert(nl_catd_type cat)
00086 #if !defined (_STLP_USE_NL_CATD_MAPPING)
00087   { return (messages_base::catalog)cat; }
00088 #else
00089   ;
00090 #endif
00091 
00092   void erase(messages_base::catalog)
00093 #if !defined (_STLP_USE_NL_CATD_MAPPING)
00094   {}
00095 #else
00096   ;
00097 #endif
00098 
00099   nl_catd_type operator [] ( messages_base::catalog cat )
00100 #if !defined (_STLP_USE_NL_CATD_MAPPING)
00101   { return cat; }
00102 #else
00103   { return cat < 0 ? 0 : M[cat]; }
00104 #endif
00105 
00106 private:
00107   _Catalog_nl_catd_map(const _Catalog_nl_catd_map&);
00108   _Catalog_nl_catd_map& operator =(const _Catalog_nl_catd_map&);
00109 
00110 #if defined (_STLP_USE_NL_CATD_MAPPING)
00111   map_type M;
00112   rmap_type Mr;
00113   static _STLP_VOLATILE __stl_atomic_t _count;
00114 #endif
00115 };
00116 
00117 class _Messages {
00118 public:
00119   typedef messages_base::catalog catalog;
00120 
00121   _Messages(bool, const char *name);
00122   _Messages(bool, _Locale_messages*);
00123 
00124   catalog do_open(const string& __fn, const locale& __loc) const;
00125   string do_get(catalog __c, int __set, int __msgid,
00126                 const string& __dfault) const;
00127 #if !defined (_STLP_NO_WCHAR_T)
00128   wstring do_get(catalog __c, int __set, int __msgid,
00129                  const wstring& __dfault) const;
00130 #endif
00131   void do_close(catalog __c) const; 
00132   ~_Messages(); 
00133 
00134 private:
00135   _Locale_messages* _M_message_obj;
00136   _Catalog_locale_map* _M_map;
00137   mutable _Catalog_nl_catd_map _M_cat;
00138 
00139   //private definition to avoid warning (with ICL)
00140   _Messages(const _Messages&);
00141   _Messages& operator=(const _Messages&);
00142 };
00143 
00144 _STLP_MOVE_TO_STD_NAMESPACE
00145 
00146 _STLP_END_NAMESPACE
00147 
00148 #endif
00149 
00150 // Local Variables:
00151 // mode:C++
00152 // End:

Generated on Fri May 25 2012 04:33:41 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.