home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / include / xlocinfo < prev    next >
Text File  |  1998-06-16  |  3KB  |  115 lines

  1. // xlocinfo internal header
  2.  
  3. #if     _MSC_VER > 1000
  4. #pragma once
  5. #endif
  6.  
  7. #ifndef _XLOCINFO_
  8. #define _XLOCINFO_
  9. #include <xlocinfo.h>
  10. #include <cstdlib>
  11. #include <xstddef>
  12.  
  13. #ifdef  _MSC_VER
  14. #pragma pack(push,8)
  15. #endif  /* _MSC_VER */
  16. _STD_BEGIN
  17.  
  18.         // CLASS _Timevec
  19. class _CRTIMP _Timevec {
  20. public:
  21.     _Timevec(void *_P = 0)
  22.         : _Ptr(_P) {}
  23.     _Timevec(const _Timevec& _Rhs)
  24.         {*this = _Rhs; }
  25.     ~_Timevec()
  26.         {free(_Ptr); }
  27.     _Timevec& operator=(const _Timevec& _Rhs)
  28.         {_Ptr = _Rhs._Ptr;
  29.         ((_Timevec *)&_Rhs)->_Ptr = 0;
  30.         return (*this); }
  31.     void *_Getptr() const
  32.         {return (_Ptr); }
  33. private:
  34.     void *_Ptr;
  35.     };
  36.         // CLASS _Locinfo
  37. class _CRTIMP _Locinfo {
  38. public:
  39.     typedef ::_Collvec _Collvec;
  40.     typedef ::_Ctypevec _Ctypevec;
  41.     typedef ::_Cvtvec _Cvtvec;
  42.     typedef std::_Timevec _Timevec;
  43.     _Locinfo(const char * = "C");
  44.     _Locinfo(int, const char *);
  45.     ~_Locinfo();
  46.     _Locinfo& _Addcats(int, const char *);
  47.     string _Getname() const
  48.         {return (_Nname); }
  49.     _Collvec _Getcoll() const
  50.         {return (::_Getcoll()); }
  51.     _Ctypevec _Getctype() const
  52.         {return (::_Getctype()); }
  53.     _Cvtvec _Getcvt() const
  54.         {return (::_Getcvt()); }
  55.     const lconv *_Getlconv() const
  56.         {return (localeconv()); }
  57.     _Timevec _Gettnames() const
  58.         {return (_Timevec(::_Gettnames())); }
  59.     const char *_Getdays() const
  60.         {char *_S = ::_Getdays();
  61.         if (_S != 0)
  62.             {((_Locinfo *)this)->_Days = _S, free(_S); }
  63.         return (_Days.size() != 0 ? _Days.c_str()
  64.                 : ":Sun:Sunday:Mon:Monday:Tue:Tuesday"
  65.                 ":Wed:Wednesday:Thu:Thursday:Fri:Friday"
  66.                 ":Sat:Saturday"); }
  67.     const char *_Getmonths() const
  68.         {char *_S = ::_Getmonths();
  69.         if (_S != 0)
  70.             {((_Locinfo *)this)->_Months = _S, free(_S); }
  71.         return (_Months.size() != 0 ? _Months.c_str()
  72.                 : ":Jan:January:Feb:February:Mar:March"
  73.                 ":Apr:April:May:May:Jun:June"
  74.                 ":Jul:July:Aug:August:Sep:September"
  75.                 ":Oct:October:Nov:November:Dec:December"); }
  76.     const char *_Getfalse() const
  77.         {return ("false"); }
  78.     const char *_Gettrue() const
  79.         {return ("true"); }
  80.     const char *_Getno() const
  81.         {return ("no"); }
  82.     const char *_Getyes() const
  83.         {return ("yes"); }
  84. private:
  85.     string _Days, _Months, _Oname, _Nname;
  86.     };
  87.         // TEMPLATE FUNCTIONS
  88. template<class _E> inline
  89.     int __cdecl _Strcoll(const _E *_F1, const _E *_L1,
  90.         const _E *_F2, const _E *_L2, const _Locinfo::_Collvec *)
  91.     {for (; _F1 != _L1 && _F2 != _L2; ++_F1, ++_F2)
  92.         if (*_F1 < *_F2)
  93.             return (-1);
  94.         else if (*_F2 < *_F1)
  95.             return (+1);
  96.     return (_F2 != _L2 ? -1 : _F1 != _L1 ? +1 : 0); }
  97. template<class _E> inline
  98.     size_t __cdecl _Strxfrm(_E *_F1, _E *_L1,
  99.         const _E *_F2, const _E *_L2, const _Locinfo::_Collvec *)
  100.     {size_t _N = _L2 - _F2;
  101.     if (_N <= _L1 - _F1)
  102.         memcpy(_F1, _F2, _N * sizeof (_E));
  103.     return (_N); }
  104. _STD_END
  105. #ifdef  _MSC_VER
  106. #pragma pack(pop)
  107. #endif  /* _MSC_VER */
  108.  
  109. #endif /* _XLOCINFO_ */
  110.  
  111. /*
  112.  * Copyright (c) 1996 by P.J. Plauger.  ALL RIGHTS RESERVED. 
  113.  * Consult your license regarding permissions and restrictions.
  114.  */
  115.