Hi All,
My question is about the factory class of a stimulus (core) plugin. I had written this plugin for earlier versions of MonkeyWorks, and now I am adapting it to work with recent versions of MWorks.
My stimulus class is derived from the BasicTransformStimulus class. I noticed that in the current version the BasicTransformStimulus constructor accepts an argument of the type ParameterValueMap. Therefore, I modified my stimulus constructor to accept one argument of the same type as ParameterValueMap. (I am not sure whether that was a proper choice I made for the plugin and whether it conforms with the new MWorks core architecture).
Now I am wondering what is the pattern to define a new object of my stimulus class in the factory method “createObject”, given the fact that “createObject” receives an argument of the type “std::map<std::string, std::string>”.
Thanks in advance,
Alireza
Hi Alireza,
The current component architecture is designed to eliminate the need for custom factory classes. The correct approach is probably best explained by example, so I encourage you to take a look at my DynamicRandomDots plugin. The following two methods of the DynamicRandomDots
class are key:
static void describeComponent(ComponentInfo &info);
explicit DynamicRandomDots(const ParameterValueMap ¶meters);
The first method defines the component type and specifies what parameters it takes. Parameters can be required or optional and can have a default value. Note that the first thing it does is call describeComponent
on its base class (BasicTransformStimulus
in your case), in order to add the base’s parameters to the ComponentInfo
object.
The second method is the constructor, which uses the contents of the ParameterValueMap
to initialize member variables. The ParameterValue
class supports casting to a variety of common types (including shared_ptr<Variable>
), so you can generally follow the example of DynamicRandomDots
and directly initialize your member variables with parameters[PARAMETER_NAME]
.
With these two methods in place, you can eliminate your custom factory and instead use the StandardStimulusFactory
template. Take a look at DynamicRandomDotsPlugin::registerComponents
to see how this is done.
Hopefully this will be enough to get you started. If you need additional assistance, please let me know!
Chris