ALBA
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
albaString Class Reference

#include <albaString.h>

Inheritance diagram for albaString:
Inheritance graph
[legend]
Collaboration diagram for albaString:
Collaboration graph
[legend]

Public Member Functions

const albaID Length () const
 
void Copy (const char *src)
 
void NCopy (const char *src, int n)
 
void Erase (int start, int end=-1)
 
char * Duplicate () const
 
int Compare (const char *str) const
 
bool Equals (const char *str) const
 
bool StartsWith (const char *str) const
 
bool EndsWith (const char *str) const
 
albaStringAppend (const char *str)
 
int FindChr (const int c) const
 
void Replace (char from, char to)
 
int FindLastChr (const int c) const
 
int FindFirst (const char *str) const
 
int FindLast (const char *str) const
 
const char * BaseName () const
 
void ExtractPathName ()
 
void SetPathName (const char *str)
 
void SetPathName (albaString *str)
 
char * ParsePathName ()
 
char * ParsePathName (albaString *str)
 
void ForceDuplicate ()
 
const char * GetCStr () const
 
char * GetNonConstCStr ()
 
int GetSize () const
 
int SetMaxLength (albaID len)
 
bool IsEmpty () const
 
albaStringSet (const char *a, bool release=false)
 
void SetCStr (char *a, bool release=false)
 
void Printf (const char *format,...)
 
void NPrintf (unsigned long size, const char *format,...)
 
 operator const char * () const
 
char & operator[] (const int i)
 
const char operator[] (const int i) const
 
const bool operator== (const char *src) const
 
const bool operator!= (const char *src) const
 
const bool operator< (const char *a) const
 
const bool operator> (const char *a) const
 
const bool operator<= (const char *a) const
 
const bool operator>= (const char *a) const
 
albaStringoperator<< (const char *a)
 
void operator<< (std::ostream &os)
 
void operator>> (std::istream &os)
 
albaStringoperator<< (int d)
 
albaStringoperator<< (long d)
 
albaStringoperator<< (float d)
 
albaStringoperator<< (double d)
 
albaStringoperator<< (albaMatrix d)
 
albaStringoperator<< (albaString *s)
 
albaStringoperator+= (const char *s)
 
 albaString (const albaString &src)
 
 albaString (const char *src)
 
 albaString (const double &num)
 
albaStringoperator= (const albaString &mat)
 
albaStringoperator= (const char *src)
 
albaStringoperator= (const double &num)
 
 albaString ()
 
 ~albaString ()
 

Static Public Member Functions

static albaID Length (const char *str)
 
static void Copy (char *dest, const char *src)
 
static char * Duplicate (const char *str)
 
static void Duplicate (char *&store, const char *src, bool release=true)
 
static int Compare (const char *str1, const char *str2)
 
static bool Equals (const char *str1, const char *str2)
 
static bool StartsWith (const char *str1, const char *str2)
 
static bool EndsWith (const char *str1, const char *str2)
 
static char * Append (const char *str1, const char *str2)
 
static const char * BaseName (const char *filename)
 
static char * ParsePathName (char *str)
 
static bool IsEmpty (const char *str)
 
static wxString Format (const char *format,...)
 

Protected Member Functions

int SetSize (albaID size)
 
void Initialize ()
 

Protected Attributes

char * m_CStr
 
const char * m_ConstCStr
 
albaID m_Size
 

Detailed Description

albaString - performs common string operations on c-strings.

albaString is an implementation of string which operates on a traditional c-string internally stored. At each moment this string can be retrieved with GetCStr(). The memory of this m_CStr is automatically garbaged. Originally based on vtkString. BEWARE, when albaString is assigned with Set() to a "const char *" this is simply referenced and not copied, this implies very high performance but can cause invalid memory access: e.g. in case the "const char *" is a function argument. When a albaString storing a reference to a const char * is modified the string is automatically copied into a new memory. This string can be passed as argument wherever a const char * is expected.

See also
albaCString

Definition at line 42 of file albaString.h.

Constructor & Destructor Documentation

◆ albaString() [1/4]

albaString::albaString ( const albaString src)

◆ albaString() [2/4]

albaString::albaString ( const char *  src)

◆ albaString() [3/4]

albaString::albaString ( const double &  num)

◆ albaString() [4/4]

albaString::albaString ( )

◆ ~albaString()

albaString::~albaString ( )

Member Function Documentation

◆ Length() [1/2]

static albaID albaString::Length ( const char *  str)
static

This static method returns the size of c-string.

If the string is empty, it returns 0. It can handle null pointers.

◆ Length() [2/2]

const albaID albaString::Length ( ) const

This method returns the size of this string.

◆ Copy() [1/2]

static void albaString::Copy ( char *  dest,
const char *  src 
)
static

static method to copy c-string to the another c-string.

