message_facets.h

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 <stl/_messages_facets.h>
00023 #include <stl/_ctype.h>
00024 // #include <istream>
00025 #include <typeinfo>
00026 #include <hash_map>
00027 #include "c_locale.h"
00028 
00029 _STLP_BEGIN_NAMESPACE
00030 
00031 // Forward declaration of an opaque type.
00032 struct _Catalog_locale_map;
00033 
00034 _Locale_messages* __acquire_messages(const char* name); 
00035 void __release_messages(_Locale_messages* cat);
00036 
00037 // Class _Catalog_locale_map.  The reason for this is that, internally,
00038 // a message string is always a char*.  We need a ctype facet to convert
00039 // a string to and from wchar_t, and the user is permitted to provide such
00040 // a facet when calling open().
00041 
00042 struct _Catalog_locale_map
00043 {
00044   _Catalog_locale_map() : M(0) {}
00045   ~_Catalog_locale_map() { if (M) delete M; }
00046 
00047   void insert(int key, const locale& L);
00048   locale lookup(int key) const;
00049   void erase(int key);
00050 
00051   hash_map<int, locale, hash<int>, equal_to<int> >* M;
00052 
00053 private:                        // Invalidate copy constructor and assignment
00054   _Catalog_locale_map(const _Catalog_locale_map&);
00055   void operator=(const _Catalog_locale_map&);
00056 };
00057 
00058 
00059 class _Messages {
00060 public:
00061   typedef messages_base::catalog catalog;
00062 
00063   _Messages();
00064 
00065   virtual catalog     do_open(const string& __fn, const locale& __loc) const;
00066   virtual string do_get(catalog __c, int __set, int __msgid,
00067                         const string& __dfault) const;
00068 # ifndef _STLP_NO_WCHAR_T
00069   virtual wstring do_get(catalog __c, int __set, int __msgid,
00070                              const wstring& __dfault) const;
00071 # endif
00072   virtual void        do_close(catalog __c) const;
00073   virtual ~_Messages();
00074   bool _M_delete;
00075 };
00076 
00077 class _Messages_impl : public _Messages {
00078 public:
00079 
00080   _Messages_impl(bool);
00081 
00082   _Messages_impl(bool, _Locale_messages*);
00083 
00084   catalog     do_open(const string& __fn, const locale& __loc) const;
00085   string do_get(catalog __c, int __set, int __msgid,
00086                         const string& __dfault) const;
00087 # ifndef _STLP_NO_WCHAR_T
00088   wstring do_get(catalog __c, int __set, int __msgid,
00089                  const wstring& __dfault) const;
00090 # endif
00091   void        do_close(catalog __c) const;
00092   
00093   ~_Messages_impl();
00094 
00095 private:
00096   _Locale_messages* _M_message_obj;
00097   _Catalog_locale_map* _M_map;
00098 };
00099 
00100 _STLP_END_NAMESPACE
00101 
00102 #endif

Generated on Mon Jun 5 10:20:45 2006 for Intelligence.kdevelop by  doxygen 1.4.6