Humble Framework for SkyOS


Main Page | Modules | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

Base


Detailed Description

The Base module includes all classes and functions that are mandatory, i.e, the MUST be included in any application built with the Humble framework. To include all Base classes and definitions, the file Humble.h should be the first header file in any given source file.

Portable alias for the "memory comparison" RTL function (memcmp)

STR_* macros text string pointers for validity. These wrap the "safe" versions of the different RTL functions that check for NULL pointers or respect a caller-supplied maximum value.

Counts the number of times a character occurs in a string


Data Structures

class  HObj
 All Humble Framework classes are derived from this object. More...
class  HObjNoCopy
 Subclass of HObj that prevents and object from being copied. More...
class  HID
 Mix-in class that adds an "ID" to any class. More...
class  HError
 Stores error information. More...
class  HMemory
 The HMemory class manages a dynamic memory buffer. More...
class  HMem< BUFFER_SIZE >
 Manages a small (<4KB) buffer by pre-allocating the memory. More...
class  HPtr< T >
 HPtr template class. More...
class  HString
 Dynamically allocated string class with reference counting. More...
class  HStr< MAX_LEN >
 Manages small (<4KB) strings by pre-allocating the buffer. More...
class  HClass
 Brief description of the class. More...

Defines

#define TEXT(p)   ((unsigned char *)(p))
#define MEM_CMP(x, y, n)   Humble::safe_memcmp((x),(y),(n))
#define MEM_COPY(d, s, n)   Humble::safe_memcpy((d),(s),(n))
 Portable alias for the "memory copy" RTL function (memcpy).
#define MEM_FILL(d, c, n)   Humble::safe_memset((d),(c),(n))
 Portable alias for the "memory set" RTL function (memset).
#define MEM_MOVE(d, s, n)   Humble::safe_memmove((d),(s),(n))
 Portable alias for the "memory move" RTL function (memmove).
#define MEM_ZERO(d, n)   Humble::safe_memset((d),0x00,(n))
 Portable alias for the "memory zero" RTL function.
#define STR_COUNT(p, c)   Humble::safe_strcount((p),(c))
#define STR_EMPTY(p)   (NULL_PTR(p) || *(p) == '\0')
 Evaluates to true if a pointer is invalid, or references a zero-length string.
#define STR_SAFE(p)   (GOOD_PTR(p) ? (p) : kStrEmpty)
 Returns a string, or an empty string ("") if the string pointer is invalid.
#define STR_VALID(p)   (GOOD_PTR(p) && *(p) != '\0')
 Evaluates to true if a string is valid and non-empty (opposite to STR_EMPTY).
#define STR_CAT(s, d, n)   Humble::safe_strncat((s),(d),(n))
 Substitute for the "string character search" (strncat) RTL function.
#define STR_CHR(s, c)   Humble::safe_strchr((s),(c))
 Substitute for the "string character search" (strchr) RTL function.
#define STR_CMP(a, b)   Humble::safe_strcmp((a),(b))
 Substitue for the "string compare" (strcmp) RTL function.
#define STR_ICMP(a, b)   Humble::safe_strcmpi((a),(b))
 Substitue for the "string case insensitive compare" (stricmp) RTL function.
#define STR_NCMP(a, b, n)   Humble::safe_strcmpn((a),(b),(n))
 Substitue for the "string case fixed length compare" (strncmp) RTL function.
#define STR_WCMP(a, b)   Humble::safe_strcmpw((a),(b))
 string case wildcard compare" function
#define STR_CPY(s, d)   Humble::safe_strncpy((s),(d))
 Substitue for the "string copy" (strnpy) RTL function.
#define STR_NCPY(s, d, n)   Humble::safe_strncpy((s),(d),(n))
#define STR_LEN(s)   Humble::safe_strlen(s)
 Substitue for the "string length" (strlen) RTL function.
#define STR_NLEN(s, u)   Humble::safe_strlen((s),(u))
#define STR_LWR(s)   Humble::safe_strlwr(s)
 Substitue for the "string lower" (strlwr) RTL function.
#define STR_RCHR(s, c)   Humble::safe_strrchr((s),(c))
 Substitute for the "string reverse character search" (strrchr) RTL function.
