2.7.2. 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:

Example 2.27. Creating an instance of a component

CASIModule * MyModelFactory::createInstance(CASIModuleIF *parent,
            const std::string& instance_name) 
{
    return new MyModel(parent, const std::string& instance_name);
}
Copyright © 2007 ARM Limited. All rights reserved.ARM DUI 0359B
Non-Confidential