home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / OSL_INC.PAK / INLINES.H < prev    next >
C/C++ Source or Header  |  1995-08-29  |  4KB  |  99 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectSupport
  3. // (C) Copyright 1992, 1994 by Borland International, All Rights Reserved
  4. //
  5. //   Common inline templates & functions
  6. //----------------------------------------------------------------------------
  7. #if !defined(OSL_INLINES_H)
  8. #define OSL_INLINES_H
  9.  
  10. #if !defined(OSL_DEFS_H)
  11. # include <osl/defs.h>
  12. #endif
  13. #if !defined(STRING_H)
  14. # include <string.h>
  15. #endif
  16.  
  17. //
  18. // Misc support functions & macros
  19. //
  20. template <class T> inline void Swap(T far& a, T far& b) {a^=b; b^=a; a^=b;}
  21. template <class T> inline T Min(T a, T b) {return a<b ? a : b;}
  22. template <class T> inline T Max(T a, T b) {return a>b ? a : b;}
  23. int    Sqrt(long val);
  24. #define COUNTOF(s)   (sizeof(s) / sizeof((s)[0]))
  25. #if !defined(LOWORD)
  26. # define LOWORD(l)           ((uint16)(l))
  27. #endif
  28. #if !defined(HIWORD)
  29. # define HIWORD(l)           ((uint16)((uint32)(l) >> 16))
  30. #endif
  31.  
  32. //
  33. // Inline versions of common RTL functions, overloaded for far ptrs for use
  34. // when in a near data model.
  35. //
  36. #if defined(BI_DATA_NEAR)
  37.   inline void far* memccpy(void far* d, const void far* s, int c, size_t n)
  38.                      {return _fmemccpy(d, s, c, n);}
  39.   inline void far* memchr(const void far* s, int c, size_t n)
  40.                      {return _fmemchr(s, c, n);}
  41.   inline int       memcmp(const void far* s1, const void far* s2, size_t n)
  42.                      {return _fmemcmp(s1, s2, n);}
  43.   inline void far* memcpy(void far* d, const void far* s, size_t n)
  44.                      {return _fmemcpy(d, s, n);}
  45.   inline int       memicmp(const void far* s1, const void far* s2, size_t n)
  46.                      {return _fmemicmp(s1, s2, n);}
  47.   inline void far* memset(void far* s, int c, size_t n)
  48.                      {return _fmemset(s, c, n);}
  49.   inline void far* memmove(void far* d, const void far* s, size_t n)
  50.                      {return _fmemmove(d, s, n);}
  51.  
  52.   inline char far* strcat(char far* d, const char far* s)
  53.                      {return _fstrcat(d, s);}
  54.   inline char far* strchr(const char far* s, int c) {return _fstrchr(s, c);}
  55.   inline int       strcmp(const char far* s1, const char far* s2)
  56.                      {return _fstrcmp(s1, s2);}
  57.   inline char far* strcpy(char far* d, const char far* s)
  58.                      {return _fstrcpy(d, s);}
  59.   inline int       stricmp(const char far* s1, const char far* s2)
  60.                      {return _fstricmp(s1, s2);}
  61.   inline size_t    strlen(const char far* s) {return _fstrlen(s);}
  62.   inline char far* strlwr(char far* s) {return _fstrlwr(s);}
  63.   inline char far* strncat(char far* d, const char far* s, size_t maxlen)
  64.                      {return _fstrncat(d, s, maxlen);}
  65.   inline int       strncmp(const char far* s1, const char far* s2, size_t maxlen)
  66.                      {return _fstrncmp(s1, s2, maxlen);}
  67.   inline char far* strncpy(char far* d, const char far* s, size_t maxlen)
  68.                      {return _fstrncpy(d, s, maxlen);}
  69.   inline int       strnicmp(const char far* s1, const char far* s2, size_t maxlen)
  70.                      {return _fstrnicmp(s1, s2, maxlen);}
  71.   inline char far* strrchr(const char far* s, int c) {return _fstrrchr(s, c);}
  72.   inline char far* strtok(char far* s1, const char far* s2)
  73.                      {return _fstrtok(s1, s2);}
  74.   inline char far* strupr(char far* s) {return _fstrupr(s);}
  75. #endif
  76.  
  77. //
  78. // type overloaded version of Window's huge mem copy (hmemcpy) for flat models
  79. //
  80. #if !defined(BI_PLAT_WIN16)
  81.   inline void      hmemcpy(void* d, const void* s, long n) {memcpy(d, s, n);}
  82. #endif
  83.  
  84. //
  85. // strnewdup() uses new char[], to allow duplicated strings to be deleted
  86. //
  87. char* _BIDSFUNC strnewdup(const char* s, size_t allocSize = 0);
  88. #if defined(BI_DATA_NEAR)
  89.   char far* _BIDSFUNC strnewdup(const char far* s, size_t allocSize = 0);
  90.   long atol(const char far* s);
  91. #endif
  92. #if !defined(BI_PLAT_WIN16)
  93.   wchar_t* _BIDSFUNC strnewdup(const wchar_t* s, size_t allocSize = 0);
  94.   wchar_t* _BIDSFUNC strcpy(wchar_t* dst, const wchar_t* src);
  95.   size_t   _BIDSFUNC strlen(const wchar_t* s);
  96. #endif
  97.   
  98. #endif  // OSL_INLINES_H
  99.