Defines | Functions

# newgrf_class_func.h File Reference

Implementation of the NewGRF class' functions. More...

`#include "newgrf_class.h"`
`#include "table/strings.h"`

Go to the source code of this file.

## Defines
#define | DEFINE_NEWGRF_CLASS_METHOD(type)
| Helper for defining the class method's signatures.
#define | INSTANTIATE_NEWGRF_CLASS_METHODS(name, Tspec, Tid, Tmax)
| Force instantiation of the methods so we don't get linker errors.
## Functions
| DEFINE_NEWGRF_CLASS_METHOD (void)
| Reset the classes, i.e.
| DEFINE_NEWGRF_CLASS_METHOD (Tid)
| Allocate a class with a given global class ID.
| DEFINE_NEWGRF_CLASS_METHOD (StringID)
| Get the name of a particular class.
| DEFINE_NEWGRF_CLASS_METHOD (uint)
| Get the number of allocated classes.
| DEFINE_NEWGRF_CLASS_METHOD (const Tspec *)
| Get a spec from a particular class at a given index.

## Detailed Description

Implementation of the NewGRF class' functions.

Definition in file newgrf_class_func.h.

## Define Documentation

#define DEFINE_NEWGRF_CLASS_METHOD | ( |  | type | ) |

Value:

    template <typename Tspec, typename Tid, Tid Tmax> \
      type NewGRFClass<Tspec, Tid, Tmax>

Helper for defining the class method's signatures.

Parameters:

  | type | The type of the class.

Definition at line 20 of file newgrf_class_func.h.

#define INSTANTIATE_NEWGRF_CLASS_METHODS | ( |  | name,
|  |  | Tspec,
|  |  | Tid,
|  |  | Tmax |
| ) |  |  |

Value:

    template void name::Reset(); \
      template Tid name::Allocate(uint32 global_id); \
      template void name::SetName(Tid cls_id, StringID name); \
      template void name::Assign(Tspec *spec); \
      template StringID name::GetName(Tid cls_id); \
      template uint name::GetCount(); \
      template uint name::GetCount(Tid cls_id); \
      template const Tspec *name::Get(Tid cls_id, uint index); \
      template const Tspec *name::GetByGrf(uint32 grfid, byte localidx, int *index);

Force instantiation of the methods so we don't get linker errors.

Definition at line 174 of file newgrf_class_func.h.

## Function Documentation

DEFINE_NEWGRF_CLASS_METHOD | ( | void |  | ) |

Reset the classes, i.e.

Assign a spec to one of the classes.

Set the name of a particular class.

clear everything.

Parameters:

  | cls_id | The id for the class.

Precondition:
  index < GetCount(cls_id)

Parameters:

  | name | The new name for the class.
  | spec | The spec to assign.

Note:
  The spec must have a valid class id set.

Definition at line 84 of file newgrf_class_func.h.

References NewGRFClass< Tspec, Tid, Tmax >::count, ReallocT(), and NewGRFClass< Tspec, Tid, Tmax >::spec.

DEFINE_NEWGRF_CLASS_METHOD | ( | const Tspec * |  | ) |

Get a spec from a particular class at a given index.

Retrieve a spec by GRF location.

Parameters:

  | cls_id | The class to get the spec from.
  | index | The index where to find the spec.

Precondition:
  index < GetCount(cls_id)

Returns:
  The spec at given location.

Parameters:

  | grfid | GRF ID of spec.
  | local_id | Index within GRF file of spec.
  | index | Pointer to return the index of the spec in its class. If NULL then not used.

Returns:
  The spec.

Definition at line 153 of file newgrf_class_func.h.

DEFINE_NEWGRF_CLASS_METHOD | ( | uint |  | ) |

Get the number of allocated classes.

Get the number of allocated specs within a particular class.

Returns:
  The number of classes.

Parameters:

  | cls_id | The class to get the size of.

Precondition:
  cls_id < GetCount()

Returns:
  The size of the class.

Definition at line 124 of file newgrf_class_func.h.

DEFINE_NEWGRF_CLASS_METHOD | ( | StringID |  | ) |

Get the name of a particular class.

Parameters:

  | cls_id | The class to get the name of.

Precondition:
  index < GetCount(cls_id)

Returns:
  The name of said class.

Definition at line 101 of file newgrf_class_func.h.

DEFINE_NEWGRF_CLASS_METHOD | ( | Tid |  | ) |

Allocate a class with a given global class ID.

Parameters:

  | cls_id | The global class id, such as 'DFLT'.

Returns:
  The (non global!) class ID for the class.

Note:
  Upon allocating the same global class ID for a second time, this first allocation will be given.

Definition at line 50 of file newgrf_class_func.h.

References grfmsg().