home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
IBMCLASS
/
IBUFFER.INL
< prev
next >
Wrap
Text File
|
1993-10-22
|
4KB
|
110 lines
#ifndef _IBUFFER_INL_
#define _IBUFFER_INL_ 0
/*******************************************************************************
* FILE NAME: ibuffer.inl *
* *
* DESCRIPTION: *
* This file contains the definition of the inline functions for the *
* class(es) declared in ibuffer.hpp. *
* *
* COPYRIGHT: *
* Licensed Materials - Property of IBM *
* (C) Copyright IBM Corporation 1992, 1993 *
* All Rights Reserved *
* US Government Users Restricted Rights - Use, duplication, or *
* disclosure *
* restricted by GSA ADP Schedule Contract with IBM Corp. *
* *
*******************************************************************************/
#ifndef _IBUFFER_
#undef _IBUFFER_INL_
#define _IBUFFER_INL_ 1
#include <ibuffer.hpp>
#endif
extern "C"
{
#include <limits.h>
}
#ifndef _IEXCBASE_
#include <iexcbase.hpp>
#endif
#if _IBUFFER_INL_
#define inline
#endif
#pragma info(nopar)
/*---------------------------- Overflow Checking -----------------------------*/
inline unsigned IBuffer :: checkAddition ( unsigned addend1, unsigned addend2 )
{
return ( addend1 < UINT_MAX - addend2 ) ? addend1 + addend2 : overflow();
}
inline unsigned IBuffer :: checkMultiplication ( unsigned factor1, unsigned factor2 )
{
return ( factor1 < UINT_MAX / factor2 ) ? factor1 * factor2 : overflow();
}
/*--------------------------------- Private ----------------------------------*/
#ifdef __DEBUG_ALLOC__
inline void * IBuffer :: operator new ( size_t size,
const char * filename, size_t linenum,
unsigned realSize )
{
void *p = ::operator new (checkAddition( sizeof( IBuffer ), realSize ),
filename, linenum );
return p;
}
inline void IBuffer :: operator delete ( void *p,
const char * filename,
size_t linenum)
{
::operator delete ((char*)p, filename, linenum);
}
#else
inline void * IBuffer :: operator new ( size_t size, unsigned realSize )
{
void *p = ::new char[ checkAddition( sizeof( IBuffer ), realSize ) ];
return p;
}
#endif
/*---------------------------- Reference Counting ----------------------------*/
inline void IBuffer :: addRef ( )
{
refs++;
}
inline void IBuffer :: removeRef ( )
{
#ifdef IC_DEVELOP
IASSERT( refs != 0 );
#endif
if ( --refs == 0 )
delete this;
}
/*-------------------------------- Accessors ---------------------------------*/
inline unsigned IBuffer :: useCount ( ) const
{
return refs;
}
inline unsigned IBuffer :: length ( ) const
{
return len;
}
inline const char *IBuffer :: contents ( ) const
{
return data;
}
inline char *IBuffer :: contents ( )
{
return data;
}
inline IBuffer *IBuffer :: fromContents ( const char *p )
{
return (IBuffer*)( p - offsetof( IBuffer, data ) );
}
#pragma info(restore)
#endif // _IBUFFER_INL_