A factory which creates Component objects. More...
#include <ComponentFactory.h>
Static Public Member Functions | |
static refcount_ptr< Component > | CreateComponent (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 void | RunUnitTests (int &nSucceeded, int &nFailures) |
Runs unit test cases. More... | |
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.
|
static |
Creates a component given a short component name.
componentNameAndOptionalArgs may be e.g. "testmips(cpu=R4400,cpus=4)"
.
componentNameAndOptionalArgs | The component name, e.g. "dummy", optionally followed by arguments in parentheses. |
gxemul | A pointer to a GXemul instance. May be NULL. |
Definition at line 87 of file ComponentFactory.cc.
References ComponentCreateArgs::componentCreationSettings, ComponentListEntry::componentName, GXemul::GetUI(), ComponentCreateArgs::gxemul, UI::ShowDebugMessage(), and StringHelper::SplitStringIntoVector().
Referenced by Component::Clone(), TestMIPSMachine::Create(), TestM88KMachine::Create(), MVME187Machine::Create(), SGI_IP30_Machine::Create(), SGI_IP32_Machine::Create(), CycloneVHMachine::Create(), HP700RXMachine::Create(), GXemul::DumpMachineAsHTML(), ListComponentsCommand::Execute(), GXemul::GenerateHTMLListOfComponents(), and RegisterComponentClass().
|
static |
Returns a vector of all available component names.
onlyTemplates | If true, only those component names that are templates are returned. |
Definition at line 217 of file ComponentFactory.cc.
Referenced by ListComponentsCommand::Execute(), GXemul::GenerateHTMLListOfComponents(), and GXemul::ListTemplates().
|
static |
Gets a specific attribute value for a component.
name | The name of a component, e.g. "testmips". |
attributeName | The attribute, e.g. "template" or "machine". |
Definition at line 189 of file ComponentFactory.cc.
Referenced by ListComponentsCommand::Execute(), GXemul::GenerateHTMLListOfComponents(), HasAttribute(), and GXemul::ListTemplates().
|
static |
Get override arguments for component creation.
Definition at line 156 of file ComponentFactory.cc.
References ComponentCreateArgs::componentCreationSettings, GXemul::GetUI(), ComponentCreateArgs::gxemul, and UI::ShowDebugMessage().
Referenced by CycloneVHMachine::Create(), HP700RXMachine::Create(), SGI_IP32_Machine::Create(), TestM88KMachine::Create(), SGI_IP30_Machine::Create(), TestMIPSMachine::Create(), MVME187Machine::Create(), I960_CPUComponent::Create(), MIPS_CPUComponent::Create(), and M88K_CPUComponent::Create().
|
static |
Checks if a component has a specific attribute.
name | The name of a component, e.g. "testmips". |
attributeName | The attribute, e.g. "template" or "machine". |
Definition at line 210 of file ComponentFactory.cc.
References GetAttribute().
Referenced by GXemul::GenerateHTMLListOfComponents(), and GXemul::IsTemplateMachine().
|
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.
name | The name of the component class. Must be a const char* which lives for the lifetime of the program. |
createFunc | A pointer to the component's Create function. |
getAttributeFunc | A pointer to the component's GetAttribute function. |
Definition at line 54 of file ComponentFactory.cc.
References CreateComponent(), and refcount_ptr< T >::IsNULL().
|
static |
|
static |
Unregisters all manually registered component classes.
Definition at line 80 of file ComponentFactory.cc.
Referenced by internal_w().