Devel Lib
Devel::CCharArray< Size > Class Template Reference

A class for representing and manipulating a character array. More...

#include <CharArray.h>

Public Member Functions

 CCharArray ()
 Default constructor.
 
 CCharArray (const char *i_szString)
 Explicit constructor. More...
 
 CCharArray (const std::string &i_sString)
 Explicit constructor. More...
 
 CCharArray (std::initializer_list< char > i_oList)
 Initializer list constructor. More...
 
 CCharArray (const CCharArray< Size > &i_szString)
 Copy constructor. More...
 
template<size_t TOtherSize>
 CCharArray (const CCharArray< TOtherSize > &i_szString)
 Copy constructor. More...
 
 ~CCharArray ()=default
 Default destructor.
 
void set (const std::string &i_sString)
 Set char array data from string. More...
 
void set (const char *i_szString, size_t i_nSize)
 Set char array data from char pointer. More...
 
void set (const char *i_szString)
 Set char array data from char pointer. More...
 
void set (const CCharArray< Size > &i_szString)
 Set char array data from other CCharArray. More...
 
template<size_t SizeOther>
void set (const CCharArray< SizeOther > &i_szString)
 Set char array data from other CCharArray. More...
 
char * begin ()
 
const char * begin () const
 
char * end ()
 
const char * end () const
 
const char * c_str () const
 
size_t length () const
 
char & first ()
 
const char & first () const
 
char & last ()
 
const char & last () const
 
char & at (const size_t i_nIndex)
 
const char & at (const size_t i_nIndex) const
 
std::string toStdString () const
 
CCharArray< Size > & operator= (const CCharArray< Size > &i_szString)
 Assigns the contents of another CCharArray to this object. More...
 
template<size_t TOtherSize>
CCharArray< Size > & operator= (const CCharArray< TOtherSize > &i_szString)
 Assigns the contents of another CCharArray to this object. More...
 
CCharArray< Size > & operator= (const std::string &i_sString)
 Assigns the contents of a standard string to this object. More...
 
CCharArray< Size > & operator= (const char *i_szString)
 Assigns the contents of a char array to this object. More...
 
bool operator== (const CCharArray< Size > &i_szString) const
 Compare CCharArray object with another for equality. More...
 
template<size_t SizeOther>
bool operator== (const CCharArray< SizeOther > &i_szString) const
 Compare CCharArray object with another for equality. More...
 
bool operator== (const char *i_szString) const
 Compare CCharArray object with a char array for equality. More...
 
bool operator== (const std::string &i_sString) const
 Compare CCharArray object with a standard string for equality. More...
 
bool operator!= (const CCharArray< Size > &i_szString) const
 Compare CCharArray object with another for inequality. More...
 
template<size_t SizeOther>
bool operator!= (const CCharArray< SizeOther > &i_szString) const
 Compare CCharArray object with another for inequality. More...
 
bool operator!= (const char *i_szString) const
 Compare CCharArray object with a char array for inequality. More...
 
bool operator!= (const std::string &i_sString) const
 Compare CCharArray object with a standard string for inequality. More...
 
 operator char * ()
 Implicit conversion to a char array.
 
 operator const char * () const
 Implicit conversion to a const char array.
 

Static Public Member Functions

static constexpr size_t maxLength ()
 

Detailed Description

template<size_t Size>
class Devel::CCharArray< Size >

A class for representing and manipulating a character array.

This class encapsulates character arrays by providing constructors, assignment operators, and string manipulation functionalities.

Example

This class must be used with the template type being the size of the array you are working with.

Devel::CCharArray<50> arr; // Creating an instance of CCharArray with a size of 50
// Setting data from a C-style string
arr.set("Hello, world!");
// Setting data from a std::string
std::string str = "Hello, world!";
arr.set(str);
// Setting data from another CCharArray
// Getting the C-style string representation of the array
const char* cStr = arr.c_str();
// Getting the std::string representation of the array
std::string stdStr = arr.toStdString();
// Comparing CCharArray with another CCharArray, a C-style string, and a std::string
bool isEqual = (arr == arr2) && (arr == cStr) && (arr == stdStr);
A class for representing and manipulating a character array.
Definition: CharArray.h:41
void set(const std::string &i_sString)
Set char array data from string.
Definition: CharArray.h:90
std::string toStdString() const
Definition: CharArray.h:190
const char * c_str() const
Definition: CharArray.h:142

