Utilities
This section lists utility classes and functions, which help to implement Circle applications.
CString
#include <circle/string.h>
-
class CString
This class encapsulates a character string and allows different manipulations on it. The methods of this class are not reentrant.
-
CString::CString(const char *pString)
Creates a string object. Sets the string initially to
pString.
-
CString::CString(const CString &rString)
Copy constructor. Creates a new string object. Sets the string initially to the value of
rString.rStringremains unchanged.
-
CString::CString(CString &&rrString)
Move constructor. Creates a new string object. Sets the string initially to the value of
rrString.rrStringis set to an empty string.
-
CString::operator const char*(void) const
Returns a pointer to the string buffer, which is terminated with a zero-character.
-
const char *CString::operator=(const char *pString)
Assigns a new string. Returns a pointer to the string buffer, which is terminated with a zero-character.
-
CString &CString::operator=(const CString &rString)
Assigns a new string. Returns a reference to the string object.
-
CString &CString::operator=(CString &&rrString)
Move assignment. Assigns a new string.
rrStringis set to an empty string. Returns a reference to the string object.
-
size_t CString::GetLength(void) const
Returns the length of the string in number of characters (zero for empty string).
-
int CString::Compare(const char *pString) const
Compares
pStringwith the string. Returns:zero, if the strings are identical
a negative value, if the string is smaller than
pStringa positive value, if the string is greater than
pString
-
int CString::Find(char chChar) const
Searches for
chCharin the string. Returns the zero-based index of the character or -1, if it is not found.
-
int CString::Replace(const char *pOld, const char *pNew)
Replaces all occurrences of
pOldwithpNewin the string. Returns the number of occurrences.
-
void CString::Format(const char *pFormat, ...)
Formats a string as known from
sprintf(). Does support only a subset of the known format specifiers:%[#][[-][0]len][.prec][l|ll]{c|d|f|i|o|p|s|u|x|X}Field
Description
#
insert prefix 0, 0x or 0X for %o, %x or %X
-
left justify output
0
insert leading zeros
len
decimal number specifying the length of the field
.prec
decimal number specifying the precision for %f
l
type is
longll
type is
long long(with STDLIB_SUPPORT >= 1 only)c
insert
chard
insert decimal
int,longorlong long(maybe with sign)f
insert
doublei
same as %d
o
insert octal
unsigned,unsigned longorunsigned long longp
same as %x
s
insert string (type is
const char *)u
insert decimal
unsigned,unsigned longorunsigned long longx
insert hex
unsigned,unsigned longorunsigned long long(lower case)X
insert hex
unsigned,unsigned longorunsigned long long(upper case)
CPtrArray
#include <circle/ptrarray.h>
-
class CPtrArray
This class implements a dynamic array of pointers. The methods of this class are not reentrant.
-
CPtrArray::CPtrArray(unsigned nInitialSize = 100, unsigned nSizeIncrement = 100)
Creates a
CPtrArrayobject with initially space fornInitialSizeelements. The memory allocation will be increased bynSizeIncrementelements, when the array is full.
-
void *CPtrArray::operator[](unsigned nIndex) const
Returns the pointer for the array element at
nIndex(based on zero).nIndexmust be smaller than the value returned fromGetCount().
CPtrList
#include <circle/ptrlist.h>
-
class CPtrList
This class implements a linked list of pointers. The methods of this class are not reentrant.
-
type TPtrListElement
Opaque type definition.
-
TPtrListElement *CPtrList::GetNext(TPtrListElement *pElement)
Returns the next element following
pElement, or 0 if nothing follows.
-
void CPtrList::InsertBefore(TPtrListElement *pAfter, void *pPtr)
Inserts
pPtrbefore the elementpAfter, which must not be 0.
CNumberPool
#include <circle/numberpool.h>
-
class CNumberPool
This class implements an allocation pool for numbers. The methods of this class are not reentrant.
-
static const unsigned Limit = 63
Allowed maximum of an allocated number.
-
CNumberPool::CNumberPool(unsigned nMin, unsigned nMax = Limit)
Creates a number pool.
nMinis the minimal returned number byAllocateNumber().nMaxis the maximal returned number.
-
unsigned CNumberPool::AllocateNumber(boolean bMustSucceed, const char *pFrom = "numpool")
Allocates a number from the number pool and returns it. If there are no more numbers available, this method returns
CNumberPool::Invalid, ifbMustSucceedisFALSE, or the system halts with a panic message otherwise. This message has the prefixpFrom.
-
void CNumberPool::FreeNumber(unsigned nNumber)
Returns
nNumber, which has been allocated earlier, to the number pool for reuse.
Atomic memory access
#include <circle/atomic.h>
This header file defines some functions, which implement an atomic access to an aligned int variable in memory. These functions can be useful for synchronization purposes, especially for multi-core applications, where using a spin lock would be too time consuming. All accesses to such a variable must use one of the following functions, to ensure them being atomic.
-
int AtomicGet(volatile const int *pVar)
Returns the value of the
intvariable atpVar.
-
int AtomicSet(volatile int *pVar, int nValue)
Sets the
intvariable atpVartonValueand returnsnValue.
-
int AtomicExchange(volatile int *pVar, int nValue)
Sets the
intvariable atpVartonValueand returns the previous value.
-
int AtomicCompareExchange(volatile int *pVar, int nCompare, int nValue)
Sets the
intvariable atpVartonValue, if the previous value of the variable wasnCompare, and returns the previous value of the variable.
-
int AtomicAdd(volatile int *pVar, int nValue)
Adds
nValueto theintvariable atpVar. Returns the result of the operation.
-
int AtomicSub(volatile int *pVar, int nValue)
Subtracts
nValuefrom theintvariable atpVar. Returns the result of the operation.
-
int AtomicIncrement(volatile int *pVar)
Increments the
intvariable atpVarby 1. Returns the result of the operation.
-
int AtomicDecrement(volatile int *pVar)
Decrements the
intvariable atpVarby 1. Returns the result of the operation.
C standard library functions
#include <circle/util.h>
This header file defines some functions, known from the C standard library.
Memory functions
-
void *memset(void *pBuffer, int nValue, size_t nLength)
-
void *memcpy(void *pDest, const void *pSrc, size_t nLength)
-
void *memmove(void *pDest, const void *pSrc, size_t nLength)
-
int memcmp(const void *pBuffer1, const void *pBuffer2, size_t nLength)
String functions
-
size_t strlen(const char *pString)
-
int strcmp(const char *pString1, const char *pString2)
-
int strcasecmp(const char *pString1, const char *pString2)
-
int strncmp(const char *pString1, const char *pString2, size_t nMaxLen)
-
int strncasecmp(const char *pString1, const char *pString2, size_t nMaxLen)
-
char *strcpy(char *pDest, const char *pSrc)
-
char *strncpy(char *pDest, const char *pSrc, size_t nMaxLen)
-
char *strcat(char *pDest, const char *pSrc)
-
char *strchr(const char *pString, int chChar)
-
char *strstr(const char *pString, const char *pNeedle)
-
char *strtok_r(char *pString, const char *pDelim, char **ppSavePtr)
Number conversion
-
unsigned long strtoul(const char *pString, char **ppEndPtr, int nBase)
-
unsigned long long strtoull(const char *pString, char **ppEndPtr, int nBase)
-
int atoi(const char *pString)
Other functions
#include <circle/util.h>
-
u16 bswap16(u16 usValue)
-
u32 bswap32(u32 ulValue)
Swaps the byte order of a 16- or 32-bit value.
-
int parity32(unsigned nValue)
Returns the number of 1-bits in
nValuemodulo 1.
Macros
#include <circle/macros.h>
-
PACKED
Packs a
structdefinition. The members will be stored tightly, not aligned as usual.
-
ALIGN(n)
Aligns a variable or member to a boundary of
nin memory.
-
NORETURN
Append this to the prototype of a function, which never returns.
-
BIT(n)
Returns the bit mask
(1U << (n)).
-
likely(exp)
-
unlikely(exp)
In time critical code this gives the compiler a hint, which result of the boolean expression
expis normally expected. This can result in faster code.