Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

StorageBuffer Class Reference

Class holds storage for strings including a statically allocated buffer for short strings. More...

#include <StorageBuffer.h>

Inheritance diagram for StorageBuffer:

LargeStorageBuffer RFName RFBoco RFBocoHash RFNameValue RFResult RFExpressionInfo List of all members.

Public Methods

 StorageBuffer (const char *str=0)
 Construct object out of any string buffer. More...

 StorageBuffer (const char *str, size_t len)
 Construct object out of any string buffer. More...

 StorageBuffer (const unsigned char *str, size_t len)
 Construct object out of any string buffer. More...

 StorageBuffer (const StorageBuffer& buf)
 Invoke StorageBuffer::operator=().

StorageBuffer& operator= (const StorageBuffer& buf)
 Can either use this copying method or increment and decrement the ref_count of storage buffers. More...

virtual ~StorageBuffer ()
 Invoke destroy_obj() on destruction. More...

virtual void destroy_obj ()
 Release storage on destruction. More...

const unsigned char* getBuffer () const
 Return 'unmodifyable' pointer to actual string buffer. More...

unsigned char* getBufferForWrite ()
 Return 'modifyable' pointer to actual string buffer. More...

int getAllocation () const
 Return allocation. More...

int getLength () const
 Return length. More...

size_t getRefCount () const
 Return refCount. More...

size_t hash () const
 Dragon's book's algorithm for hash values. More...

StorageBuffer* setLength (int aVal)
 Set length of string. More...

virtual int largeModelBuffer () const
 Whether or not this string is large string model object. More...

virtual size_t nextAllocation (size_t alloc) const
 Return the next allocation size for the buffer. More...

virtual StorageBuffer* duplicateStorage () const
 Duplicate the storage and return a new buffer. More...

StorageBuffer* duplicate ()
 Duplicate this object. More...

void allocateStorage (size_t alloc)
 Allocate storage to fit request. More...

void initializeStorage (char ic)
 Initialize storage to specified character. More...

void releaseStorage ()
 Release any dynamically allocated storage and point buffer to statically allocated stateBuffer.

int isShared () const
 Is the string buffer shared (reference count > 0)? More...

void incrRefCount ()
 Increment the reference count by 1.

void decrRefCount ()
 If the reference count is already 0, release the storage, otherwise reduce the reference count by 1.

StorageBuffer* setStorage (const StorageBuffer& buf)
 Set the string to the specified buf. More...

StorageBuffer* setStorage (const char *str, size_t len)
 Set the string to the specified string buffer of specified length. More...

StorageBuffer* setStorage (const unsigned char *str, size_t len)
 Set the string to the specified string buffer of specified length. More...

void setStorageStr (const char *str, size_t len)
 Set the string to the specified string of specified length. More...

void setStorageStr (const unsigned char *str, size_t len)
 Set the string to the specified string of specified length. More...

StorageBuffer* appendStorage (const StorageBuffer& buf)
 Append the specified string to the current string. More...

StorageBuffer* appendStorage (const char *str, size_t len)
 Append specified string buffer of specified length to current string. More...

StorageBuffer* appendStorage (const unsigned char *str, size_t len)
 Append specified string buffer of specified length to current string. More...

void appendStorageStr (const char *str, size_t len)
 Append specified string of specified length to the current string. More...

void appendStorageStr (const unsigned char *str, size_t len)
 Append specified string of specified length to the current string. More...

StorageBuffer* prependStorage (const StorageBuffer& buf)
 Prepend the specified string to the current string. More...

StorageBuffer* prependStorage (const char *str, size_t len)
 Prepend specified string buffer of specified length to current string. More...

StorageBuffer* prependStorage (const unsigned char *str, size_t len)
 Prepend specified string buffer of specified length to current string. More...

void prependStorageStr (const char *str, size_t len)
 Prepend specified string of specified length to the current string. More...

void prependStorageStr (const unsigned char *str, size_t len)
 Prepend specified string of specified length to the current string. More...

void setLengthFromStrlen ()
 Set the length of the string from the string length (strlen) of the current buffer.

unsigned char& operator[] (int i)
 Return reference to ith member of the string. More...

const unsigned char& operator[] (int i) const
 Return reference to ith member of the string. More...

int compare (const StorageBuffer& b) const
 Compare two strings. More...

int compare_no_case (const StorageBuffer& b) const
 Compare two strings paying no attention to case. More...


Static Public Methods

size_t StringLength (const char *iBuffer)
 Return the string length so that inline functions don't directly see strlen which is included from different places on different platforms.


Protected Attributes

unsigned char* buffer
 Pointer to current string.

unsigned char staticBuffer [static_buffer_size]
 Statically allocated buffer for short strings.

size_t allocation
 Current total allocation.

size_t length
 Current length of the string.

size_t refCount
 Reference count to storage. More...


Friends

int operator== (const StorageBuffer& a, const StorageBuffer& b)
 Returns 1 if strings a and b are equal (strcmp). More...

int operator!= (const StorageBuffer& a, const StorageBuffer& b)
 Return !StorageBuffer::operator==.


Detailed Description

