OpenTTD Source: DriverFactoryBase Class Reference

OpenTTD Source 15.0-beta1

Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Types | Static Private Member Functions | Private Attributes | Friends
DriverFactoryBase Class Referenceabstract

Base for all driver factories. More...

`#include <driver.h>`

Inheritance diagram for DriverFactoryBase:

## Public Member Functions
std::string_view | GetDescription () const
| Get a nice description of the driver-class.
virtual Driver * | CreateInstance () const =0
| Create an instance of this driver-class.

## Static Public Member Functions
static void | ShutdownDrivers ()
| Shuts down all active drivers.
static void | SelectDriver (const std::string &name, Driver::Type type)
| Find the requested driver and return its class.
static void | GetDriversInfo (std::back_insert_iterator< std::string > &output_iterator)
| Build a human readable list of available drivers, grouped by type.

## Protected Member Functions
| DriverFactoryBase (Driver::Type type, int priority, const char *name, const char *description)
| Construct a new DriverFactory.
virtual | ~DriverFactoryBase ()
| Frees memory used for this->name.
virtual bool | UsesHardwareAcceleration () const
| Does the driver use hardware acceleration (video-drivers only).

## Private Types
typedef std::map< std::string, DriverFactoryBase * > | Drivers
| Type for a map of drivers.

## Static Private Member Functions
static Drivers & | GetDrivers ()
| Get the map with drivers.
static Driver ** | GetActiveDriver (Driver::Type type)
| Get the active driver for the given type.
static std::string_view | GetDriverTypeName (Driver::Type type)
| Get the driver type name.
static bool | SelectDriverImpl (const std::string &name, Driver::Type type)
| Find the requested driver and return its class.
static void | MarkVideoDriverOperational ()
| Mark the current video driver as operational.

## Private Attributes
Driver::Type | type
| The type of driver.
int | priority
| The priority of this factory.
std::string_view | name
| The name of the drivers of this factory.
std::string_view | description
| The description of this driver.

## Friends
class | MusicDriver
class | SoundDriver
class | VideoDriver

## Detailed Description

Base for all driver factories.

Definition at line 57 of file driver.h.

## Member Typedef Documentation

## ◆ Drivers

typedef std::map<std::string, DriverFactoryBase *> DriverFactoryBase::Drivers
| private

Type for a map of drivers.

Definition at line 68 of file driver.h.

## Constructor & Destructor Documentation

## ◆ DriverFactoryBase()

DriverFactoryBase::DriverFactoryBase | ( | Driver::Type | type,
|  | int | priority,
|  | const char * | name,
|  | const char * | description
| ) |  |
| protected

Construct a new DriverFactory.

Parameters

  type | The type of driver.
  priority | The priority within the driver class.
  name | The name of the driver.
  description | A long-ish description of the driver.

Definition at line 244 of file driver.cpp.

References GetDrivers(), GetDriverTypeName(), name, and type.

## ◆ ~DriverFactoryBase()

DriverFactoryBase::~DriverFactoryBase | ( |  | ) |
| protectedvirtual

Frees memory used for this->name.

Definition at line 258 of file driver.cpp.

References GetDrivers(), GetDriverTypeName(), name, and type.

## Member Function Documentation

## ◆ CreateInstance()

virtual Driver * DriverFactoryBase::CreateInstance | ( |  | ) | const
| pure virtual

Create an instance of this driver-class.

Returns
  The instance.

Implemented in FMusicDriver_Allegro, FMusicDriver_BeMidi, FMusicDriver_Cocoa, FMusicDriver_DMusic, FMusicDriver_ExtMidi, FMusicDriver_FluidSynth, FMusicDriver_Null, FMusicDriver_Win32, FSoundDriver_Allegro, FSoundDriver_Cocoa, FSoundDriver_Null, FSoundDriver_SDL, FSoundDriver_Win32, FSoundDriver_XAudio2, FVideoDriver_Allegro, FVideoDriver_CocoaOpenGL, FVideoDriver_CocoaQuartz, FVideoDriver_Dedicated, FVideoDriver_Null, FVideoDriver_SDL_Default, FVideoDriver_SDL_OpenGL, FVideoDriver_SDL, and FVideoDriver_Win32GDI.

Referenced by SelectDriverImpl().

## ◆ GetActiveDriver()

static Driver ** DriverFactoryBase::GetActiveDriver | ( | Driver::Type | type | ) |
| inlinestaticprivate

Get the active driver for the given type.

Parameters

  type | The type to get the driver for.

Returns
  The active driver.

Definition at line 84 of file driver.h.

Referenced by MusicDriver::GetInstance(), SoundDriver::GetInstance(), VideoDriver::GetInstance(), and SelectDriverImpl().

## ◆ GetDescription()

std::string_view DriverFactoryBase::GetDescription | ( |  | ) | const
| inline

Get a nice description of the driver-class.

Returns
  The description.

Definition at line 138 of file driver.h.

Referenced by GetDriversInfo().

## ◆ GetDrivers()

static Drivers & DriverFactoryBase::GetDrivers | ( |  | ) |
| inlinestaticprivate