Constructor & Destructor Documentation

◆ CCharArray() [1/5]

template<size_t Size>
Devel::CCharArray< Size >::CCharArray ( const char *  i_szString)
inlineexplicit

Explicit constructor.

Parameters
i_szStringThe char pointer to copy

◆ CCharArray() [2/5]

template<size_t Size>
Devel::CCharArray< Size >::CCharArray ( const std::string &  i_sString)
inlineexplicit

Explicit constructor.

Parameters
i_sStringThe string to copy

◆ CCharArray() [3/5]

template<size_t Size>
Devel::CCharArray< Size >::CCharArray ( std::initializer_list< char >  i_oList)
inline

Initializer list constructor.

Parameters
i_oListinitializer list

◆ CCharArray() [4/5]

template<size_t Size>
Devel::CCharArray< Size >::CCharArray ( const CCharArray< Size > &  i_szString)
inline

Copy constructor.

Parameters
i_szStringThe char array to copy

◆ CCharArray() [5/5]

template<size_t Size>
template<size_t TOtherSize>
Devel::CCharArray< Size >::CCharArray ( const CCharArray< TOtherSize > &  i_szString)
inlineexplicit

Copy constructor.

Parameters
i_szStringThe char array to copy

Member Function Documentation

◆ at() [1/2]

template<size_t Size>
char& Devel::CCharArray< Size >::at ( const size_t  i_nIndex)
inline
Returns
The character at the given index of the char array

◆ at() [2/2]

template<size_t Size>
const char& Devel::CCharArray< Size >::at ( const size_t  i_nIndex) const
inline
Returns
The character at the given index of the const char array

◆ begin() [1/2]

template<size_t Size>
char* Devel::CCharArray< Size >::begin ( )
inline
Returns
A pointer to the beginning of the char array

◆ begin() [2/2]

template<size_t Size>
const char* Devel::CCharArray< Size >::begin ( ) const
inline
Returns
A pointer to the beginning of the const char array

◆ c_str()

template<size_t Size>
const char* Devel::CCharArray< Size >::c_str ( ) const
inline
Returns
A const char pointer representing the char array

◆ end() [1/2]

template<size_t Size>
char* Devel::CCharArray< Size >::end ( )
inline
Returns
A pointer to the end of the char array

◆ end() [2/2]

template<size_t Size>
const char* Devel::CCharArray< Size >::end ( ) const
inline
Returns
A pointer to the end of the const char array

◆ first() [1/2]

template<size_t Size>
char& Devel::CCharArray< Size >::first ( )
inline
Returns
The first character of the char array

◆ first() [2/2]

template<size_t Size>
const char& Devel::CCharArray< Size >::first ( ) const
inline
Returns
The first character of the const char array

◆ last() [1/2]

template<size_t Size>
char& Devel::CCharArray< Size >::last ( )
inline
Returns
The last character of the char array

◆ last() [2/2]

template<size_t Size>
const char& Devel::CCharArray< Size >::last ( ) const
inline
Returns
The last character of the const char array

◆ length()

template<size_t Size>
size_t Devel::CCharArray< Size >::length ( ) const
inline
Returns
The length of the char array

◆ maxLength()

template<size_t Size>
static constexpr size_t Devel::CCharArray< Size >::maxLength ( )
inlinestaticconstexpr
Returns
The maximum length of the char array

◆ operator!=() [1/4]

template<size_t Size>
bool Devel::CCharArray< Size >::operator!= ( const CCharArray< Size > &  i_szString) const
inline

Compare CCharArray object with another for inequality.

Parameters
i_szStringThe CCharArray to compare
Returns
True if not equal, False otherwise

◆ operator!=() [2/4]

template<size_t Size>
template<size_t SizeOther>
bool Devel::CCharArray< Size >::operator!= ( const CCharArray< SizeOther > &  i_szString) const
inline

Compare CCharArray object with another for inequality.

Parameters
i_szStringThe CCharArray to compare
Returns
True if not equal, False otherwise

◆ operator!=() [3/4]