Class holds storage for strings including a statically allocated buffer for short strings.

Manages setting, appending and prepending of strings. Variety of constructors for ease of use with character buffers (char *'s) and literal strings (const char *).

Examples:

exmesh_impl.cxx, test_blk.C, and test_blkinter.C.


Constructor & Destructor Documentation

StorageBuffer::StorageBuffer ( const char * str = 0 )
 

Construct object out of any string buffer.

Initializes string to nil then appends passed string. If str not specified or is 0, string is empty string.

See also:
appendStorageStr().
Parameters:
str   string buffer. Default argument is 0.

StorageBuffer::StorageBuffer ( const char * str,
size_t len )
 

Construct object out of any string buffer.

Initializes string to nil then appends passed string.

See also:
appendStorageStr().
Parameters:
str   string buffer.
len   length of string.

StorageBuffer::StorageBuffer ( const unsigned char * str,
size_t len )
 

Construct object out of any string buffer.

Initializes string to nil then appends passed string.

See also:
appendStorageStr().
Parameters:
str   string buffer.
len   length of string.

StorageBuffer::~StorageBuffer ( ) [inline, virtual]
 

Invoke destroy_obj() on destruction.

Having method destroy_obj() allows object to be used in type_allocator lists.

See also:
destroy() , type_allocator::~type_allocator().


Member Function Documentation

StorageBuffer & StorageBuffer::operator= ( const StorageBuffer & buf ) [inline]
 

Can either use this copying method or increment and decrement the ref_count of storage buffers.

The copy model leaves ref_count alone. Ie, the model is that the storage stored in one buffer is copied to another, but the number of objects that own the storage described by this allocator is the same. Releases current storage before the copy.

See also:
releaseStorage(). , incrRefCount() , decrRefCount().
Parameters:
buf   string to copy.

void StorageBuffer::destroy_obj ( ) [inline, virtual]
 

Release storage on destruction.

See also:
releaseStorage().

Reimplemented in RFBoco, RFName, RFNameValue, and RFResult.

const unsigned char * StorageBuffer::getBuffer ( ) const [inline]
 

Return 'unmodifyable' pointer to actual string buffer.

Returns:
buffer.
Examples:
test_blk.C, and test_blkinter.C.

unsigned char * StorageBuffer::getBufferForWrite ( ) [inline]
 

Return 'modifyable' pointer to actual string buffer.

Returns:
buffer.

int StorageBuffer::getAllocation ( ) const [inline]
 

Return allocation.

Returns:
allocation.

int StorageBuffer::getLength ( ) const [inline]
 

Return length.

Returns:
length.

size_t StorageBuffer::getRefCount ( ) const [inline]
 

Return refCount.

Returns:
refCount.

size_t StorageBuffer::hash ( ) const
 

Dragon's book's algorithm for hash values.

Returns:
hash value for string.

StorageBuffer * StorageBuffer::setLength ( int aVal )
 

Set length of string.

Parameters:
aVal   new length of string.

int StorageBuffer::largeModelBuffer ( ) const [virtual]
 

Whether or not this string is large string model object.

Application might choose to manipulate large strings differently.

Returns:
0.

Reimplemented in LargeStorageBuffer.

size_t StorageBuffer::nextAllocation ( size_t alloc ) const [virtual]
 

Return the next allocation size for the buffer.

StorageBuffer allocates space in blocks.

Parameters:
alloc   desired allocation.
Returns:
actual next allocation that should be used.

Reimplemented in LargeStorageBuffer.

StorageBuffer * StorageBuffer::duplicateStorage ( ) const [virtual]
 

Duplicate the storage and return a new buffer.

Returns:
literal copy of storage. Returned buffer owns the storage.

Reimplemented in LargeStorageBuffer.

StorageBuffer * StorageBuffer::duplicate ( ) [inline]
 

Duplicate this object.

Used right before we reset the string for this object so that shared buffer not destroyed.

Returns:
clone of this object. If string buffer not shared, returns itself. If it is shared, returns a copy and decrements the reference count.

void StorageBuffer::allocateStorage ( size_t alloc )
 

Allocate storage to fit request.

Parameters:
alloc   requested allocation.

void StorageBuffer::initializeStorage ( char ic )
 

Initialize storage to specified character.

Parameters:
ic   initialization character.

int StorageBuffer::isShared ( ) const [inline]
 

Is the string buffer shared (reference count > 0)?

Returns:
if refCount > 0, return 1; otherwise 0.

StorageBuffer * StorageBuffer::setStorage ( const StorageBuffer & buf ) [inline]
 

Set the string to the specified buf.

Invoke setStorage(const char *, size_t).

Parameters:
buf   string buffer.
Returns:
new updated storage buffer.

StorageBuffer * StorageBuffer::setStorage ( const char * str,
size_t len ) [inline]
 

Set the string to the specified string buffer of specified length.

Invokes setStorage(const unsigned char *, size_t)

Parameters:
str   string buffer.
len   length of string.
Returns:
updated storage buffer.

StorageBuffer * StorageBuffer::setStorage ( const unsigned char * str,
size_t len ) [inline]
 

Set the string to the specified string buffer of specified length.

Duplicates storage (so as to maintain shared copies of current buffer), then updates the string.

See also:
duplicate() , setStorageStr(const unsigned char *, size_t).
Parameters:
str   string buffer.
len   length of string.
Returns:
updated storage buffer.

void StorageBuffer::setStorageStr ( const char * str,
size_t len ) [inline]
 

Set the string to the specified string of specified length.

See also:
setStorageStr(const unsigned char *, size_t).
Parameters:
str   string buffer.
len   length of string.

void StorageBuffer::setStorageStr ( const unsigned char * str,
size_t len ) [inline]
 

Set the string to the specified string of specified length.

Releases current storage then copies string to buffer.

See also:
releaseStorage() , appendStorageStr().
Parameters:
str   string buffer.
len   length of string.

StorageBuffer * StorageBuffer::appendStorage ( const StorageBuffer & buf ) [inline]
 

Append the specified string to the current string.

Invoke setStorage(const char *, size_t).

Parameters:
buf   string buffer.
Returns:
new updated storage buffer.

StorageBuffer * StorageBuffer::appendStorage ( const char * str,
size_t len ) [inline]
 

Append specified string buffer of specified length to current string.

Invokes appendStorage()(const unsigned char *, size_t).

Parameters:
str   string buffer.
len   length of string.
Returns:
updated storage buffer.

StorageBuffer * StorageBuffer::appendStorage ( const unsigned char * str,
size_t len ) [inline]
 

Append specified string buffer of specified length to current string.

Duplicates storage (so as to maintain shared copies of current buffer), then updates the string.

See also:
duplicate() , appendStorageStr(const unsigned char *, size_t).
Parameters:
str   string buffer.
len   length of string.
Returns:
updated storage buffer.

void StorageBuffer::appendStorageStr ( const char * str,
size_t len ) [inline]
 

Append specified string of specified length to the current string.

See also:
appendStorageStr(const unsigned char *, size_t).
Parameters:
str   string buffer.
len   length of string.

void StorageBuffer::appendStorageStr ( const unsigned char * str,
size_t len )
 

Append specified string of specified length to the current string.

Parameters:
str   string buffer.
len   length of string.

StorageBuffer * StorageBuffer::prependStorage ( const StorageBuffer & buf ) [inline]
 

Prepend the specified string to the current string.

Invoke setStorage(const char *, size_t).

Parameters:
buf   string buffer.
Returns:
new updated storage buffer.

StorageBuffer * StorageBuffer::prependStorage ( const char * str,
size_t len ) [inline]
 

Prepend specified string buffer of specified length to current string.

Invokes appendStorage()(const unsigned char *, size_t).

Parameters:
str   string buffer.
len   length of string.
Returns:
updated storage buffer.

StorageBuffer * StorageBuffer::prependStorage ( const unsigned char * str,
size_t len ) [inline]
 

Prepend specified string buffer of specified length to current string.

Duplicates storage (so as to maintain shared copies of current buffer), then updates the string.

See also:
duplicate() , appendStorageStr(const unsigned char *, size_t).
Parameters:
str   string buffer.
len   length of string.
Returns:
updated storage buffer.

void StorageBuffer::prependStorageStr ( const char * str,
size_t len ) [inline]
 

Prepend specified string of specified length to the current string.

See also:
appendStorageStr(const unsigned char *, size_t).
Parameters:
str   string buffer.
len   length of string.

void StorageBuffer::prependStorageStr ( const unsigned char * str,
size_t len )
 

Prepend specified string of specified length to the current string.

Parameters:
str   string buffer.
len   length of string.

unsigned char & StorageBuffer::operator[] ( int i )
 

Return reference to ith member of the string.

Returns:
reference to ith member of the string.

Reimplemented in LargeStorageBuffer.

const unsigned char & StorageBuffer::operator[] ( int i ) const
 

Return reference to ith member of the string.

Returns:
reference to ith member of the string.

Reimplemented in LargeStorageBuffer.

int StorageBuffer::compare ( const StorageBuffer & b ) const
 

Compare two strings.

Parameters:
b   string to compare.
Returns:
<0 if this < b, 0 a == b, > 0 a > b.

int StorageBuffer::compare_no_case ( const StorageBuffer & b ) const
 

Compare two strings paying no attention to case.

Parameters:
b   string to compare.
Returns:
<0 if this < b, 0 a == b, > 0 a > b.


Friends And Related Function Documentation

int operator== ( const StorageBuffer & a,
const StorageBuffer & b ) [friend]
 

Returns 1 if strings a and b are equal (strcmp).

Parameters:
a   operand 1.
b   operand 2.
Returns:
if strings specified by a and b are equal return 1; otherwise 0.


Member Data Documentation

size_t StorageBuffer::refCount [protected]
 

Reference count to storage.

This object is designed for use in larger systems that reference count. Users can use reference count externally or simply copy the string.

See also:
StorageBuffer::operator=().


The documentation for this class was generated from the following file:
Generated at Wed Mar 2 11:18:59 2005 for Result Library by doxygen1.2.0 written by Dimitri van Heesch, © 1997-2000