VAE - Virtual Audio Engine 1
Small Data Driven Audio Engine
tklb::StackString< N > Class Template Reference

Super simple class to hold and compare strings on the stack. More...

#include <TString.hpp>

Inheritance diagram for tklb::StackString< N >:
Collaboration diagram for tklb::StackString< N >:

Public Member Functions

 StackString ()
 
 StackString (const char *str)
 
StackStringoperator= (const char *str)
 
const char * c_str () const
 
const char & operator[] (const Size index) const
 
char & operator[] (const Size index)
 
template<int N2>
bool operator== (const StackString< N2 > &b) const
 
bool operator== (const char *str) const
 
bool empty () const
 
Size size () const
 
void set (const char *str)
 

Private Types

using Size = unsigned int
 

Private Attributes

char mData [N]
 

Detailed Description

template<unsigned int N = 8>
class tklb::StackString< N >

Super simple class to hold and compare strings on the stack.

Template Parameters
NSize of the string

Definition at line 13 of file TString.hpp.

Member Typedef Documentation

◆ Size

template<unsigned int N = 8>
using tklb::StackString< N >::Size = unsigned int
private

Definition at line 15 of file TString.hpp.

Constructor & Destructor Documentation

◆ StackString() [1/2]

template<unsigned int N = 8>
tklb::StackString< N >::StackString ( )
inline

Definition at line 17 of file TString.hpp.

17{ for (Size i = 0; i < N; i++) { mData[i] = '\0'; } }
unsigned int Size
Definition: TString.hpp:15

◆ StackString() [2/2]

template<unsigned int N = 8>
tklb::StackString< N >::StackString ( const char *  str)
inline

Definition at line 18 of file TString.hpp.

18{ set(str); }
void set(const char *str)
Definition: TString.hpp:59
Here is the call graph for this function:

Member Function Documentation

◆ c_str()

template<unsigned int N = 8>
const char * tklb::StackString< N >::c_str ( ) const
inline

Definition at line 20 of file TString.hpp.

20{ return mData; }

◆ empty()

template<unsigned int N = 8>
bool tklb::StackString< N >::empty ( ) const
inline

Definition at line 44 of file TString.hpp.

44 {
45 if (N == 0) { return true; }
46 return mData[0] == '\0';
47 }

◆ operator=()

template<unsigned int N = 8>
StackString & tklb::StackString< N >::operator= ( const char *  str)
inline

Definition at line 19 of file TString.hpp.

19{ set(str); return *this; }
Here is the call graph for this function:

◆ operator==() [1/2]

template<unsigned int N = 8>
bool tklb::StackString< N >::operator== ( const char *  str) const
inline

Definition at line 33 of file TString.hpp.

33 {
34 if (N == 0) { return false; }
35 for(Size i = 0; i < N; i++) {
36 if (str[i] == '\0') {
37 return str[i] == mData[i];
38 }
39 if (str[i] != mData[i]) { return false; }
40 }
41 return true;
42 }

◆ operator==() [2/2]

template<unsigned int N = 8>
template<int N2>
bool tklb::StackString< N >::operator== ( const StackString< N2 > &  b) const
inline

Definition at line 25 of file TString.hpp.

25 {
26 if (N == 0) { return false; }
27 for(Size i = 0; i < (N < N2 ? N : N2); i++) {
28 if (mData[i] != b[i]) { return false; }
29 }
30 return true;
31 }

◆ operator[]() [1/2]

template<unsigned int N = 8>
char & tklb::StackString< N >::operator[] ( const Size  index)
inline

Definition at line 22 of file TString.hpp.

22{ return mData[index]; }

◆ operator[]() [2/2]

template<unsigned int N = 8>
const char & tklb::StackString< N >::operator[] ( const Size  index) const
inline

Definition at line 21 of file TString.hpp.

21{ return mData[index]; }

◆ set()

template<unsigned int N = 8>
void tklb::StackString< N >::set ( const char *  str)
inline

Definition at line 59 of file TString.hpp.

59 {
60 if (N == 0) { return; }
61 Size i = 0;
62 for(i = 0; i < N; i++) {
63 if (str[i] == '\0') { break; }
64 mData[i] = str[i];
65 }
66 for(; i < N; i++) { mData[i] = '\0'; }
67 mData[N - 1] = '\0'; // just in case, will run over the last char
68 }
Here is the caller graph for this function:

◆ size()

template<unsigned int N = 8>
Size tklb::StackString< N >::size ( ) const
inline

Definition at line 49 of file TString.hpp.

49 {
50 if (N == 0) { return 0; }
51 for (Size i = 0; i < N; i++) {
52 if (mData[i] == '\0') {
53 return i;
54 }
55 }
56 return N; // someone wrote past the end
57 }

Member Data Documentation

◆ mData

template<unsigned int N = 8>
char tklb::StackString< N >::mData[N]
private

Definition at line 14 of file TString.hpp.


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