Lagrangian Particle Code for The Simulation of 2D/3D Fluid Dynamics
 All Classes Files Functions Variables Typedefs Friends Pages
Public Types | Public Member Functions | Static Public Member Functions | List of all members
StateFactory Class Reference

The abstract factory class for creating objects in the State family. More...

#include <state.h>

Public Types

typedef State *(* StateCreateFunc )()
 Defines a function pointer pointing to a function which creates objects in the State family.
 

Public Member Functions

void registerState (std::string name, StateCreateFunc func)
 Registers (links) the state name name with the function func for creating objects in the State family. More...
 

Static Public Member Functions

static StateFactoryinstance ()
 Returns reference to a Singleton object of class StateFactory. More...
 

This function creates an object of the class linked to the

Parameters
[in]namethe name linked to a specific class in the State family via the registrerState member function
Returns
A State * pointer pointing to an object of a specific class in the State family

Example usage:

State* newState = factory.createState(name);
StatecreateState (std::string name)
 

Detailed Description

The abstract factory class for creating objects in the State family.

Author
Chen, Hsin-Chiang (morri.nosp@m.sche.nosp@m.n2008.nosp@m.@gma.nosp@m.il.co.nosp@m.m)
Version
1.0
Date
2014/08/08

Created on: 2014/06/07

Member Function Documentation

StateFactory & StateFactory::instance ( )
static

Returns reference to a Singleton object of class StateFactory.

Parameters
None
Returns
Reference to a static object of class StateFactory

Example usage:

Note
This function is implemented based on the lazy Singleton design pattern; therefore, only one StateFactory instance is allowed in each program
void StateFactory::registerState ( std::string  name,
StateCreateFunc  func 
)

Registers (links) the state name name with the function func for creating objects in the State family.

After registration, name can be used as an argument in the createState member function for creating objects of the linked type in the State family

Parameters
[in]namethe state name
[in]functhe function pointer pointing to the function that creates objects of a specific type in the State family
Returns
None
Note
Instead of using this function directly, consider using the StateRegistrar class for the purpose of linking a state name and a specific class in the State family. The function is kept public in case one wants to use it directly

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