Evo C++ Library v0.5.1
Public Types | Public Member Functions | Public Attributes | Static Public Attributes | List of all members
StringInt< T, PADDING > Struct Template Reference

#include <evo/string.h>

Inheritance diagram for StringInt< T, PADDING >:
Inheritance graph
[legend]

Detailed Description

template<class T, int PADDING = 1>
struct evo::StringInt< T, PADDING >

String fixed-size buffer for formatting an integer.

Template Parameters
TInteger type
PADDINGAdditional padding for buffer, defaults to 1 for terminator
Example

This example uses printf() as a function that requires a terminated string.

#include <evo/string.h>
#include <stdio.h>
using namespace evo;
int main() {
StringInt<int> str1(12345);
printf("%s\n", str1.data());
printf("%s\n", str2.set(6677));
return 0;
}

Output:

12345
6677

Public Types

typedef ListBase< char, StrSizeTListBaseType
 List base type (this) More...
 
typedef StrSizeT Size
 Size type. More...
 
typedef StringInt< T, PADDING > ThisType
 This type. More...
 

Public Member Functions

 StringInt ()
 Constructor intializes to null. More...
 
 StringInt (T num, int base=fDEC, bool terminated=true, uint end_padding=0)
 Constructor intializes with set(). More...
 
ThisTypeadd (const char *data, Size size)
 Append additional data to buffer. More...
 
char * addnew (Size size)
 Add additional space to buffer and return pointer to new uninitialized space in buffer. More...
 
char * data ()
 Get formatted string pointer. More...
 
ThisTypeset ()
 Set as null. More...
 
char * set (T num, int base=fDEC, bool terminated=true, uint end_padding=0)
 Set as formatted integer. More...
 
Size size () const
 Get formatting string size. More...
 

Public Attributes

char buffer [BUF_SIZE]
 String buffer More...
 
char * data_
 Data pointer, NULL if null. More...
 
StrSizeT size_
 Data size as item count, 0 if empty or null. More...
 

Static Public Attributes

static const int BUF_SIZE = IntegerT<T>::MAXSTRLEN + PADDING
 Buffer size. More...
 

Member Typedef Documentation

◆ ListBaseType

typedef ListBase<char ,StrSizeT > ListBaseType
inherited

List base type (this)

◆ Size

typedef StrSizeT Size

Size type.

◆ ThisType

typedef StringInt<T,PADDING> ThisType

This type.

Constructor & Destructor Documentation

◆ StringInt() [1/2]

StringInt ( )
inline

Constructor intializes to null.

◆ StringInt() [2/2]

StringInt ( num,
int  base = fDEC,
bool  terminated = true,
uint  end_padding = 0 
)
inline

Constructor intializes with set().

  • Formatting is done in reverse (least digit first) so additional padding after terminator is normally before the returned pointer
Parameters
numNumber to set/format
baseNumber base to format with (2 - 36)
terminatedWhether to add terminator after number
end_paddingPadding to leave at end (PADDING template param must make room for this)

Member Function Documentation

◆ add()

ThisType& add ( const char *  data,
Size  size 
)
inline

Append additional data to buffer.

Parameters
dataData pointer to copy from
sizeSize to copy and add
Returns
This

◆ addnew()

char* addnew ( Size  size)
inline

Add additional space to buffer and return pointer to new uninitialized space in buffer.

  • This increases the data size used and returns a pointer to the newly added data to write to, which should be considered uninitialized
  • Results are undefined if null – call StringInt(T,int,bool,uint) or set(T,int,bool,uint) first
  • This assumes there's enough buffer padding via PADDING template param, and via end_padding argument when set
Parameters
sizeSize to add
Returns
Pointer to newly added data (uninitialized)

◆ data()

char* data ( )
inline

Get formatted string pointer.

Returns
String pointer, NULL if null

◆ set() [1/2]

ThisType& set ( )
inline

Set as null.

Returns
This

◆ set() [2/2]

char* set ( num,
int  base = fDEC,
bool  terminated = true,
uint  end_padding = 0 
)
inline

Set as formatted integer.

  • Note that formatting is done in reverse (least digit first) so any extra space is at the beginning of the buffer
Parameters
numNumber to set/format
baseNumber base to format with (2 - 36)
terminatedWhether to add terminator after number
end_paddingPadding in buffer to leave after string value (PADDING template param must make room for this)
Returns
Pointer to formatted string in buffer

◆ size()

Size size ( ) const
inline

Get formatting string size.

  • Padding is not included in size
Returns
string size in bytes, 0 if null

Member Data Documentation

◆ BUF_SIZE

const int BUF_SIZE = IntegerT<T>::MAXSTRLEN + PADDING
static

Buffer size.

◆ buffer

char buffer[BUF_SIZE]

String buffer

◆ data_

char * data_
inherited

Data pointer, NULL if null.

◆ size_

StrSizeT size_
inherited

Data size as item count, 0 if empty or null.


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