CBlobT< Titem_, Tbase_ > Class Template Reference

Blob - simple dynamic Titem_ array. More...

#include <blob.hpp>

Data Structures

struct  OnTransfer

Public Types

typedef Titem_ Titem
typedef Tbase_ Tbase
typedef Tbase::bsize_t bsize_t

Public Member Functions

FORCEINLINE CBlobT ()
 Default constructor - makes new Blob ready to accept any data.
FORCEINLINE CBlobT (const Titem_ *p, bsize_t num_items)
 Constructor - makes new Blob with data.
FORCEINLINE CBlobT (const Tbase &src)
 Copy constructor - make new blob to become copy of the original (source) blob.
FORCEINLINE CBlobT (const OnTransfer &ot)
 Take ownership constructor.
FORCEINLINE ~CBlobT ()
 Destructor - ensures that allocated memory (if any) is freed.
FORCEINLINE void CheckIdx (bsize_t idx) const
 Check the validity of item index (only in debug mode).
FORCEINLINE Titem * Data ()
 Return pointer to the first data item - non-const version.
FORCEINLINE const Titem * Data () const
 Return pointer to the first data item - const version.
FORCEINLINE Titem * Data (bsize_t idx)
 Return pointer to the idx-th data item - non-const version.
FORCEINLINE const Titem * Data (bsize_t idx) const
 Return pointer to the idx-th data item - const version.
FORCEINLINE bsize_t Size () const
 Return number of items in the Blob.
FORCEINLINE bsize_t MaxSize () const
 Return total number of items that can fit in the Blob without buffer reallocation.
FORCEINLINE bsize_t GetReserve () const
 Return number of additional items that can fit in the Blob without buffer reallocation.
FORCEINLINE void Free ()
 Free the memory occupied by Blob destroying all items.
FORCEINLINE Titem * GrowSizeNC (bsize_t num_items)
 Grow number of data items in Blob by given number - doesn't construct items.
FORCEINLINE Titem * GrowSizeC (bsize_t num_items)
 Grow number of data items in Blob by given number - constructs new items (using Titem_'s default constructor).
FORCEINLINE void ReduceSize (bsize_t num_items)
 Destroy given number of items and reduce the Blob's data size.
FORCEINLINE Titem * AppendNew ()
 Append one data item at the end (calls Titem_'s default constructor).
FORCEINLINE Titem * Append (const Titem &src)
 Append the copy of given item at the end of Blob (using copy constructor).
FORCEINLINE Titem * Append (const Titem *pSrc, bsize_t num_items)
 Add given items (ptr + number of items) at the end of blob.
FORCEINLINE void RemoveBySwap (bsize_t idx)
 Remove item with the given index by replacing it by the last item and reducing the size by one.
FORCEINLINE void RemoveBySwap (Titem *pItem)
 Remove item given by pointer replacing it by the last item and reducing the size by one.
FORCEINLINE Titem * MakeFreeSpace (bsize_t num_items)
 Ensures that given number of items can be added to the end of Blob.
FORCEINLINE OnTransfer Transfer ()

Static Public Attributes

static const bsize_t Titem_size = sizeof(Titem)

Detailed Description

template<class Titem_, class Tbase_ = CBlobBaseSimple>
class CBlobT< Titem_, Tbase_ >

Blob - simple dynamic Titem_ array.

Titem_ (template argument) is a placeholder for any type. Titem_ can be any integral type, pointer, or structure. Using Blob instead of just plain C array simplifies the resource management in several ways: 1. When adding new item(s) it automatically grows capacity if needed. 2. When variable of type Blob comes out of scope it automatically frees the data buffer. 3. Takes care about the actual data size (number of used items). 4. Dynamically constructs only used items (as opposite of static array which constructs all items)

Definition at line 341 of file blob.hpp.


Member Function Documentation

template<class Titem_, class Tbase_ = CBlobBaseSimple>
FORCEINLINE Titem* CBlobT< Titem_, Tbase_ >::MakeFreeSpace ( bsize_t  num_items  )  [inline]

Ensures that given number of items can be added to the end of Blob.

Returns pointer to the first free (unused) item

Definition at line 527 of file blob.hpp.


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

Generated on Wed Feb 17 23:07:24 2010 for OpenTTD by  doxygen 1.6.1