#define STR_REV(s)   Humble::safe_strrev(s)
 Substitute for the "string reverse" (strrev) RTL function.
#define STR_SPRINTF   Humble::safe_sprintf
 Portable alias for the "string formatting" RTL function (sprintf).
#define STR_STR(s, a)   Humble::safe_strstr((s),(a))
 Substitute for the "string substring search" (strstr) RTL function.
#define STR_TO_INT(s)   Humble::safe_strtoi(s)
 Substitute for the "string to integer" (strtoi) RTL function.
#define STR_UPR(s)   Humble::safe_strupr(s)
 Substitue for the "string upper" (strupr) RTL function.
#define STR_VSPRINTF   Humble::safe_vsprintf
 Portable alias for the vsprintf() RTL function.
#define DECLARE_HUMBLE_APP(x)
 Declares the global main() function.

Typedefs

typedef char Text
 < Portable alias for a single character (char) Portable alias for a character (string) pointer (char *)
typedef TextTextPtr
 Portable alias for a pointer to a constant string (char const *).
typedef Text const * StringPtr
typedef signed char int8
 < Portable alias for a signed 8-bit value Portable alias for an unsigned 8-bit value
typedef unsigned char uint8
typedef short int16
 < Portable alias for a signed 15-bit value Portable alias for an unsigned 15-bit value
typedef unsigned short uint16
typedef long int32
 < Portable alias for a signed 32-bit value Portable alias for an unsigned 32-bit value
typedef unsigned long uint32
typedef void * Ptr
 < Portable alias for a void pointer (void *) Portable alias for a pointer to constant byte data (const unsigned char *)
typedef void const * PtrConst
 Portable alias for a pointer to byte data (unsigned char *).
typedef uint8 * PtrData
 Portable alias for a pointer to byte data (unsigned char *).
typedef uint8 const * PtrDataConst
 Force a string as changeable to avoid compiler warnings.
typedef HStr< 255 > HStrTmp
 Generic string class.

Enumerations

enum  ErrCode {
  ERR_ASSERT = -1, NO_ERROR = 0, ERR_API_ERROR, ERR_BAD_PARAMETER,
  ERR_BAD_WINDOW, ERR_BUFFER_OVERFLOW, ERR_BUFFER_UNDERFLOW, ERR_BUY_MORE_RAM,
  ERR_CRC_FAILURE, ERR_DATA_INVALID, ERR_DIV_ZERO, ERR_DUPLICATE,
  ERR_FILE_INVALID, ERR_FILE_DELETE, ERR_FILE_OPEN, ERR_FILE_READ,
  ERR_FILE_WRITE, ERR_MAX_CAPACITY, ERR_NOT_FOUND, ERR_NOT_IMPLEMENTED,
  ERR_NOT_INITIALIZED, ERR_NULL_PTR, ERR_OUT_OF_RANGE, ERR_STL_EXCEPTION,
  ERR_MYSTERY
}
 An enumerated list of error codes. More...

Functions

int32 Humble::safe_memcmp (PtrConst, PtrConst, uint32)
 Replacement for the "memory comparison" (memcmp) RTL function.
Ptr Humble::safe_memcpy (Ptr, PtrConst, uint32)
 Replacement for the "memory copy" (memcpy) RTL function.
Ptr Humble::safe_memmove (Ptr, PtrConst, uint32)
 Replacement for the "memory move" (memmove) RTL function.
Ptr Humble::safe_memset (Ptr, uint8, uint32)
 Replacement for the "memory set" (memset) RTL function.
StringPtr Humble::safe_strchr (StringPtr, Text)
 Replacement for the "string character" (strchr) RTL function.
int32 Humble::safe_strcmp (StringPtr, StringPtr)
 Replacement for the "string comparison" (strcmp) RTL function.
int32 Humble::safe_strcmpi (StringPtr, StringPtr)
 Replacement for the "string comparison" (stricmp) RTL function.
bool Humble::safe_strcmpw (StringPtr, StringPtr)
 String comparison function with wildcards.
TextPtr Humble::safe_strncat (TextPtr, StringPtr, int32)
 Replacement for the "string concatenate" (strncat) RTL function.
int32 Humble::safe_strcount (StringPtr, Text)
 Counts the number of times a character is found in a string.
