OpenTTD Source: CStrA Struct Reference

OpenTTD Source 1.11.0-RC1

Public Types | Public Member Functions | Data Fields
CStrA Struct Reference

Blob based case sensitive ANSI/UTF-8 string. More...

`#include <str.hpp>`

Inheritance diagram for CStrA:

## Public Types
typedef CBlobT< char > | base
| base class
Public Types inherited from CBlobT< char >
typedef ByteBlob | base

## Public Member Functions
| CStrA ()
| Create an empty CStrT.
| CStrA (const CStrA &src)
| Copy constructor.
| CStrA (const OnTransfer &ot)
| Take over ownership constructor.
char * | GrowSizeNC (uint count)
| Grow the actual buffer and fix the trailing zero at the end.
void | AppendStr (const char *str)
| Append zero-ended C string.
void | Append (const CStrA &src)
| Append another CStrA.
CStrA & | operator= (const char *src)
| Assignment from C string.
CStrA & | operator= (const CStrA &src)
| Assignment from another CStrA.
bool | operator< (const CStrA &other) const
| Lower-than operator (to support stl collections)
int | AddFormatL (const char *format, va_list args) WARN_FORMAT(2
| Add formatted string (like vsprintf) at the end of existing contents.
| for (;;)
| if (ret > 0)
int CDECL | WARN_FORMAT (2, 3) AddFormat(const char *format
| Add formatted string (like sprintf) at the end of existing contents.
int CDECL | va_start (args, format)
| va_end (args)
int CDECL | WARN_FORMAT (2, 3) Format(const char *format
| Assign formatted string (like sprintf).
| va_start (args, format)
| va_end (args)
Public Member Functions inherited from CBlobT< char >
| CBlobT ()
| Default constructor - makes new Blob ready to accept any data.
| CBlobT (const OnTransfer &ot)
| Take ownership constructor.
| ~CBlobT ()
| Destructor - ensures that allocated memory (if any) is freed.
void | CheckIdx (size_t index) const
| Check the validity of item index (only in debug mode)
char * | Data ()
| Return pointer to the first data item - non-const version.
const char * | Data () const
| Return pointer to the first data item - const version.
char * | Data (size_t index)
| Return pointer to the index-th data item - non-const version.
const char * | Data (size_t index) const
| Return pointer to the index-th data item - const version.
size_t | Size () const
| Return number of items in the Blob.
size_t | MaxSize () const
| Return total number of items that can fit in the Blob without buffer reallocation.
size_t | GetReserve () const
| Return number of additional items that can fit in the Blob without buffer reallocation.
char * | GrowSizeNC (size_t num_items)
| Grow number of data items in Blob by given number - doesn't construct items.
char * | MakeFreeSpace (size_t num_items)
| Ensures that given number of items can be added to the end of Blob. More...
OnTransfer | Transfer ()
Public Member Functions inherited from ByteBlob
| ByteBlob ()
| default constructor - initializes empty blob
| ByteBlob (const ByteBlob &src)
| copy constructor
| ByteBlob (BlobHeader *const &src)
| move constructor - take ownership of blob data
| ~ByteBlob ()
| destructor
bool | IsEmpty () const
| return true if blob doesn't contain valid data
size_t | Length () const
| return the number of valid data bytes in the blob
size_t | Capacity () const
| return the current blob capacity in bytes
byte * | Begin ()
| return pointer to the first byte of data - non-const version
const byte * | Begin () const
| return pointer to the first byte of data - const version
void | Clear ()
| invalidate blob's data - doesn't free buffer
void | Free ()
| free the blob's memory
void | AppendRaw (const void *p, size_t num_bytes)
| append new bytes at the end of existing data bytes - reallocates if necessary
void | AppendRaw (const ByteBlob &src)
| append bytes from given source blob to the end of existing data bytes - reallocates if necessary
byte * | Prepare (size_t num_bytes)
| Reallocate if there is no free space for num_bytes bytes. More...
byte * | Append (size_t num_bytes)
| Increase Length() by num_bytes. More...
void | SmartAlloc (size_t new_size)
| reallocate blob data if needed
void | FixTail () const
| fixing the four bytes at the end of blob data - useful when blob is used to hold string

## Data Fields
int | addSize = addSize / 2
int | ret = AddFormatL(format, args)
int | err = 0
| else
return | ret
int CDECL va_list | args

## Additional Inherited Members
Static Public Attributes inherited from CBlobT< char >
static const size_t | type_size
Static Public Attributes inherited from ByteBlob
static const size_t | tail_reserve = 4
| four extra bytes will be always allocated and zeroed at the end
static const size_t | header_size = sizeof(BlobHeader)
Protected Member Functions inherited from ByteBlob
void | InitEmpty ()
| initialize the empty blob
void | Init (BlobHeader *src)
| initialize blob by attaching it to the given header followed by data
BlobHeader & | Hdr ()
| blob header accessor - use it rather than using the pointer arithmetic directly - non-const version
const BlobHeader & | Hdr () const
| blob header accessor - use it rather than using the pointer arithmetic directly - const version
size_t & | LengthRef ()
| return reference to the actual blob size - used when the size needs to be modified
Static Protected Member Functions inherited from ByteBlob
static BlobHeader * | RawAlloc (size_t num_bytes)
| all allocation should happen here
static BlobHeader * | Zero ()
| Return header pointer to the static BlobHeader with both items and capacity containing zero.
static size_t | AllocPolicy (size_t min_alloc)
| simple allocation policy - can be optimized later
static void | RawFree (BlobHeader *p)
| all deallocations should happen here
Protected Attributes inherited from ByteBlob
union {
byte * data
| ptr to the first byte of data
BlobHeader * header
| ptr just after the BlobHeader holding items and capacity
}; |
| type used as class member

## Detailed Description

Blob based case sensitive ANSI/UTF-8 string.

Definition at line 20 of file str.hpp.

## Field Documentation

## ◆ args

int CDECL va_list CStrA::args

Initial value:
{
base::Free()

Definition at line 139 of file str.hpp.

## ◆ else

CStrA::else

Initial value:
{
base::FixTail()

Definition at line 121 of file str.hpp.

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

- src/misc/str.hpp

ByteBlob::Free
void Free()
free the blob's memory
Definition: blob.hpp:211
ByteBlob::FixTail
void FixTail() const
fixing the four bytes at the end of blob data - useful when blob is used to hold string
Definition: blob.hpp:285