template<size_t Size>
bool Devel::CCharArray< Size >::operator!= ( const char *  i_szString) const
inline

Compare CCharArray object with a char array for inequality.

Parameters
i_szStringThe char array to compare
Returns
True if not equal, False otherwise

◆ operator!=() [4/4]

template<size_t Size>
bool Devel::CCharArray< Size >::operator!= ( const std::string &  i_sString) const
inline

Compare CCharArray object with a standard string for inequality.

Parameters
i_sStringThe string to compare
Returns
True if not equal, False otherwise

◆ operator=() [1/4]

template<size_t Size>
CCharArray<Size>& Devel::CCharArray< Size >::operator= ( const CCharArray< Size > &  i_szString)
inline

Assigns the contents of another CCharArray to this object.

Parameters
i_szStringThe CCharArray to copy
Returns
This CCharArray object

◆ operator=() [2/4]

template<size_t Size>
template<size_t TOtherSize>
CCharArray<Size>& Devel::CCharArray< Size >::operator= ( const CCharArray< TOtherSize > &  i_szString)
inline

Assigns the contents of another CCharArray to this object.

Parameters
i_szStringThe CCharArray to copy
Returns
This CCharArray object

◆ operator=() [3/4]

template<size_t Size>
CCharArray<Size>& Devel::CCharArray< Size >::operator= ( const char *  i_szString)
inline

Assigns the contents of a char array to this object.

Parameters
i_szStringThe char array to copy
Returns
This CCharArray object

◆ operator=() [4/4]

template<size_t Size>
CCharArray<Size>& Devel::CCharArray< Size >::operator= ( const std::string &  i_sString)
inline

Assigns the contents of a standard string to this object.

Parameters
i_sStringThe string to copy
Returns
This CCharArray object

◆ operator==() [1/4]

template<size_t Size>
bool Devel::CCharArray< Size >::operator== ( const CCharArray< Size > &  i_szString) const
inline

Compare CCharArray object with another for equality.

Parameters
i_szStringThe CCharArray to compare
Returns
True if equal, False otherwise

◆ operator==() [2/4]

template<size_t Size>
template<size_t SizeOther>
bool Devel::CCharArray< Size >::operator== ( const CCharArray< SizeOther > &  i_szString) const
inline

Compare CCharArray object with another for equality.

Parameters
i_szStringThe CCharArray to compare
Returns
True if equal, False otherwise

◆ operator==() [3/4]

template<size_t Size>
bool Devel::CCharArray< Size >::operator== ( const char *  i_szString) const
inline

Compare CCharArray object with a char array for equality.

Parameters
i_szStringThe char array to compare
Returns
True if equal, False otherwise

◆ operator==() [4/4]

template<size_t Size>
bool Devel::CCharArray< Size >::operator== ( const std::string &  i_sString) const
inline

Compare CCharArray object with a standard string for equality.

Parameters
i_sStringThe string to compare
Returns
True if equal, False otherwise

◆ set() [1/5]

template<size_t Size>
void Devel::CCharArray< Size >::set ( const CCharArray< Size > &  i_szString)
inline

Set char array data from other CCharArray.

Parameters
i_szStringThe CCharArray to set

◆ set() [2/5]

template<size_t Size>
template<size_t SizeOther>
void Devel::CCharArray< Size >::set ( const CCharArray< SizeOther > &  i_szString)
inline

Set char array data from other CCharArray.

Parameters
i_szStringThe CCharArray to set

◆ set() [3/5]

template<size_t Size>
void Devel::CCharArray< Size >::set ( const char *  i_szString)
inline

Set char array data from char pointer.

Parameters
i_szStringThe string to set

◆ set() [4/5]

template<size_t Size>
void Devel::CCharArray< Size >::set ( const char *  i_szString,
size_t  i_nSize 
)
inline

Set char array data from char pointer.

Parameters
i_szStringThe string to set
i_nSizeThe size of the string

◆ set() [5/5]

template<size_t Size>
void Devel::CCharArray< Size >::set ( const std::string &  i_sString)
inline

Set char array data from string.

Parameters
i_sStringThe string to set

◆ toStdString()

template<size_t Size>
std::string Devel::CCharArray< Size >::toStdString ( ) const
inline
Returns
The CCharArray as a standard string

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