home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / include / ibuffer.inl < prev    next >
Encoding:
Text File  |  1996-02-22  |  2.8 KB  |  93 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. *   classes declared in ibuffer.hpp.                                           *
  9. *                                                                              *
  10. * COPYRIGHT:                                                                   *
  11. *   IBM Open Class Library                                                     *
  12. *   (C) Copyright International Business Machines Corporation 1992, 1996       *
  13. *   Licensed Material - Program-Property of IBM - All Rights Reserved.         *
  14. *   US Government Users Restricted Rights - Use, duplication, or disclosure    *
  15. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  16. *                                                                              *
  17. *******************************************************************************/
  18. #ifndef _IBUFFER_
  19.   #undef  _IBUFFER_INL_
  20.   #define _IBUFFER_INL_ 1
  21.   #include <ibuffer.hpp>
  22. #endif
  23.  
  24. extern "C" {
  25.   #include <limits.h>
  26. }
  27.  
  28. #include <iexcbase.hpp>
  29.  
  30. #if _IBUFFER_INL_
  31.   #define inline
  32. #endif
  33.  
  34. #pragma info(nopar)
  35.  
  36. /*---------------------------- Overflow Checking -----------------------------*/
  37. inline unsigned IBuffer :: checkAddition ( unsigned addend1, unsigned addend2 )
  38.   {
  39.   return ( addend1 < UINT_MAX - addend2 ) ? addend1 + addend2 : overflow();
  40.   }
  41. inline unsigned IBuffer :: checkMultiplication ( unsigned factor1,
  42.                                                  unsigned factor2 )
  43.   {
  44.   return ( factor1 < UINT_MAX / factor2 ) ? factor1 * factor2 : overflow();
  45.   }
  46. /*---------------------------- Reference Counting ----------------------------*/
  47. inline void IBuffer :: addRef ( )
  48.   {
  49.   refs++;
  50.   }
  51. inline void IBuffer :: removeRef ( )
  52.   {
  53.   #ifdef IC_DEVELOP
  54.     IASSERT( refs != 0 );
  55.   #endif
  56.   if ( --refs == 0 )
  57.     delete this;
  58.   }
  59. /*-------------------------------- Accessors ---------------------------------*/
  60. inline unsigned IBuffer :: useCount ( ) const
  61.   {
  62.   return refs;
  63.   }
  64. inline unsigned IBuffer :: length ( ) const
  65.   {
  66.   return len;
  67.   }
  68. inline const char *IBuffer :: contents ( ) const
  69.   {
  70.   return data;
  71.   }
  72. inline char *IBuffer :: contents ( )
  73.   {
  74.   return data;
  75.   }
  76.  
  77. #if 0     // moved these functions to ibuffer0.cpp for SOM
  78.  
  79.  
  80. inline IBuffer *IBuffer :: fromContents ( const char *p )
  81.   {
  82.   return (IBuffer*)( p - offsetof( IBuffer, data ) );
  83.   }
  84.  
  85.  
  86. #endif // for SOM
  87.  
  88.  
  89.  
  90. #pragma info(restore)
  91.  
  92. #endif // _IBUFFER_INL_
  93.