OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- Data Structures
- Class Hierarchy
- Data Fields

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.
SmallMatrix & | operator= (const SmallMatrix &other)
| Assignment.
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.
void | EraseColumnPreservingOrder (uint x, uint count=1)
| Remove columns from the matrix while preserving the order of other columns.
void | EraseRow (uint y)
| Erase a row, replacing it with the last one.
void | EraseRowPreservingOrder (uint y, uint count=1)
| Remove columns from the matrix while preserving the order of other columns.
void | AppendRow (uint to_add=1)
| Append rows.
void | AppendColumn (uint to_add=1)
| Append rows.
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.
uint | Height () const
uint | Width () const
const T & | Get (uint x, uint y) const
| Get item x/y (const).
T & | Get (uint x, uint y)
| Get item x/y.
const T * | operator[] (uint x) const
| Get column "number" (const)
T * | operator[] (uint x)
| Get column "number" (const)

## 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 40 of file smallmatrix_type.hpp.

## Constructor & Destructor Documentation

template<typename T>

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

Copy constructor.

Parameters

  other | The other matrix to copy.

Definition at line 55 of file smallmatrix_type.hpp.

## Member Function Documentation

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 205 of file smallmatrix_type.hpp.

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 196 of file smallmatrix_type.hpp.

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 133 of file smallmatrix_type.hpp.

Referenced by LinkGraph::RemoveNode().

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 147 of file smallmatrix_type.hpp.

template<typename T>

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

Erase a row, replacing it with the last one.

Parameters

  x | Position of the row.

Definition at line 164 of file smallmatrix_type.hpp.

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

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

Definition at line 180 of file smallmatrix_type.hpp.

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 278 of file smallmatrix_type.hpp.

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 291 of file smallmatrix_type.hpp.

template<typename T>

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

Assignment.

Parameters

  other | The other matrix to assign.

Definition at line 69 of file smallmatrix_type.hpp.

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 303 of file smallmatrix_type.hpp.

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 315 of file smallmatrix_type.hpp.

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

  width | Target width.
  height | Target height.

Definition at line 216 of file smallmatrix_type.hpp.

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

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

- src/core/smallmatrix_type.hpp