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.
- Note
length
always reflects the required name/path length, and may be longer than size.
Constructor & Destructor Documentation
◆ NameBuffer() [1/3]
|
inline |
◆ NameBuffer() [2/3]
◆ NameBuffer() [3/3]
|
inline |
Make a NameBuffer point to contents of a String.
Member Function Documentation
◆ addSep()
|
inline |
When building file paths this method simplified appending separators.
- Return values
-
int error code
- Note
- if the path is not empty, a separator character is appended
◆ begin()
|
inline |
◆ c_str()
|
inline |
◆ copy() [1/3]
copies text from a source buffer into a name buffer
- Parameters
-
src source name srclen number of characters in name
- Note
- length field is always set to srclen, regardless of number of characters copied.
◆ copy() [2/3]
|
inline |
◆ copy() [3/3]
|
inline |
◆ 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()
|
inline |
◆ operator const char *()
|
inline |
◆ operator String()
|
inlineexplicit |
◆ operator==()
|
inline |
◆ overflow()
|
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()
|
inline |
get the number of free characters available
- Return values
-
uint16_t
- Note
- returns 0 if buffer has overrun
◆ 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: