home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / stlpt453.zip / STLport-4.5.3 / src / message_facets.h < prev    next >
C/C++ Source or Header  |  2001-01-26  |  3KB  |  103 lines

  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.  
  21. #include <string>
  22. #include <stl/_messages_facets.h>
  23. #include <stl/_ctype.h>
  24. // #include <istream>
  25. #include <typeinfo>
  26. #include <hash_map>
  27. #include "c_locale.h"
  28.  
  29. _STLP_BEGIN_NAMESPACE
  30.  
  31. // Forward declaration of an opaque type.
  32. struct _Catalog_locale_map;
  33.  
  34. _Locale_messages* __acquire_messages(const char* name); 
  35. void __release_messages(_Locale_messages* cat);
  36.  
  37. // Class _Catalog_locale_map.  The reason for this is that, internally,
  38. // a message string is always a char*.  We need a ctype facet to convert
  39. // a string to and from wchar_t, and the user is permitted to provide such
  40. // a facet when calling open().
  41.  
  42. struct _Catalog_locale_map
  43. {
  44.   _Catalog_locale_map() : M(0) {}
  45.   ~_Catalog_locale_map() { if (M) delete M; }
  46.  
  47.   void insert(int key, const locale& L);
  48.   locale lookup(int key) const;
  49.   void erase(int key);
  50.  
  51.   hash_map<int, locale, hash<int>, equal_to<int> >* M;
  52.  
  53. private:                        // Invalidate copy constructor and assignment
  54.   _Catalog_locale_map(const _Catalog_locale_map&);
  55.   void operator=(const _Catalog_locale_map&);
  56. };
  57.  
  58.  
  59. class _Messages {
  60. public:
  61.   typedef messages_base::catalog catalog;
  62.  
  63.   _Messages();
  64.  
  65.   virtual catalog     do_open(const string& __fn, const locale& __loc) const;
  66.   virtual string do_get(catalog __c, int __set, int __msgid,
  67.             const string& __dfault) const;
  68. # ifndef _STLP_NO_WCHAR_T
  69.   virtual wstring do_get(catalog __c, int __set, int __msgid,
  70.                              const wstring& __dfault) const;
  71. # endif
  72.   virtual void        do_close(catalog __c) const;
  73.   virtual ~_Messages();
  74.   bool _M_delete;
  75. };
  76.  
  77. class _Messages_impl : public _Messages {
  78. public:
  79.  
  80.   _Messages_impl(bool);
  81.  
  82.   _Messages_impl(bool, _Locale_messages*);
  83.  
  84.   catalog     do_open(const string& __fn, const locale& __loc) const;
  85.   string do_get(catalog __c, int __set, int __msgid,
  86.             const string& __dfault) const;
  87. # ifndef _STLP_NO_WCHAR_T
  88.   wstring do_get(catalog __c, int __set, int __msgid,
  89.          const wstring& __dfault) const;
  90. # endif
  91.   void        do_close(catalog __c) const;
  92.   
  93.   ~_Messages_impl();
  94.  
  95. private:
  96.   _Locale_messages* _M_message_obj;
  97.   _Catalog_locale_map* _M_map;
  98. };
  99.  
  100. _STLP_END_NAMESPACE
  101.  
  102. #endif
  103.