int Humble::safe_strlen (StringPtr, int32 nMaxLen=INT32_MAX)
 Replacement for the "string length" (strlen) RTL function.
TextPtr Humble::safe_strlwr (TextPtr)
 Replacement for the "string lower" (strlwr) RTL function.
StringPtr Humble::safe_strrchr (StringPtr, Text)
 Replacement for the "string reverse character" (strrchr) RTL function.
TextPtr Humble::safe_strrev (TextPtr)
 Replacement for the "string reverse" (strrev) RTL function.
StringPtr Humble::safe_strstr (StringPtr, StringPtr)
 Replacement for the "string substring search" (strstr) RTL function.
int32 Humble::safe_strtoi (StringPtr)
 Converts a string to an integer.
TextPtr Humble::safe_strupr (TextPtr)
 Replacement for the "string upper" (strupr) RTL function.
int32 Humble::safe_vsprintf (TextPtr, int32, StringPtr, va_list)
 Replacement for the vsprintf() RTL function.
int32 Humble::safe_sprintf (TextPtr, int32, StringPtr,...)
 Replacement for the sprintf() RTL function.

Variables

const int8 INT8_MAX = SCHAR_MAX
 maximum value for int8
const int8 INT8_MIN = SCHAR_MIN
 minimum value for int8
const uint8 UINT8_MAX = UCHAR_MAX
 maximum value for uint8
const int16 INT16_MAX = SHRT_MAX
 maximum value for int16
const int16 INT16_MIN = SHRT_MIN
 minimum value for int16
const uint16 UINT16_MAX = USHRT_MAX
 maximum value for uint16
const int32 INT32_MAX = LONG_MAX
 maximum value for int32
const int32 INT32_MIN = LONG_MIN
 minimum value for int32
const uint32 UINT32_MAX = ULONG_MAX
 maximum value for uint32


Define Documentation

#define DECLARE_HUMBLE_APP  ) 
 

Value:

x   theApp;                                                             \
    int main(int argc, char * argv[])                                       \
        { return theApp.Main(argc, argv); }
Including this macro will cause the main() function to be declared. This should only be done once for each application, or linker errors will occur. This macro must be declared after the DECLARE_HUMBLE_VARS macro.

Parameters:
x the application class (typically derived from HApp)

Definition at line 32 of file HApp.h.


Typedef Documentation

typedef HStr<255> HStrTmp
 

The HStrTmp class is an instance of the HStr class, predefined to a maximum length of 255 bytes. It is intended for generic usage.

Definition at line 1360 of file HString.h.


Enumeration Type Documentation

enum ErrCode
 

Fatal error codes which (eventually) should be translated into human- readable strings. By convention, debugging errors are negative, while run-time errors are positve.

Enumeration values:
ERR_ASSERT  A debug ASSERT() test failed.
NO_ERROR  Special "no error" value.
ERR_API_ERROR  An API call failed.
ERR_BAD_PARAMETER  A function parameter was invalid.
ERR_BAD_WINDOW  A window object or structure is invalid.
ERR_BUFFER_OVERFLOW  An internal buffer was too small.
ERR_BUFFER_UNDERFLOW  An internal buffer underflow.
ERR_BUY_MORE_RAM  A memory allocation failed.
ERR_CRC_FAILURE  An internal CRC check failed.
ERR_DATA_INVALID  An internal data element was invalid.
ERR_DIV_ZERO  Black holes are where God divided by zero.
ERR_DUPLICATE  A file or data element already exists.
ERR_FILE_DELETE  A file could not be deleted.
ERR_FILE_OPEN  A file could not be opened.
ERR_FILE_READ  A file read error ocurred.
ERR_FILE_WRITE  A file write error ocurred.
ERR_MAX_CAPACITY  An internal structure is "full".
ERR_NOT_FOUND  A file or data element was not found.
ERR_NOT_IMPLEMENTED  A technique or method has not be implemented.
ERR_NOT_INITIALIZED  A data structure or object was not initialized.
ERR_NULL_PTR  An invalid (NULL) pointer was detected.
ERR_OUT_OF_RANGE  An internal value was out of range.
ERR_STL_EXCEPTION  An STL call threw an exception.
ERR_MYSTERY  A 'catch-all everything else' error.