Get the map with drivers.

Definition at line 73 of file driver.h.

Referenced by DriverFactoryBase(), GetDriversInfo(), SelectDriverImpl(), and ~DriverFactoryBase().

## ◆ GetDriversInfo()

void DriverFactoryBase::GetDriversInfo | ( | std::back_insert_iterator< std::string > & | output_iterator | ) |
| static

Build a human readable list of available drivers, grouped by type.

Parameters

  output_iterator | The iterator to write the string to.

Definition at line 219 of file driver.cpp.

References Driver::DT_BEGIN, Driver::DT_END, GetDescription(), GetDrivers(), GetDriverTypeName(), name, priority, and type.

Referenced by ShowHelp().

## ◆ GetDriverTypeName()

static std::string_view DriverFactoryBase::GetDriverTypeName | ( | Driver::Type | type | ) |
| inlinestaticprivate

Get the driver type name.

Parameters

  type | The type of driver to get the name of.

Returns
  The name of the type.

Definition at line 95 of file driver.h.

Referenced by DriverFactoryBase(), GetDriversInfo(), SelectDriver(), SelectDriverImpl(), and ~DriverFactoryBase().

## ◆ MarkVideoDriverOperational()

void DriverFactoryBase::MarkVideoDriverOperational | ( |  | ) |
| staticprivate

Mark the current video driver as operational.

Definition at line 206 of file driver.cpp.

References BASE_DIR, FioFindFullPath(), FioRemove(), and HWACCELERATION_TEST_FILE.

Referenced by VideoDriver::Tick().

## ◆ SelectDriver()

void DriverFactoryBase::SelectDriver | ( | const std::string & | name,
|  | Driver::Type | type
| ) |  |
| static

Find the requested driver and return its class.

Parameters

  name | the driver to select.
  type | the type of driver to select

Postcondition
  Sets the driver so GetCurrentDriver() returns it too.

Definition at line 88 of file driver.cpp.

References GetDriverTypeName(), name, SelectDriverImpl(), and type.

Referenced by openttd_main().

## ◆ SelectDriverImpl()

bool DriverFactoryBase::SelectDriverImpl | ( | const std::string & | name,
|  | Driver::Type | type
| ) |  |
| staticprivate

Find the requested driver and return its class.

Parameters

  name | the driver to select.
  type | the type of driver to select

Postcondition
  Sets the driver so GetCurrentDriver() returns it too.

Returns
  True upon success, otherwise false.

Definition at line 104 of file driver.cpp.

References _video_hw_accel, BASE_DIR, CreateInstance(), Debug, Driver::DT_VIDEO, FioFindFullPath(), FioFOpenFile(), FioRemove(), GetActiveDriver(), GetDrivers(), GetDriverTypeName(), HWACCELERATION_TEST_FILE, name, priority, ScheduleErrorMessage(), Driver::Start(), StrEqualsIgnoreCase(), type, and UsesHardwareAcceleration().

Referenced by SelectDriver().

## ◆ ShutdownDrivers()

static void DriverFactoryBase::ShutdownDrivers | ( |  | ) |
| inlinestatic

Shuts down all active drivers.

Definition at line 123 of file driver.h.

References Driver::DT_BEGIN, Driver::DT_END, and Driver::Stop().

Referenced by ShutdownGame().

## ◆ UsesHardwareAcceleration()

virtual bool DriverFactoryBase::UsesHardwareAcceleration | ( |  | ) | const
| inlineprotectedvirtual

Does the driver use hardware acceleration (video-drivers only).

Returns
  True if the driver uses hardware acceleration.

Reimplemented in FVideoDriver_CocoaOpenGL, and FVideoDriver_SDL_OpenGL.

Definition at line 114 of file driver.h.

Referenced by SelectDriverImpl().

## Friends And Related Symbol Documentation

## ◆ MusicDriver

friend class MusicDriver
| friend

Definition at line 59 of file driver.h.

## ◆ SoundDriver

friend class SoundDriver
| friend

Definition at line 60 of file driver.h.

## ◆ VideoDriver

friend class VideoDriver
| friend

Definition at line 61 of file driver.h.

## Field Documentation

## ◆ description

std::string_view DriverFactoryBase::description
| private

The description of this driver.

Definition at line 66 of file driver.h.

## ◆ name

std::string_view DriverFactoryBase::name
| private

The name of the drivers of this factory.

Definition at line 65 of file driver.h.

Referenced by DriverFactoryBase(), GetDriversInfo(), SelectDriver(), SelectDriverImpl(), and ~DriverFactoryBase().

## ◆ priority

int DriverFactoryBase::priority
| private

The priority of this factory.

Definition at line 64 of file driver.h.

Referenced by GetDriversInfo(), and SelectDriverImpl().

## ◆ type

Driver::Type DriverFactoryBase::type
| private

The type of driver.

Definition at line 63 of file driver.h.

Referenced by DriverFactoryBase(), GetDriversInfo(), SelectDriver(), SelectDriverImpl(), and ~DriverFactoryBase().

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

- src/driver.h
- src/driver.cpp