// -*- C++ -*-
/***************************************************************************
 *
 * messages - Declarations for the Standard Library messaging facet
 *
 ***************************************************************************
 *    
 *  Copyright 2000 Compaq Computer Corporation
 *
 *  COMPAQ Registered in U.S. Patent and Trademark Office.
 *
 *  Confidential computer software. Valid license from Compaq required for
 *  possession, use or copying. Consistent with FAR 12.211 and 12.212,
 *  Commercial Computer Software, Computer Software Documentation, and
 *  Technical Data for Commercial Items are licensed to the U.S. Government
 *  under vendor's standard commercial license.
 *
 ****************************************************************************
 *
 * (c) Copyright 1994, 1998 Rogue Wave Software, Inc.
 * ALL RIGHTS RESERVED
 *
 * The software and information contained herein are proprietary to, and
 * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
 * intends to preserve as trade secrets such software and information.
 * This software is furnished pursuant to a written license agreement and
 * may be used, copied, transmitted, and stored only in accordance with
 * the terms of such license and with the inclusion of the above copyright
 * notice.  This software and information or any other copies thereof may
 * not be provided or otherwise made available to any other person.
 *
 * Notwithstanding any other lease or license that may pertain to, or
 * accompany the delivery of, this computer software and information, the
 * rights of the Government regarding its use, reproduction and disclosure
 * are as set forth in Section 52.227-19 of the FARS Computer
 * Software-Restricted Rights clause.
 * 
 * Use, duplication, or disclosure by the Government is subject to
 * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
 * Technical Data and Computer Software clause at DFARS 252.227-7013.
 * Contractor/Manufacturer is Rogue Wave Software, Inc.,
 * P.O. Box 2328, Corvallis, Oregon 97339.
 *
 * This computer software and information is distributed with "restricted
 * rights."  Use, duplication or disclosure is subject to restrictions as
 * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
 * Computer Software-Restricted Rights (April 1985)."  If the Clause at
 * 18-52.227-74 "Rights in Data General" is specified in the contract,
 * then the "Alternate III" clause applies.
 *
 **************************************************************************/

#ifndef __STD_MESSAGE__
#define __STD_MESSAGE__

#ifndef __STD_RWLOCALE__
#include <rwlocale>
#endif

#if defined(__DECCXX)
#   ifdef __PRAGMA_ENVIRONMENT
#      pragma __environment __save
#      pragma __environment __cxx_header_defaults
#   endif
#endif

#if defined(__VMS) && defined(__DECCXX) && !defined(__DECFIXCXXL1158)
#pragma __extern_prefix __save
#pragma __extern_prefix "CXXL$" 
#endif

