IFS::NameBuffer Struct Reference

defines a 'safe' name buffer More...

#include <NameBuffer.h>

Inheritance diagram for IFS::NameBuffer:
Collaboration diagram for IFS::NameBuffer:

Public Member Functions

 NameBuffer ()
 
 NameBuffer (char *buffer, uint16_t size, uint16_t length=0)
 
 NameBuffer (String &s)
 Make a NameBuffer point to contents of a String. More...
 
 operator const char * () const
 
char * begin ()
 
const char * c_str () const
 
 operator String () const
 
bool operator== (const char *other)
 
int copy (const char *src, uint16_t srclen)
 copies text from a source buffer into a name buffer More...
 
int copy (const char *src)
 
int copy (const NameBuffer &name)
 
int addSep ()
 When building file paths this method simplified appending separators. More...
 
char * endptr ()
 get a pointer to the next write position More...
 
uint16_t space ()
 get the number of free characters available More...
 
void terminate ()
 ensure the buffer has a nul terminator, even if it means overwriting content More...
 
bool overflow () const
 determine if name buffer overflowed More...
 
bool endsWith (const char *suffix) const
 

Public Attributes

char * buffer {nullptr}
 Buffer to store name. More...
 
uint16_t size {0}
 IN: Size of buffer. More...
 
uint16_t length {0}
 OUT: length of name. More...
 

Detailed Description

defines a 'safe' name buffer

Note
Instead of including a fixed name array in Stat (and IFileSystem::Info) structures, we use a NameBuffer to identify a separate buffer. This has several advantages:
- Maximum size is not fixed
- Finding and copying the name is optional
- Actual name length is returned in the 'length' field, regardless of size
- A NameBuffer structure (or one containing it) only requires initialising once before
a loop operation as buffer/size are preserved.
There are fancier ways to do this but a structure is transparent and requires no heap allocation.
length always reflects the required name/path length, and may be longer than size.

Constructor & Destructor Documentation

◆ NameBuffer() [1/3]

IFS::NameBuffer::NameBuffer ( )
inline

◆ NameBuffer() [2/3]

IFS::NameBuffer::NameBuffer ( char *  buffer,
uint16_t  size,
uint16_t  length = 0 
)
inline

◆ NameBuffer() [3/3]

IFS::NameBuffer::NameBuffer ( String s)
inline

Make a NameBuffer point to contents of a String.

Member Function Documentation

◆ addSep()

int IFS::NameBuffer::addSep ( )
inline

When building file paths this method simplified appending separators.

Return values
interror code
Note
if the path is not empty, a separator character is appended

◆ begin()

char* IFS::NameBuffer::begin ( )
inline

◆ c_str()

const char* IFS::NameBuffer::c_str ( ) const
inline

◆ copy() [1/3]

int IFS::NameBuffer::copy ( const char *  src)
inline

◆ copy() [2/3]

int IFS::NameBuffer::copy ( const char *  src,
uint16_t  srclen 
)
inline

copies text from a source buffer into a name buffer

Parameters
srcsource name
srclennumber of characters in name
Note
length field is always set to srclen, regardless of number of characters copied.

◆ copy() [3/3]

int IFS::NameBuffer::copy ( const NameBuffer name)
inline

◆ endptr()

char* IFS::NameBuffer::endptr ( )
inline

get a pointer to the next write position

Return values
char*
Note
use space() to ensure buffer doesn't overrun When writing text be sure to call terminate() when complete

◆ endsWith()

bool IFS::NameBuffer::endsWith ( const char *  suffix) const
inline

◆ operator const char *()

IFS::NameBuffer::operator const char * ( ) const
inline

◆ operator String()

IFS::NameBuffer::operator String ( ) const
inlineexplicit

◆ operator==()

bool IFS::NameBuffer::operator== ( const char *  other)
inline

◆ overflow()

bool IFS::NameBuffer::overflow ( ) const
inline

determine if name buffer overflowed

Note
Compares returned length with buffer size; A nul terminator is always appended, so size should be >= (length + 1)

◆ space()

uint16_t IFS::NameBuffer::space ( )
inline

get the number of free characters available

Return values
uint16_t
Note
returns 0 if buffer has overrun

◆ terminate()

void IFS::NameBuffer::terminate ( )
inline

ensure the buffer has a nul terminator, even if it means overwriting content

Member Data Documentation

◆ buffer

char* IFS::NameBuffer::buffer {nullptr}

Buffer to store name.

◆ length

uint16_t IFS::NameBuffer::length {0}

OUT: length of name.

◆ size

uint16_t IFS::NameBuffer::size {0}

IN: Size of buffer.


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