Definition at line 25 of file HError.h.


Function Documentation

int32 Humble::safe_memcmp PtrConst  p1,
PtrConst  p2,
uint32  uBytes
 

This method is identical to memcmp(), but is also guaranteed to correctly handle NULL pointers. This method is wrapped by the MEM_CMP macro.

Returns:
Zero if the two memory blocks are equal,
Parameters:
p1 Left block to compare
p2 Right block to compare
uBytes Count of bytes to compare
See also:
MEM_CMP

Definition at line 223 of file Humble.cpp.

Ptr Humble::safe_memcpy Ptr  pDst,
PtrConst  pSrc,
uint32  uBytes
 

This method is identical to memcpy(), but is also guaranteed to correctly handle NULL parameters. It also checks for overlapping copies and calls memmove() when applicable. This method is wrapped by the MEM_COPY macro.

Returns:
Destination block after copy
Parameters:
pDst Source string
pSrc Destination string
uBytes Maximum length of destination block
See also:
MEM_COPY

Definition at line 246 of file Humble.cpp.

Ptr Humble::safe_memmove Ptr  pDst,
PtrConst  pSrc,
uint32  uBytes
 

This method is identical to memmove(), but is also guaranteed to correctly handle NULL parameters. This method is wrapped by the MEM_MOVE macro.

Returns:
Destination block after copy
Parameters:
pDst Source string
pSrc Destination string
uBytes Maximum length of destination block
See also:
MEM_MOVE

Definition at line 273 of file Humble.cpp.

Ptr Humble::safe_memset Ptr  pDst,
uint8  xVal,
uint32  uBytes
 

This method is identical to memset(), but is also guaranteed to correctly handle invalid parameters. This method is wrapped by the MEM_FILL macro.

Returns:
Destination block after copy
Parameters:
pDst Source string
xVal Value to set
uBytes Maximum length of destination block
See also:
MEM_FILL

Definition at line 294 of file Humble.cpp.

StringPtr Humble::safe_strchr StringPtr  pstr,
Text  ch
 

This method is a wrapper around strchr(), but also correctly handles a NULL string by returning a NULL result. This method is wrapped by the STR_CHR macro.

Returns:
Ptr to first ocurrence of ch, or NULL if not found
Parameters:
pstr Ptr to string to search
ch Character to search for
See also:
STR_CHR

Definition at line 315 of file Humble.cpp.

int32 Humble::safe_strcmp StringPtr  pstr1,
StringPtr  pstr2
 

This method is a wrapper around strcmp(), but also correctly handles NULL parameters. This method is wrapped by the STR_CMP macro.

Returns:
Zero if the two strings are equal,
Parameters:
pstr1 Left string to compare
pstr2 Right string to compare
See also:
STR_CMP

Definition at line 330 of file Humble.cpp.

int32 Humble::safe_strcmpi StringPtr  pstr1,
StringPtr  pstr2
 

This method is a wrapper around stricmp(), but also correctly handles NULL parameters. This method is wrapped by the STR_ICMP macro.

Returns:
Zero if the two strings are equal,
Parameters:
pstr1 Left string to compare
pstr2 Right string to compare
See also:
STR_ICMP

Definition at line 350 of file Humble.cpp.

bool Humble::safe_strcmpw StringPtr  pstr,
StringPtr  pstrMask
 

This method is identical to strncmp(), but also correctly handles NULL parameters. It also recognizes the '?' and '*' wildcard operators. This method is wrapped by the STR_CMPW macro.

Returns:
Zero if the two strings are equal,
Parameters:
pstr Left string to compare
pstrMask Right string to compare
See also:
STR_CMPW

Definition at line 404 of file Humble.cpp.

TextPtr Humble::safe_strncat TextPtr  pszSrc,
StringPtr  pstrDst,
int32  nMaxLen
 

This method is identical to strncat(), but is also guaranteed to correctly handle NULL parameters. This method is wrapped by the STR_CAT macro.

Returns:
Destination string after copy
Parameters:
pszSrc Destination string
pstrDst Source string
nMaxLen Maximum length of destination string
See also:
STR_CAT

Definition at line 483 of file Humble.cpp.