#ifndef _RWSTD_NO_NAMESPACE
namespace std {
#endif

struct _RWSTDExport messages_base {
#if defined(__DECCXX) && !defined(__DECFIXCXXL1198)
  typedef int catalog;
#else
  typedef size_t catalog;
#endif
};

#ifndef _RWSTD_NO_NAMESPACE
} namespace _RWrwstd {
#endif

// --------------------------------------
// Implementation class -- messages_impl.
// --------------------------------------

class _RWSTDExport messages_impl {
  _RW_STD::string loc_name_;                          \
 protected:
  messages_impl (_RW_STD::string name);

  _RW_STD::messages_base::catalog open_cat_ (const _RW_STD::string &,const _RW_STD::locale &) const;
  char *get_mess_ (_RW_STD::messages_base::catalog,int,int) const;
  const _RW_STD::locale &get_loc_ (_RW_STD::messages_base::catalog) const;
  void close_cat_ (_RW_STD::messages_base::catalog) const;
  static _RW_STD::string get_loc_name_ (const char*);
};

#ifndef _RWSTD_NO_NAMESPACE
} namespace std {
#endif

// ----------------------------------------------------
// Standard message retrieval facet -- messages<charT>.
// ----------------------------------------------------

template <class charT>
class   messages: public locale::facet, public messages_base,
    public __RWSTD::messages_impl
{
 public:
  typedef charT char_type;
  typedef basic_string<charT,char_traits<charT>,allocator<charT> > string_type;

  _EXPLICIT messages (size_t refs=0);

  catalog open (const string& fn, const locale& loc) const
    { return do_open(fn,loc); }
  string_type get (catalog c, int set, int msgid, const string_type& df) const
    { return do_get(c,set,msgid,df); }
  void close (catalog c) const { do_close(c); }

  static locale::id id;

  // Implementation:
  enum { _RWfacet_cat = locale::_RWrw_messages_category, _RWok_implicit = 1 };

 protected:
  virtual ~messages();

  virtual catalog do_open (const string&, const locale&) const;
  virtual string_type do_get (catalog, int, int, const string_type&) const;
  virtual void do_close (catalog) const;

  // Implementation:
  messages (size_t refs,string);

 private:
  #ifdef _RWSTD_NO_MEMBER_TEMPLATES
  locale::id &_RWget_id (void) const { return id; }
  #endif
};

// -------------------------------------------------
// Standard derived facet -- messages_byname<charT>.
// -------------------------------------------------

template <class charT>
class  messages_byname: public messages<charT> {
 public:
  _EXPLICIT messages_byname (const char*, size_t refs=0);

 protected:

  // Virtual members inherited from messages<charT>:
  // ~messages_byname();
  // catalog do_open (const string&, const locale&) const;
  // string_type do_get (catalog, int, int, const string_type&) const;
  // void do_close (catalog) const;
};


#if defined(__DECCXX) && !defined(__DECFIXCXXL646)
// -------------------------------------------------------
// Standard facet specialization -- messages_byname<char>.
// -------------------------------------------------------

template <>
class _RWSTDExportTemplate messages_byname<char> : public messages<char> {
 public:
  _EXPLICIT messages_byname (const char*, size_t refs=0);

 protected:
  virtual ~messages_byname();

  virtual catalog do_open (const string&, const locale&) const;
  virtual string_type do_get (catalog, int, int, const string_type&) const;
  virtual void do_close (catalog) const;
};

// ----------------------------------------------------------
// Standard facet specialization -- messages_byname<wchar_t>.
// ----------------------------------------------------------

#ifndef _RWSTD_NO_WIDE_CHAR

template <>
class _RWSTDExportTemplate messages_byname<wchar_t> : public messages<wchar_t> {
 public:
  _EXPLICIT messages_byname (const char*, size_t refs=0);

 protected:
  virtual ~messages_byname();

  virtual catalog do_open (const string&, const locale&) const;
  virtual string_type do_get (catalog, int, int, const string_type&) const;
  virtual void do_close (catalog) const;

 private:
  wchar_t *msg_;
};

#endif // __RWSTD_NO_WIDE_CHAR

#endif // 646

#ifndef _RWSTD_NO_NAMESPACE
} namespace _RWrwstd {
#endif

#ifndef _RWSTD_NO_FUNC_PARTIAL_SPEC

template <class charT>
inline _RW_STD::messages<charT>* create_named_facet
    (_RW_STD::messages<charT>*,const char *name,size_t refs)
{ return new _RW_STD::messages_byname<charT>(name,refs); }

#else
_RWSTD_TEMPLATE
inline _RW_STD::messages<char>* create_named_facet
    (_RW_STD::messages<char>*,const char *name,size_t refs)
{ return new _RW_STD::messages_byname<char>(name,refs); }

#ifndef _RWSTD_NO_WIDE_CHAR
_RWSTD_TEMPLATE
inline _RW_STD::messages<wchar_t>* create_named_facet
    (_RW_STD::messages<wchar_t>*,const char *name,size_t refs)
{ return new _RW_STD::messages_byname<wchar_t>(name,refs); }

#endif // _RWSTD_NO_WIDE_CHAR
#endif // _RWSTD_NO_FUNC_PARTIAL_SPEC


#ifndef _RWSTD_NO_NAMESPACE
} // namespace _RWrwstd
#endif

#if defined(__VMS) && defined(__DECCXX) && !defined(__DECFIXCXXL1158)
#   pragma __extern_prefix __restore
#endif

#ifdef _RWSTD_COMPILE_INSTANTIATE
#include <messages.cc>
#endif


#if defined(__DECCXX)
#   ifdef __PRAGMA_ENVIRONMENT
#      pragma __environment __restore
#   endif
#endif

#endif /* __STD_MESSAGE__ */
