Factory Class of a new stimulus core plugin
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
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Support Staff 1 Posted by Christopher Sta... on 13 Jan, 2012 05:32 PM
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: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 theComponentInfo
object.The second method is the constructor, which uses the contents of the
ParameterValueMap
to initialize member variables. TheParameterValue
class supports casting to a variety of common types (includingshared_ptr<Variable>
), so you can generally follow the example ofDynamicRandomDots
and directly initialize your member variables withparameters[PARAMETER_NAME]
.With these two methods in place, you can eliminate your custom factory and instead use the
StandardStimulusFactory
template. Take a look atDynamicRandomDotsPlugin::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
Christopher Stawarz closed this discussion on 22 Feb, 2012 03:38 PM.