◆ Copy() [2/2]

void albaString::Copy ( const char *  src)

Copy a c-string to this string.

◆ NCopy()

void albaString::NCopy ( const char *  src,
int  n 
)

Copy N characters of another string to this string.

◆ Erase()

void albaString::Erase ( int  start,
int  end = -1 
)

Erase characters from start position to end position.

If end is not specified erase to the end of the string.

◆ Duplicate() [1/3]

static char * albaString::Duplicate ( const char *  str)
static

This method makes a duplicate of a c-string similar to C function strdup but it uses new to create new string, so you can use delete to remove it.

It returns 0 if the input is empty. This function automatically release old pointed data (if not specified differently)

◆ Duplicate() [2/3]

static void albaString::Duplicate ( char *&  store,
const char *  src,
bool  release = true 
)
static

This method makes a duplicate of the string similar to C function strdup but it uses new to create new string, so you can use delete to remove it.

It returns 0 if the input is empty. The new string pointer is copied in the destination pointer. If this was already != NULL, the corresponding memory is released. This is useful to automatically manage garbage collection but beware to not provide an uninitialized pointer variable. Beware memory releasing must be performed by consumer

◆ Duplicate() [3/3]

char * albaString::Duplicate ( ) const

Duplicate the string stored inside this object.

Beware memory releasing must be performed by consumer

◆ Compare() [1/2]

static int albaString::Compare ( const char *  str1,
const char *  str2 
)
static

This static method compare two strings.

It is similar to strcmp, but it can handle null pointers. return 0 if str1 == str2, -1 if str1<str2, 1 if str1>str2

◆ Compare() [2/2]

int albaString::Compare ( const char *  str) const

This method compare the given c-string with the one stored inside this object.

It is similar to strcmp, but it can handle null pointers. Return 0 if str equal this, -1 if str > this, 1 if str < this

◆ Equals() [1/2]

static bool albaString::Equals ( const char *  str1,
const char *  str2 
)
inlinestatic

This static method compare two strings.

It is similar to strcmp, but it can handle null pointers. Also it only returns C style true or false versus compare which returns also which one is greater.

Definition at line 106 of file albaString.h.

◆ Equals() [2/2]

bool albaString::Equals ( const char *  str) const

This method compare the given c-string with the one stored inside this object.

It is similar to strcmp, but it can handle null pointers. Also it only returns C style true or false versus compare which returns also which one is greater.

◆ StartsWith() [1/2]

static bool albaString::StartsWith ( const char *  str1,
const char *  str2 
)
static

Static method to check if the first string starts with the second one.

◆ StartsWith() [2/2]

bool albaString::StartsWith ( const char *  str) const

Check if this string starts with the given one.

◆ EndsWith() [1/2]

static bool albaString::EndsWith ( const char *  str1,
const char *  str2 
)
static

Static method to check if the first string ends with the second one.

◆ EndsWith() [2/2]

bool albaString::EndsWith ( const char *  str) const

Check if this string ends with the given one.

◆ Append() [1/2]

static char * albaString::Append ( const char *  str1,
const char *  str2 
)
static

Append two strings and produce a new one.

The consumer must delete the resulting string. The method returns 0 if inputs are empty or if there was an error.

◆ Append() [2/2]

albaString & albaString::Append ( const char *  str)

Append a new string to this string.

◆ FindChr()

int albaString::FindChr ( const int  c) const

Scan the string for the first occurrence of the character.

◆ Replace()

void albaString::Replace ( char  from,
char  to 
)

Replace each caracter from with to.

◆ FindLastChr()

int albaString::FindLastChr ( const int  c) const

Scan the string for the first occurrence of the character.

◆ FindFirst()

int albaString::FindFirst ( const char *  str) const

Find first occurrence of a substring.

◆ FindLast()

int albaString::FindLast ( const char *  str) const

Find last occurrence of a substring.

◆ BaseName() [1/2]

static const char * albaString::BaseName ( const char *  filename)
static

Extract the base name of a filename string.

◆ BaseName() [2/2]

const char * albaString::BaseName ( ) const

◆ ExtractPathName()

void albaString::ExtractPathName ( )

Extract the pathname from a filename string.

Result is written inplace.

◆ SetPathName() [1/2]

void albaString::SetPathName ( const char *  str)

parse the given string to substitute each (back)slash character with the right pathname separator.

◆ SetPathName() [2/2]

void albaString::SetPathName ( albaString str)

◆ ParsePathName() [1/3]

char * albaString::ParsePathName ( )

parse the given string to substitute each (back)slash character with the right pathname separator.

◆ ParsePathName() [2/3]

static char * albaString::ParsePathName ( char *  str)
static

◆ ParsePathName() [3/3]

char * albaString::ParsePathName ( albaString str)

◆ ForceDuplicate()

