home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / Xenon / C++ / FreeCommandLineTools.exe / Include / Rw / usefacet.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-31  |  7.3 KB  |  161 lines

  1. #ifndef __USEFACET_H
  2. #define __USEFACET_H
  3. #pragma option push -b -a8 -pc -Vx- -Ve- -w-inl -w-aus -w-sig
  4. // -*- C++ -*-
  5. /***************************************************************************
  6.  *
  7.  * usefacet - Declarations for the Standard Library facet access functions
  8.  *            and for the convenience functions (isalpha etc.)
  9.  *
  10.  ***************************************************************************
  11.  *
  12.  * Copyright (c) 1994-1999 Rogue Wave Software, Inc.  All Rights Reserved.
  13.  *
  14.  * This computer software is owned by Rogue Wave Software, Inc. and is
  15.  * protected by U.S. copyright laws and other laws and by international
  16.  * treaties.  This computer software is furnished by Rogue Wave Software,
  17.  * Inc. pursuant to a written license agreement and may be used, copied,
  18.  * transmitted, and stored only in accordance with the terms of such
  19.  * license and with the inclusion of the above copyright notice.  This
  20.  * computer software or any other copies thereof may not be provided or
  21.  * otherwise made available to any other person.
  22.  *
  23.  * U.S. Government Restricted Rights.  This computer software is provided
  24.  * with Restricted Rights.  Use, duplication, or disclosure by the
  25.  * Government is subject to restrictions as set forth in subparagraph (c)
  26.  * (1) (ii) of The Rights in Technical Data and Computer Software clause
  27.  * at DFARS 252.227-7013 or subparagraphs (c) (1) and (2) of the
  28.  * Commercial Computer Software รป Restricted Rights at 48 CFR 52.227-19,
  29.  * as applicable.  Manufacturer is Rogue Wave Software, Inc., 5500
  30.  * Flatiron Parkway, Boulder, Colorado 80301 USA.
  31.  *
  32.  **************************************************************************/
  33.  
  34. #ifndef __STD_USEFACET__
  35. #define __STD_USEFACET__
  36.  
  37. #ifndef __STD_RWLOCALE__
  38. #include <rw/rwlocale>
  39. #endif
  40.  
  41. #ifndef _RWSTD_NO_NAMESPACE
  42. namespace std {
  43. #endif
  44.  
  45. // Template use_facet<Facet>(loc) returns a reference to a facet.  Its result
  46. // is guaranteed by locale's value semantics to last at least as long as the
  47. // locale or any copy of the locale it came from.
  48.  
  49. #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  50. #define _RWSTD_SELECT_FACET
  51. #else
  52. #define _RWSTD_SELECT_FACET ,Facet*
  53. #endif
  54.  
  55. template <class Facet>
  56. _RWSTD_TRICKY_INLINE
  57. const Facet &use_facet (const locale &loc _RWSTD_SELECT_FACET)
  58. {
  59.   // Ensure that Facet has a static member named id, and (via cast) that it is
  60.   // of type locale::id, and obtain from it (via size_t conversion operator)
  61.   // the private numeric index associated with type Facet for this run.
  62.   size_t i=(const locale::id&) Facet::id;
  63.  
  64.   // Get pointer to facet from locale.
  65.   const __RWSTD::facet_imp *f=loc.get_facet(i);
  66.  
  67.   // If facet is not explicitly present in locale yet, use private function
  68.   // locale::__make_explicit to construct it or retrieve it from a cache, and
  69.   // install it in the locale.  This function can throw bad_cast or other
  70.   // exceptions.
  71.   if (!f)
  72.     f=loc.__make_explicit(Facet::id,Facet::__ok_implicit,Facet::__facet_cat,
  73.         __RWSTD::facet_maker<Facet>::maker_func);
  74.  
  75.   return (const Facet&)*f;
  76. }
  77.  
  78. // Function has_facet<Facet>(loc) simply reports whether a locale implements a
  79. // particular facet.  If has_facet<facet>(loc) is false, use_facet<facet>(loc)
  80. // would throw an exception.
  81.  
  82. template <class Facet>
  83. inline bool has_facet (const locale &loc _RWSTD_SELECT_FACET)
  84.     _RWSTD_THROW_SPEC_NULL
  85. {
  86.   size_t ix = (const locale::id&) Facet::id;  // verify is a locale::id.
  87.   return loc.__imp->get_facet(ix) != NULL || Facet::__ok_implicit;
  88. }
  89.  
  90. // convenience interfaces: is*(char)
  91.  
  92. #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
  93.  
  94. template <class charT> inline bool isspace(charT c, const locale& loc)
  95.   { typedef ctype<charT> idiot; return use_facet<idiot>(loc).is(ctype_base::space, c); }
  96. template <class charT> inline bool isprint(charT c, const locale& loc)
  97.   { return use_facet<ctype<charT> >(loc).is(ctype_base::print, c); }
  98. template <class charT> inline bool iscntrl(charT c, const locale& loc)
  99.   { return use_facet<ctype<charT> >(loc).is(ctype_base::cntrl, c); }
  100. template <class charT> inline bool isupper(charT c, const locale& loc)
  101.   { return use_facet<ctype<charT> >(loc).is(ctype_base::upper, c); }
  102. template <class charT> inline bool islower(charT c, const locale& loc)
  103.   { return use_facet<ctype<charT> >(loc).is(ctype_base::lower, c); }
  104. template <class charT> inline bool isalpha(charT c, const locale& loc)
  105.   { return use_facet<ctype<charT> >(loc).is(ctype_base::alpha, c); }
  106. template <class charT> inline bool isdigit(charT c, const locale& loc)
  107.   { return use_facet<ctype<charT> >(loc).is(ctype_base::digit, c); }
  108. template <class charT> inline bool ispunct(charT c, const locale& loc)
  109.   { return use_facet<ctype<charT> >(loc).is(ctype_base::punct, c); }
  110. template <class charT> inline bool isxdigit(charT c, const locale& loc)
  111.   { return use_facet<ctype<charT> >(loc).is(ctype_base::xdigit, c); }
  112. template <class charT> inline bool isalnum(charT c, const locale& loc)
  113.   { return use_facet<ctype<charT> >(loc).is(ctype_base::alnum, c); }
  114. template <class charT> inline bool isgraph(charT c, const locale& loc)
  115.   { return use_facet<ctype<charT> >(loc).is(ctype_base::graph, c); }
  116.  
  117. template <class charT> inline charT toupper(charT c, const locale& loc)
  118.   { return use_facet<ctype<charT> >(loc).toupper(c); }
  119. template <class charT> inline charT tolower(charT c, const locale& loc)
  120.   { return use_facet<ctype<charT> >(loc).tolower(c); }
  121.  
  122. #else
  123.  
  124. template <class charT> inline bool isspace(charT c, const locale& loc)
  125.   { return use_facet(loc,(ctype<charT>*)0).is(ctype_base::space, c); }
  126. template <class charT> inline bool isprint(charT c, const locale& loc)
  127.   { return use_facet(loc,(ctype<charT>*)0).is(ctype_base::print, c); }
  128. template <class charT> inline bool iscntrl(charT c, const locale& loc)
  129.   { return use_facet(loc,(ctype<charT>*)0).is(ctype_base::cntrl, c); }
  130. template <class charT> inline bool isupper(charT c, const locale& loc)
  131.   { return use_facet(loc,(ctype<charT>*)0).is(ctype_base::upper, c); }
  132. template <class charT> inline bool islower(charT c, const locale& loc)
  133.   { return use_facet(loc,(ctype<charT>*)0).is(ctype_base::lower, c); }
  134. template <class charT> inline bool isalpha(charT c, const locale& loc)
  135.   { return use_facet(loc,(ctype<charT>*)0).is(ctype_base::alpha, c); }
  136. template <class charT> inline bool isdigit(charT c, const locale& loc)
  137.   { return use_facet(loc,(ctype<charT>*)0).is(ctype_base::digit, c); }
  138. template <class charT> inline bool ispunct(charT c, const locale& loc)
  139.   { return use_facet(loc,(ctype<charT>*)0).is(ctype_base::punct, c); }
  140. template <class charT> inline bool isxdigit(charT c, const locale& loc)
  141.   { return use_facet(loc,(ctype<charT>*)0).is(ctype_base::xdigit, c); }
  142. template <class charT> inline bool isalnum(charT c, const locale& loc)
  143.   { return use_facet(loc,(ctype<charT>*)0).is(ctype_base::alnum, c); }
  144. template <class charT> inline bool isgraph(charT c, const locale& loc)
  145.   { return use_facet(loc,(ctype<charT>*)0).is(ctype_base::graph, c); }
  146.  
  147. template <class charT> inline charT toupper(charT c, const locale& loc)
  148.   { return use_facet(loc,(ctype<charT>*)0).toupper(c); }
  149. template <class charT> inline charT tolower(charT c, const locale& loc)
  150.   { return use_facet(loc,(ctype<charT>*)0).tolower(c); }
  151.  
  152. #endif
  153.  
  154. #ifndef _RWSTD_NO_NAMESPACE
  155. } // namespace std
  156. #endif
  157.  
  158. #endif //  __STD_USEFACET__
  159. #pragma option pop
  160. #endif /* __USEFACET_H */
  161.