home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / IBMCLASS / IBUFFER.INL < prev    next >
Text File  |  1993-10-22  |  4KB  |  110 lines

  1. #ifndef _IBUFFER_INL_
  2. #define _IBUFFER_INL_ 0
  3. /*******************************************************************************
  4. * FILE NAME: ibuffer.inl                                                       *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   This file contains the definition of the inline functions for the          *
  8. *   class(es) declared in ibuffer.hpp.                                         *
  9. *                                                                              *
  10. * COPYRIGHT:                                                                   *
  11. *   Licensed Materials - Property of IBM                                       *
  12. *   (C) Copyright IBM Corporation 1992, 1993                                   *
  13. *   All Rights Reserved                                                        *
  14. *   US Government Users Restricted Rights - Use, duplication, or               *
  15. *   disclosure                                                                 *
  16. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  17. *                                                                              *
  18. *******************************************************************************/
  19. #ifndef _IBUFFER_
  20.   #undef  _IBUFFER_INL_
  21.   #define _IBUFFER_INL_ 1
  22.   #include <ibuffer.hpp>
  23. #endif
  24.  
  25. extern "C"
  26.   {
  27.   #include <limits.h>
  28.   }
  29.  
  30. #ifndef _IEXCBASE_
  31.   #include <iexcbase.hpp>
  32. #endif
  33.  
  34. #if _IBUFFER_INL_
  35.   #define inline
  36. #endif
  37.  
  38. #pragma info(nopar)
  39.  
  40. /*---------------------------- Overflow Checking -----------------------------*/
  41. inline unsigned IBuffer :: checkAddition ( unsigned addend1, unsigned addend2 )
  42.   {
  43.   return ( addend1 < UINT_MAX - addend2 ) ? addend1 + addend2 : overflow();
  44.   }
  45. inline unsigned IBuffer :: checkMultiplication ( unsigned factor1, unsigned factor2 )
  46.   {
  47.   return ( factor1 < UINT_MAX / factor2 ) ? factor1 * factor2 : overflow();
  48.   }
  49. /*--------------------------------- Private ----------------------------------*/
  50. #ifdef __DEBUG_ALLOC__
  51. inline void * IBuffer :: operator new ( size_t size,
  52.                                         const char * filename, size_t linenum,
  53.                                         unsigned realSize )
  54.   {
  55.   void *p = ::operator new (checkAddition( sizeof( IBuffer ), realSize ),
  56.                            filename, linenum   );
  57.   return p;
  58.   }
  59. inline void IBuffer :: operator delete ( void *p,
  60.                                          const char * filename,
  61.                                          size_t linenum)
  62.   {
  63.   ::operator delete ((char*)p, filename, linenum);
  64.   }
  65. #else
  66. inline void * IBuffer :: operator new ( size_t size, unsigned realSize )
  67.   {
  68.   void *p = ::new char[ checkAddition( sizeof( IBuffer ), realSize ) ];
  69.   return p;
  70.   }
  71. #endif
  72. /*---------------------------- Reference Counting ----------------------------*/
  73. inline void IBuffer :: addRef ( )
  74.   {
  75.   refs++;
  76.   }
  77. inline void IBuffer :: removeRef ( )
  78.   {
  79.   #ifdef IC_DEVELOP
  80.     IASSERT( refs != 0 );
  81.   #endif
  82.   if ( --refs == 0 )
  83.     delete this;
  84.   }
  85. /*-------------------------------- Accessors ---------------------------------*/
  86. inline unsigned IBuffer :: useCount ( ) const
  87.   {
  88.   return refs;
  89.   }
  90. inline unsigned IBuffer :: length ( ) const
  91.   {
  92.   return len;
  93.   }
  94. inline const char *IBuffer :: contents ( ) const
  95.   {
  96.   return data;
  97.   }
  98. inline char *IBuffer :: contents ( )
  99.   {
  100.   return data;
  101.   }
  102. inline IBuffer *IBuffer :: fromContents ( const char *p )
  103.   {
  104.   return (IBuffer*)( p - offsetof( IBuffer, data ) );
  105.   }
  106.  
  107. #pragma info(restore)
  108.  
  109. #endif // _IBUFFER_INL_
  110.