void albaString::ForceDuplicate ( )

Force the string to create an internal duplication in place of reference to const char.

◆ GetCStr()

const char * albaString::GetCStr ( ) const

Return the pointer to the internal c-string.

◆ GetNonConstCStr()

char * albaString::GetNonConstCStr ( )

Return the pointer to the internal c-string, but first force string the internal copy.

See also
ForceDulicate ()

◆ GetSize()

int albaString::GetSize ( ) const
inline

return the real memory size allocated for the internal c-string

Definition at line 180 of file albaString.h.

◆ SetMaxLength()

int albaString::SetMaxLength ( albaID  len)

Pre-Allocate space for the internal c-string.

The memory size is is given in terms of string length, that is one more character for the trailing '\0' is allocated. Previous data is retained. Memory is reallocated only if requested size is > of existing one. All the albaString methods resize this memory when necessary, but to improve performance it's possible to preallocate an enough large memory to store the data preventing reallocation of memory. Return 0 if OK, -1 in case of relocation problems

◆ IsEmpty() [1/2]

static bool albaString::IsEmpty ( const char *  str)
inlinestatic

return true if empty

Definition at line 194 of file albaString.h.

◆ IsEmpty() [2/2]

bool albaString::IsEmpty ( ) const
inline

return true if empty

Definition at line 196 of file albaString.h.

References IsEmpty().

Referenced by IsEmpty().

Here is the call graph for this function:

◆ Set()

albaString & albaString::Set ( const char *  a,
bool  release = false 
)

Set the internal pointer to a give pointer.

Second parameter allow to force the release of the memory

Referenced by albaCString::albaCString().

◆ SetCStr()

void albaString::SetCStr ( char *  a,
bool  release = false 
)

this can be used only with non constant c-string

◆ Printf()

void albaString::Printf ( const char *  format,
  ... 
)

Format given arguments according to format string.

Format string format is that of vsprintf function

◆ Format()

static wxString albaString::Format ( const char *  format,
  ... 
)
static

◆ NPrintf()

void albaString::NPrintf ( unsigned long  size,
const char *  format,
  ... 
)

like Printf but faster (you can specify output string size)

◆ operator const char *()

albaString::operator const char * ( ) const
inline

this allows to convert a albaString to const char *.

Definition at line 216 of file albaString.h.

◆ operator[]() [1/2]

char & albaString::operator[] ( const int  i)

Direct access to single string elements for writing.

This operator forces memory copy in case of internal const char reference.

◆ operator[]() [2/2]

const char albaString::operator[] ( const int  i) const

direct access to string single elements for reading

◆ operator==()

const bool albaString::operator== ( const char *  src) const

◆ operator!=()

const bool albaString::operator!= ( const char *  src) const

◆ operator<()

const bool albaString::operator< ( const char *  a) const

◆ operator>()

const bool albaString::operator> ( const char *  a) const

◆ operator<=()

const bool albaString::operator<= ( const char *  a) const

◆ operator>=()

const bool albaString::operator>= ( const char *  a) const

◆ operator<<() [1/8]

albaString & albaString::operator<< ( const char *  a)
inline

Definition at line 236 of file albaString.h.

◆ operator<<() [2/8]

void albaString::operator<< ( std::ostream &  os)

◆ operator>>()

void albaString::operator>> ( std::istream &  os)

◆ operator<<() [3/8]

albaString & albaString::operator<< ( int  d)

◆ operator<<() [4/8]

albaString & albaString::operator<< ( long  d)

◆ operator<<() [5/8]

albaString & albaString::operator<< ( float  d)

◆ operator<<() [6/8]

albaString & albaString::operator<< ( double  d)

◆ operator<<() [7/8]

albaString & albaString::operator<< ( albaMatrix  d)

Put inside string a albaMatrix in row order example: 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 -> "1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1".

◆ operator<<() [8/8]

albaString & albaString::operator<< ( albaString s)

◆ operator+=()

albaString & albaString::operator+= ( const char *  s)

◆ operator=() [1/3]

albaString & albaString::operator= ( const albaString mat)

◆ operator=() [2/3]

albaString & albaString::operator= ( const char *  src)

◆ operator=() [3/3]

albaString & albaString::operator= ( const double &  num)

◆ SetSize()

int albaString::SetSize ( albaID  size)
protected

Allocate space for the internal c-string.

◆ Initialize()

void albaString::Initialize ( )
inlineprotected

Definition at line 279 of file albaString.h.

Member Data Documentation

◆ m_CStr

char* albaString::m_CStr
protected

Definition at line 281 of file albaString.h.

◆ m_ConstCStr

const char* albaString::m_ConstCStr
protected

Definition at line 282 of file albaString.h.

◆ m_Size

albaID albaString::m_Size
protected

Definition at line 283 of file albaString.h.


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