OpenTTD Source: SmallMatrix< T > Class Template Reference

OpenTTD Source 12.2

Public Member Functions | Protected Attributes
SmallMatrix< T > Class Template Reference

Simple matrix template class. More...

`#include <smallmatrix_type.hpp>`

## Public Member Functions
| SmallMatrix (const SmallMatrix &other)
| Copy constructor. More...
SmallMatrix & | operator= (const SmallMatrix &other)
| Assignment. More...
void | Assign (const SmallMatrix &other)
| Assign items from other vector.
void | Clear ()
| Remove all rows from the matrix.
void | Reset ()
| Remove all items from the list and free allocated memory.
void | Compact ()
| Compact the matrix down to the smallest possible size.
void | EraseColumn (uint x)
| Erase a column, replacing it with the last one. More...
void | EraseColumnPreservingOrder (uint x, uint count=1)
| Remove columns from the matrix while preserving the order of other columns. More...
void | EraseRow (uint y)
| Erase a row, replacing it with the last one. More...
void | EraseRowPreservingOrder (uint y, uint count=1)
| Remove columns from the matrix while preserving the order of other columns. More...
void | AppendRow (uint to_add=1)
| Append rows. More...
void | AppendColumn (uint to_add=1)
| Append rows. More...
void | Resize (uint new_width, uint new_height)
| Set the size to a specific width and height, preserving item positions as far as possible in the process. More...
uint | Height () const
uint | Width () const
const T & | Get (uint x, uint y) const
| Get item x/y (const). More...
T & | Get (uint x, uint y)
| Get item x/y. More...
const T * | operator[] (uint x) const
| Get column "number" (const) More...
T * | operator[] (uint x)
| Get column "number" (const) More...

## Protected Attributes
T * | data
| The pointer to the first item.
uint | width
| Number of items over first axis.
uint | height
| Number of items over second axis.
uint | capacity
| The available space for storing items.

## Detailed Description

### template<typename T>
class SmallMatrix< T >

Simple matrix template class.

Allocating a matrix in one piece reduces overhead in allocations compared with allocating a vector of vectors and saves some pointer dereferencing. However, you can only get rectangular matrixes like this and if you're changing their height very often performance will probably be worse than with a vector of vectors, due to more frequent copying of memory blocks.

No iterators are provided as iterating the columns would require persistent column objects. Those do not exist. Providing iterators with transient column objects would tie each iterator to a column object, thus replacing previously retrieved columns when iterating and defeating the point of iteration.

It's expected that the items don't need to be constructed or deleted by the container. Only memory allocation and deallocation is performed. This is the same for all openttd "SmallContainer" classes.

Template Parameters

  T | The type of the items stored

Definition at line 38 of file smallmatrix_type.hpp.

## Constructor & Destructor Documentation

## ◆ SmallMatrix()

template<typename T >

SmallMatrix< T >::SmallMatrix | ( | const SmallMatrix< T > & | other | ) |
| inline

Copy constructor.

Parameters

  other | The other matrix to copy.

Definition at line 53 of file smallmatrix_type.hpp.

## Member Function Documentation

## ◆ AppendColumn()

template<typename T >

void SmallMatrix< T >::AppendColumn | ( | uint | to_add = `1` | ) |
| inline

Append rows.

Parameters

  to_add | Number of rows to append.

Definition at line 203 of file smallmatrix_type.hpp.

## ◆ AppendRow()

template<typename T >

void SmallMatrix< T >::AppendRow | ( | uint | to_add = `1` | ) |
| inline

Append rows.

Parameters

  to_add | Number of rows to append.

Definition at line 194 of file smallmatrix_type.hpp.

## ◆ EraseColumn()

template<typename T >

void SmallMatrix< T >::EraseColumn | ( | uint | x | ) |
| inline

Erase a column, replacing it with the last one.

Parameters

  x | Position of the column.

Definition at line 131 of file smallmatrix_type.hpp.

## ◆ EraseColumnPreservingOrder()

template<typename T >

void SmallMatrix< T >::EraseColumnPreservingOrder | ( | uint | x,
|  | uint | count = `1`
| ) |  |
| inline

Remove columns from the matrix while preserving the order of other columns.

Parameters

  x | First column to remove.
  count | Number of consecutive columns to remove.

Definition at line 145 of file smallmatrix_type.hpp.

## ◆ EraseRow()

template<typename T >

void SmallMatrix< T >::EraseRow | ( | uint | y | ) |
| inline

Erase a row, replacing it with the last one.

Parameters

  y | Position of the row.

Definition at line 162 of file smallmatrix_type.hpp.

## ◆ EraseRowPreservingOrder()

template<typename T >

void SmallMatrix< T >::EraseRowPreservingOrder | ( | uint | y,
|  | uint | count = `1`
| ) |  |
| inline

Remove columns from the matrix while preserving the order of other columns.

Parameters

  y | First column to remove.
  count | Number of consecutive columns to remove.

Definition at line 178 of file smallmatrix_type.hpp.

## ◆ Get() [1/2]

template<typename T >

T& SmallMatrix< T >::Get | ( | uint | x,
|  | uint | y
| ) |  |
| inline

Get item x/y.

Parameters

  x | X-position of the item.
  y | Y-position of the item.

Returns
  Item at specified position.

Definition at line 289 of file smallmatrix_type.hpp.

## ◆ Get() [2/2]

template<typename T >

const T& SmallMatrix< T >::Get | ( | uint | x,
|  | uint | y
| ) |  | const
| inline

Get item x/y (const).

Parameters

  x | X-position of the item.
  y | Y-position of the item.

Returns
  Item at specified position.

Definition at line 276 of file smallmatrix_type.hpp.

## ◆ operator=()

template<typename T >

SmallMatrix& SmallMatrix< T >::operator= | ( | const SmallMatrix< T > & | other | ) |
| inline

Assignment.

Parameters

  other | The other matrix to assign.

Definition at line 67 of file smallmatrix_type.hpp.

## ◆ operator[]() [1/2]

template<typename T >

T* SmallMatrix< T >::operator[] | ( | uint | x | ) |
| inline

Get column "number" (const)

Parameters

  x | Position of the column.

Returns
  Column at "number".

Definition at line 313 of file smallmatrix_type.hpp.

## ◆ operator[]() [2/2]

template<typename T >

const T* SmallMatrix< T >::operator[] | ( | uint | x | ) | const
| inline

Get column "number" (const)

Parameters

  x | Position of the column.

Returns
  Column at "number".

Definition at line 301 of file smallmatrix_type.hpp.

## ◆ Resize()

template<typename T >

void SmallMatrix< T >::Resize | ( | uint | new_width,
|  | uint | new_height
| ) |  |
| inline

Set the size to a specific width and height, preserving item positions as far as possible in the process.

Parameters

  new_width | Target width.
  new_height | Target height.

Definition at line 214 of file smallmatrix_type.hpp.

Referenced by LinkGraph::AddNode(), SmallMatrix< BaseEdge >::AppendColumn(), SmallMatrix< BaseEdge >::AppendRow(), LinkGraphJob::Init(), and LinkGraph::Init().

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

- src/core/smallmatrix_type.hpp