ztring.c: A few important extension for <string.h>
 All Classes Files Functions Variables Enumerator Friends Macros
Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
zchz Class Reference

Contains a memory block of 'SIZE' characters in between 3 memory blocks of that same 'zchz::SIZE'. More...

#include <zchz.h>

Public Member Functions

 zchz (size_t n)
 Constructor. More...
 
 zchz (const char *str)
 Constructor. More...
 
size_t strsz () const
 Get current block size. More...
 
zchzoperator++ ()
 ++p More...
 
zchzoperator+= (size_t n)
 ZCHZ[i]. More...
 
char & operator[] (size_t i)
 ZCHZ += i. More...
 
 operator char * ()
 Returns the stored string (non-const operator). More...
 
 operator const char * () const
 Returns the stored string (const operator). More...
 

Private Types

enum  { SIZE = 200, adjust_SIZE = (SIZE+1)*16, real_SIZE = ( SIZE%16==0 ? SIZE : adjust_SIZE/16 ), RZ = real_SIZE }
 
enum  {
  before_overwrite = 1, after_overwrite = 2, size_is_0_or_too_large = 3, pointer_out_of_bounce = 4,
  index_out_of_bounce = 5, invalid_pointer_difference = 6, unknow_error = 7
}
 

Private Member Functions

void set (size_t size)
 Set the internal will have size equal to 'size'. More...
 
void set (const char *str)
 Set the internal block to the value to 'str'. More...
 
void reset_filling ()
 Initializes the block that surroung the stored value. More...
 
void check ()
 Checks whether the memory around the string value holds the value stored method set(). More...
 

Private Attributes

int m_errno
 Error code. More...
 
size_t m_idx
 Current offset for pointer access. More...
 
size_t m_size
 Current size of stored value. More...
 
char m_block [3 *real_SIZE]
 Stored string value. More...
 

Friends

ptrdiff_t operator- (char *l, zchz &r)
 
ptrdiff_t operator- (zchz &l, char *r)
 
char * operator+ (zchz &l, int i)
 

Detailed Description

Contains a memory block of 'SIZE' characters in between 3 memory blocks of that same 'zchz::SIZE'.

The stored value can be retrieved using 'operator char*()' and it is aligned to an 16 byte word.

Definition at line 25 of file zchz.h.

Member Enumeration Documentation

anonymous enum
private
Enumerator
SIZE 

Max block size (change it if you need more)

adjust_SIZE 
real_SIZE 

Size of the allocated block for any 'zchz'.

RZ 

Abreviation for real_SIZE.

Definition at line 26 of file zchz.h.

anonymous enum
private
Enumerator
before_overwrite 
after_overwrite 
size_is_0_or_too_large 
pointer_out_of_bounce 
index_out_of_bounce 
invalid_pointer_difference 
unknow_error 

Definition at line 58 of file zchz.h.

Constructor & Destructor Documentation

zchz::zchz ( size_t  n)
inline

Constructor.

Definition at line 39 of file zchz.h.

zchz::zchz ( const char *  str)
inline

Constructor.

Definition at line 40 of file zchz.h.

Member Function Documentation

size_t zchz::strsz ( ) const
inline

Get current block size.

Definition at line 42 of file zchz.h.

zchz & zchz::operator++ ( )
inline

++p

Definition at line 151 of file zchz.h.

zchz & zchz::operator+= ( size_t  n)
inline

ZCHZ[i].

When 'i' is too big, returns ZCHZ[ ZCHZ.strsz() ] (one past the final character). ZCHZ[ ZCHZ.strsz() ] is not flagged as an invalid reference (but changing that character will be flagged later).

Definition at line 166 of file zchz.h.

char & zchz::operator[] ( size_t  i)
inline

ZCHZ += i.

When 'i' is too big, ZCHZ will point to ZCHZ[ ZCHZ.strsz() ] (one past the final character). ZCHZ[ ZCHZ.strsz() ] is not flagged as an invalid reference (but changing that character will be flagged later).

Definition at line 181 of file zchz.h.

zchz::operator char * ( )
inline

Returns the stored string (non-const operator).

Definition at line 193 of file zchz.h.

zchz::operator const char * ( ) const
inline

Returns the stored string (const operator).

Definition at line 199 of file zchz.h.

void zchz::set ( size_t  size)
inlineprivate

Set the internal will have size equal to 'size'.

No char value is used for initializing the memory block. When 'size' is too big or zero, the block size is set to 'SIZE'.

Definition at line 124 of file zchz.h.

void zchz::set ( const char *  str)
inlineprivate

Set the internal block to the value to 'str'.

The for the block will be 1+strlen(str). When 'size' is too big no memory size adjusted is performed and the string is not copied.

Definition at line 146 of file zchz.h.

void zchz::reset_filling ( )
inlineprivate

Initializes the block that surroung the stored value.

Definition at line 110 of file zchz.h.

void zchz::check ( )
inlineprivate

Checks whether the memory around the string value holds the value stored method set().

When this method returns 'false' it usually means that a memory lick happened. Resets to zero the current error number 'm_errno'.

Definition at line 76 of file zchz.h.

Friends And Related Function Documentation

ptrdiff_t operator- ( char *  l,
zchz r 
)
friend

Definition at line 204 of file zchz.h.

ptrdiff_t operator- ( zchz l,
char *  r 
)
friend

Definition at line 221 of file zchz.h.

char* operator+ ( zchz l,
int  i 
)
friend

Definition at line 236 of file zchz.h.

Member Data Documentation

int zchz::m_errno
private

Error code.

Definition at line 34 of file zchz.h.

size_t zchz::m_idx
private

Current offset for pointer access.

Definition at line 35 of file zchz.h.

size_t zchz::m_size
private

Current size of stored value.

Definition at line 36 of file zchz.h.

char zchz::m_block[3 *real_SIZE]
private

Stored string value.

Definition at line 37 of file zchz.h.


The documentation for this class was generated from the following file: