home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
IBMCLASS
/
IBUFFER.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-22
|
18KB
|
381 lines
#ifndef _IBUFFER_
#define _IBUFFER_
/*******************************************************************************
* FILE NAME: ibuffer.hpp *
* *
* DESCRIPTION: *
* This file contains the declaration(s) of the class(es): *
* IBuffer - class to hold IString contents *
* *
* 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. *
* *
*******************************************************************************/
extern "C"
{
#include <stddef.h>
}
#ifndef _IVBASE_
#include <ivbase.hpp>
#endif
#ifndef _ISTRENUM_
#include <istrenum.hpp>
#endif
/*----------------------------------------------------------------------------*/
/* Align classes on four byte boundary. */
/*----------------------------------------------------------------------------*/
#pragma pack(4)
class IStringTest;
class IBuffer : public IVBase {
/*******************************************************************************
* The IBuffer class defines the contents of an IString. *
* *
* Notes: *
* *
* 1) This class is intended only to support the implementation of the *
* IString class. Objects of this class should not be created or *
* manipulated except through the containing IString object. *
* *
* 2) Use the following information to guide you when allocating *
* objects of this class: *
* *
* - Subclasses must not add any data members. *
* *
* - The operator new is protected so that it can be called only from *
* the newBuffer member function. *
* *
* - The destructor is protected so that instances of this class cannot *
* easily be created on the stack or as statics. *
*******************************************************************************/
public:
/*------------------------------- Reallocating ---------------------------------
| The following function manages the reallocation of IBuffers when |
| strings' contents are modified: |
| newBuffer - Allocates a new buffer and initializes it with the |
| contents of up to three argument buffers. |
| checkAddition - Verifies that the two arguments, when added, will |
| not overflow an unsigned int. |
| checkMultiplication - Verifies that the two arguments, when multiplied, |
| will not overflow an unsigned int. |
| overflow - Function that throws exception when overflow is |
| detected by checkAddition or checkMultiplication. |
| setDefaultBuffer - Sets the default (null) buffer; the argument buffer |
| must be comprised of a single null byte. |
------------------------------------------------------------------------------*/
IBuffer
*newBuffer( const void *p1, unsigned len1,
const void *p2 = 0, unsigned len2 = 0,
const void *p3 = 0, unsigned len3 = 0,
char padChar = 0 ) const;
static unsigned
checkAddition ( unsigned addend1, unsigned addend2 ),
checkMultiplication ( unsigned factor1, unsigned factor2 ),
overflow ( );
static void
setDefaultBuffer( IBuffer *newDefaultBuffer );
/*-------------------------------- Accessing -----------------------------------
| The following functions provide access to various attributes of a buffer: |
| null - Returns the address of the null buffer. |
| useCount - Returns the number of IStrings that refer to the buffer. |
| length - Returns the length of the buffer's contents. |
| contents - Returns the address of the buffer's contents. |
| defaultBuffer - Static member function that returns the address of the |
| null buffer for the class. |
| fromContents - Static member function that returns the address of |
| IBuffer, given a pointer to its contents. |
| charType - Returns the type of a character at a given index. |
| next - Returns a pointer to the next character, not the next |
| byte, in the buffer. |
------------------------------------------------------------------------------*/
static IBuffer
*defaultBuffer ( ),
*fromContents ( const char *pBuffer );
IBuffer
*null ( ) const;
unsigned
useCount ( ) const,
length ( ) const;
const char
*contents ( ) const;
char
*contents ( );
virtual IStringEnum::CharType
charType ( unsigned index ) const;
virtual char
*next ( const char *prev );
virtual const char
*next ( const char *prev ) const;
/*---------------------------- Reference Counting ------------------------------
| The following functions manage the buffer reference count: |
| addRef - Increments the usage count. |
| removeRef - Decrements the usage count and deletes the buffer when the |
| usage count goes to 0. |
------------------------------------------------------------------------------*/
void
addRef ( ),
removeRef ( );
/*-------------------------------- Comparing -----------------------------------
| The following functions permit the IBuffer's contents to be compared to |
| some other character array: |
| Comparison - Enumeration of the possible return codes from |
| IBuffer::compare. |
| compare - Compares the buffer to an argument character array. |
------------------------------------------------------------------------------*/
typedef enum
{
equal,
greaterThan,
lessThan
} Comparison;
virtual Comparison
compare ( const void *p,
unsigned len ) const;
/*-------------------------------- Character Subsetting ------------------------
| The following function is used when a subset of characters is required: |
| subString - Returns a new IBuffer, of the same type as the previous one, |
| that contains the specified subset of characters. |
------------------------------------------------------------------------------*/
virtual IBuffer
*subString ( unsigned startPos,
unsigned len,
char padCharacter ) const;
/*-------------------------------- Diagnostics ---------------------------------
| The following function provides diagnostic information about the buffer: |
| asDebugInfo - Returns information about the buffer's internal |
| representation that can be used for debugging.
------------------------------------------------------------------------------*/
virtual IString
asDebugInfo ( ) const;
/*--------------------------------- Testing ------------------------------------
| The following functions are called by the corresponding IString functions |
| to test the buffer's contents: |
| isAlphanumeric- See IString::isAlphanumeric. |
| isAlphabetic - See IString::isAlphabetic. |
| isASCII - See IString::isASCII. |
| isControl - See IString::isControl. |
| isDigits - See IString::isDigits. |
| isGraphics - See IString::isGraphics. |
| isHexDigits - See IString::isHexDigits. |
| isLowerCase - See IString::isLowerCase. |
| isPrintable - See IString::isPrintable. |
| isPunctuation - See IString::isPunctuation. |
| isUpperCase - See IString::isUpperCase. |
| isWhiteSpace - See IString::isWhiteSpace. |
| isDBCS - See IString::isDBCS. |
| isSBCS - See IString::isSBCS. |
| isValidDBCS - See IString::isValidDBCS. |
| includesDBCS - See IString::includesDBCS. |
| includesSBCS - See IString::includesSBCS. |
------------------------------------------------------------------------------*/
virtual Boolean
isAlphanumeric( ) const,
isAlphabetic ( ) const,
isASCII ( ) const,
isControl ( ) const,
isDigits ( ) const,
isGraphics ( ) const,
isHexDigits ( ) const,
isLowerCase ( ) const,
isPrintable ( ) const,
isPunctuation ( ) const,
isUpperCase ( ) const,
isWhiteSpace ( ) const,
isDBCS ( ) const,
isSBCS ( ) const,
isValidDBCS ( ) const,
includesDBCS ( ) const,
includesSBCS ( ) const;
/*-------------------------------- Searching -----------------------------------
| The following functions are called by the corresponding IString |
| functions to search the buffer's contents: |
| indexOf - See IString::indexOf. |
| indexOfAnyBut - See IString::indexOfAnyBut. |
| indexOfAnyOf - See IString::indexOfAnyOf. |
| lastIndexOf - See IString::lastIndexOf. |
| lastIndexOfAnyBut - See IString::lastIndexOfAnyBut. |
| lastIndexOfAnyOf - See IString::lastIndexOfAnyOf. |
------------------------------------------------------------------------------*/
virtual unsigned
indexOf ( const char *pString,
unsigned len,
unsigned startPos = 1 ) const,
indexOf ( const IStringTest &aTest,
unsigned startPos = 1 ) const,
indexOfAnyBut ( const char *pString,
unsigned len,
unsigned startPos = 1 ) const,
indexOfAnyBut ( const IStringTest &aTest,
unsigned startPos = 1 ) const,
indexOfAnyOf ( const char *pString,
unsigned len,
unsigned startPos = 1 ) const,
indexOfAnyOf ( const IStringTest &aTest,
unsigned startPos = 1 ) const,
lastIndexOf ( const char *pString,
unsigned len,
unsigned startPos = 0 ) const,
lastIndexOf ( const IStringTest &aTest,
unsigned startPos = 0 ) const,
lastIndexOfAnyBut ( const char *pString,
unsigned len,
unsigned startPos = 0 ) const,
lastIndexOfAnyBut ( const IStringTest &aTest,
unsigned startPos = 0 ) const,
lastIndexOfAnyOf ( const char *pString,
unsigned len,
unsigned startPos = 0 ) const,
lastIndexOfAnyOf ( const IStringTest &aTest,
unsigned startPos = 0 ) const;
/*--------------------------------- Editing ------------------------------------
The following functions are called by the corresponding IString functions
to edit the buffer's contents:
center - See IString::center.
change - See IString::change.
copy - See IString::copy.
insert - See IString::insert.
leftJustify - See IString::leftJustify.
lowerCase - See IString::lowerCase.
overlayWith - See IString::overlayWith.
remove - See IString::remove.
reverse - See IString::reverse.
rightJustify - See IString::rightJustify.
strip - See IString::strip.
translate - See IString::translate.
upperCase - See IString::upperCase.
------------------------------------------------------------------------------*/
virtual IBuffer
*center ( unsigned newLen,
char padCharacter ),
*change ( const char *pSource,
unsigned sourceLen,
const char *pTarget,
unsigned targetLen,
unsigned startPos,
unsigned numChanges ),
*copy ( unsigned numCopies ),
*insert ( const char *pInsert,
unsigned insertLen,
unsigned pos,
char padCharacter ),
*leftJustify ( unsigned newLen,
char padCharacter ),
*lowerCase ( ),
*overlayWith ( const char *overlay,
unsigned len,
unsigned pos,
char padCharacter ),
*remove ( unsigned startPos,
unsigned numChars ),
*reverse ( ),
*rightJustify ( unsigned newLen,
char padCharacter ),
*strip ( const char *pChars,
unsigned len,
IStringEnum::StripMode mode ),
*strip ( const IStringTest &aTest,
IStringEnum::StripMode mode ),
*translate ( const char *pInputChars,
unsigned inputLen,
const char *pOutputChars,
unsigned outputLen,
char padCharacter ),
*upperCase ( );
protected:
/*------------------------------ Implementing ----------------------------------
The following functions provide utilities used to implement this class:
startSearch - Initializes an indexOf search.
startBackwardsSearch - Initializes a lastIndexOf search.
allocate - Returns a new buffer of the required length.
operator new - Allocates space for a buffer of the specified
length.
operator delete - Deallocates a buffer.
dbcsTable - Table of DBCS first-byte flags ('dbcsTable[n] == 1'
if and only if n is a valid DBCS first byte).
initialize - Static member function used to initialize (set up
null buffer, DBCS table, and so forth).
className - Returns the name of the class (IBuffer).
------------------------------------------------------------------------------*/
virtual unsigned
startSearch ( unsigned startPos,
unsigned searchLen ) const,
startBackwardsSearch ( unsigned startPos,
unsigned searchLen ) const;
virtual IBuffer
*allocate ( unsigned bufLength ) const;
#ifdef __DEBUG_ALLOC__
void *operator new ( size_t t, const char * filename, size_t linenum, unsigned bufLen );
void operator delete ( void *p, const char * filename, size_t linenum );
#else
void *operator new ( size_t t, unsigned bufLen );
void operator delete ( void *p );
#endif
static char
dbcsTable[ 256 ];
static IBuffer
*initialize ( );
virtual const char
*className ( ) const;
/*-------------------------- Constructor/Destructor ----------------------------
The constructor for this class requires the length of the buffer (the
value to be stored in the length data member).
------------------------------------------------------------------------------*/
IBuffer ( unsigned newLen );
~IBuffer ( );
private:
/*--------------------------------- Private ----------------------------------*/
unsigned
refs,
len;
char
data[1];
static IBuffer
*nullBuffer;
};
/*----------------------------------------------------------------------------*/
/* Resume compiler default packing. */
/*----------------------------------------------------------------------------*/
#pragma pack()
#ifndef I_NO_INLINES
#include <ibuffer.inl>
#endif
#endif