int32 Humble::safe_strcount StringPtr  pstr,
Text  ch
 

Returns:
Number of times the character is found
Parameters:
pstr Ptr to string to search
ch Character to search for

Definition at line 538 of file Humble.cpp.

int Humble::safe_strlen StringPtr  pstr,
int32  nMaxLen
 

This method is identical to strlen(), but is also guaranteed to correctly handle a NULL string by returning a zero result. It also sanity checks the counter to ensure that it doesn't roll over (and go negative). This method is wrapped by the STR_LEN macro.

Returns:
Ptr to first ocurrence of ch in the string
Parameters:
pstr Ptr to string to search
nMaxLen [optional] Limit to the length to search for '\0'
See also:
STR_LEN

Definition at line 563 of file Humble.cpp.

TextPtr Humble::safe_strlwr TextPtr  psz  ) 
 

This method is identical to strlwr(), but is also guaranteed to correctly handle a NULL string by returning a NULL result. This method is wrapped by the STR_LWR macro.

Returns:
Ptr to string
Parameters:
psz Ptr to string to lower
See also:
STR_LWR

Definition at line 585 of file Humble.cpp.

StringPtr Humble::safe_strrchr StringPtr  pstr,
Text  ch
 

This method is identical to strrchr(), but is also guaranteed to correctly handle a NULL string by returning a NULL result. This method is wrapped by the STR_RCHR macro.

Returns:
Ptr to LAST ocurrence of ch, or NULL if not found
Parameters:
pstr Ptr to string to search
ch Character to search for
See also:
STR_RCHR

Definition at line 606 of file Humble.cpp.

TextPtr Humble::safe_strrev TextPtr  psz  ) 
 

This method is identical to strrev(), but is also guaranteed to correctly handle a NULL string by returning a NULL result. This method is wrapped by the STR_REV macro.

Returns:
Ptr to LAST ocurrence of ch, or NULL if not found
Parameters:
psz Ptr to string to reverse
See also:
STR_REV

Definition at line 629 of file Humble.cpp.

StringPtr Humble::safe_strstr StringPtr  pstr,
StringPtr  pstrFind
 

This method is identical to strstr(), but is also guaranteed to correctly handle NULL parameters by returning a NULL result. This method is wrapped by the STR_STR macro.

Returns:
Ptr to first ocurrence of pstrFind
Parameters:
pstr Ptr to string to search in
pstrFind Ptr to string to search for
See also:
STR_STR

Definition at line 666 of file Humble.cpp.

int32 Humble::safe_strtoi StringPtr  pstr  ) 
 

Returns:
Integer value of string
Parameters:
pstr String to convert

Definition at line 690 of file Humble.cpp.

TextPtr Humble::safe_strupr TextPtr  psz  ) 
 

This method is identical to strupr(), but is also guaranteed to correctly handle a NULL string by returning a NULL result. This method is wrapped by the STR_UPR macro.

Returns:
Ptr to string
Parameters:
psz Ptr to string to "upper"
See also:
STR_UPR

Definition at line 731 of file Humble.cpp.

int32 Humble::safe_vsprintf TextPtr  pstr,
int32  nMaxLen,
StringPtr  pstrFormat,
va_list  vaList
 

This method is identical to vsprintf(), but is also guaranteed to correctly handle NULL parameters by returning a NULL result. This method is wrapped by the STR_VSPRINTF macro.

Returns:
Length of formatted string
Parameters:
[out] pstr Ptr to string to format
nMaxLen Maximum length of formatted string
pstrFormat Ptr to formatting string
vaList va_list to be passed to vsprintf()
See also:
STR_VSPRINTF

Definition at line 754 of file Humble.cpp.

int32 Humble::safe_sprintf TextPtr  pstr,
int32  nMaxLen,
StringPtr  pstrFormat,
  ...
 

This method is identical to sprintf(), but is also guaranteed to correctly handle NULL parameters by returning a NULL result. This method is wrapped by the STR_SPRINTF macro.

Returns:
Length of formatted string
Parameters:
[out] pstr Ptr to string to format
nMaxLen Maximum length of formatted string
pstrFormat Ptr to string to format
See also:
STR_SPRINTF

Definition at line 793 of file Humble.cpp.


 

2006.01.09-16:37