ComponentFactory Class Reference

Back to the index.

Static Public Member Functions | List of all members
ComponentFactory Class Reference

A factory which creates Component objects. More...

#include <ComponentFactory.h>

Inheritance diagram for ComponentFactory:
UnitTestable

Static Public Member Functions

static refcount_ptr< ComponentCreateComponent (const string &componentNameAndOptionalArgs, GXemul *gxemul=NULL)
 Creates a component given a short component name. More...
 
static string GetAttribute (const string &name, const string &attributeName)
 Gets a specific attribute value for a component. More...
 
static bool HasAttribute (const string &name, const string &attributeName)
 Checks if a component has a specific attribute. More...
 
static vector< string > GetAllComponentNames (bool onlyTemplates)
 Returns a vector of all available component names. More...
 
static bool RegisterComponentClass (const char *name, refcount_ptr< Component >(*createFunc)(const ComponentCreateArgs &args), string(*getAttributeFunc)(const string &attributeName))
 Adds a new component class to the factory at runtime. More...
 
static bool GetCreationArgOverrides (ComponentCreationSettings &settings, const ComponentCreateArgs &createArgs)
 Get override arguments for component creation. More...
 
static void UnregisterAllComponentClasses ()
 Unregisters all manually registered component classes. More...
 
static void RunUnitTests (int &nSucceeded, int &nFailures)
 
- Static Public Member Functions inherited from UnitTestable
static void RunUnitTests (int &nSucceeded, int &nFailures)
 Runs unit test cases. More...
 

Detailed Description

A factory which creates Component objects.

The main usage of the ComponentFactory is simply: "Hey, give me an XYZ component." and the ComponentFactory returns a reference counted pointer to something. This can be a single Component, or it can be something more complex (a Component with children, etc).

This mechanism is also used for templates. If the user wishes to create a "testmips" machine, what actually happens is that CreateComponent() is called with "testmips" as the argument, and it returns an entire tree, which may contain something like:

machine0  [testmips]
|-- cpu0
|-- ram0
-- framebuffer0

(The example above is semi-bogus, but should illustrate the point of CreateComponent().)

Definition at line 59 of file ComponentFactory.h.

Member Function Documentation

◆ CreateComponent()

refcount_ptr< Component > ComponentFactory::CreateComponent ( const string &  componentNameAndOptionalArgs,
GXemul gxemul = NULL 
)
static

◆ GetAllComponentNames()

vector< string > ComponentFactory::GetAllComponentNames ( bool  onlyTemplates)
static

Returns a vector of all available component names.

Parameters
onlyTemplatesIf true, only those component names that are templates are returned.
Returns
A vector of all available component names.

Definition at line 217 of file ComponentFactory.cc.

References UnitTest::Assert(), Component::Clone(), ComponentListEntry::componentName, CreateComponent(), ComponentListEntry::GetAttribute, Component::GetChildren(), Component::GetClassName(), HasAttribute(), refcount_ptr< T >::IsNULL(), UNITTEST, and UNITTESTS.

Referenced by ListComponentsCommand::Execute(), GXemul::GenerateHTMLListOfComponents(), and GXemul::ListTemplates().

◆ GetAttribute()

string ComponentFactory::GetAttribute ( const string &  name,
const string &  attributeName 
)
static

Gets a specific attribute value for a component.

Parameters
nameThe name of a component, e.g. "testmips".
attributeNameThe attribute, e.g. "template" or "machine".
Returns
A string containing the attribute value. This is an empty string if the component does not exist, or if the attribute was not set for the component.

Definition at line 189 of file ComponentFactory.cc.

References ComponentListEntry::componentName, and ComponentListEntry::GetAttribute.

Referenced by ListComponentsCommand::Execute(), GXemul::GenerateHTMLListOfComponents(), and GXemul::ListTemplates().

◆ GetCreationArgOverrides()

bool ComponentFactory::GetCreationArgOverrides ( ComponentCreationSettings settings,
const ComponentCreateArgs createArgs 
)
static

◆ HasAttribute()

bool ComponentFactory::HasAttribute ( const string &  name,
const string &  attributeName 
)
static

Checks if a component has a specific attribute.

Parameters
nameThe name of a component, e.g. "testmips".
attributeNameThe attribute, e.g. "template" or "machine".
Returns
True if the name exists and the attribute is not an empty string, false otherwise (both if the name is not known, and if it is known but the attribute was not set).

Definition at line 210 of file ComponentFactory.cc.

References ComponentListEntry::GetAttribute.

Referenced by DYNTRANS_INSTR(), GXemul::GenerateHTMLListOfComponents(), GetAllComponentNames(), MachineComponent::GetAttribute(), GXemul::IsTemplateMachine(), MainbusComponent::WriteData(), CPUComponent::WriteData(), CacheComponent::WriteData(), and RAMComponent::WriteData().

◆ RegisterComponentClass()

bool ComponentFactory::RegisterComponentClass ( const char *  name,
refcount_ptr< Component >(*)(const ComponentCreateArgs &args)  createFunc,
string(*)(const string &attributeName)  getAttributeFunc 
)
static

Adds a new component class to the factory at runtime.

Component classes added using this function are then available when using e.g. CreateComponent.

Parameters
nameThe name of the component class. Must be a const char* which lives for the lifetime of the program.
createFuncA pointer to the component's Create function.
getAttributeFuncA pointer to the component's GetAttribute function.
Returns
True if the component class was registered, false if the name was already in use.

Definition at line 54 of file ComponentFactory.cc.

References refcount_ptr< T >::IsNULL().

Referenced by DummyComponent::GetAttribute().

◆ RunUnitTests()

static void ComponentFactory::RunUnitTests ( int &  nSucceeded,
int &  nFailures 
)
static

◆ UnregisterAllComponentClasses()

void ComponentFactory::UnregisterAllComponentClasses ( )
static

Unregisters all manually registered component classes.

Definition at line 80 of file ComponentFactory.cc.

Referenced by internal_w().


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

Generated on Fri Dec 7 2018 19:52:23 for GXemul by doxygen 1.8.13