| |||
| Home > The Cycle Accurate Simulation Interface > The component factory class CASIFactory > CASIFactory::createInstance() |
The createInstance() function is called
by the simulation backend to instantiate the component. It must
simply call the new operator of the component
class and return the pointer to this created instance. A pointer
to the parent component is provided as a parameter and this must
be passed on to the component’s constructor:
CASIModuleIF * MyModelFactory::createInstance(CASIModuleIF *parent,
const std::string& instance)
{
return new MyModel(parent, instance);
}
The constructor must be implemented calling the parent’s constructor and must pass the name of the system as a parameter:
MyModelFactory::MyModelFactory() : CASIFactory("MyModel") {}
Use the createInstance() function to
create an instance of the component by passing a pointer to the
parent component as shown in Example 2.27: