![]() |
![]() |
![]() |
cpg-network Reference Manual | ![]() |
---|
Using TemplatesUsing Templates — How to use template definitions in networks |
As soon as you start making larger networks, for instance with coupled oscillators, you will notice that you are duplicating a lot of states and links with common properties and actions. To somewhat assist this, you can define template objects in your network. These objects represent basic templates on which you can base new objects. Internally, when you instantiate a new object from a template, the template simply gets copied and you can then add/remove or change any properties on it to model the specific instance of that object.
To add a template programmatically to the network, you can use cpg_group_add to the template group of the network (cpg_network_get_template_group) which simply takes an object. Similarly you can remove a template from the network using cpg_group_remove. The XML specification also supports specifying templates similar to specifying normal states and links, but in a separate templates section (see CPG Network XML specification).
When you have some templates defined in your network, you can instantiate
new objects from them by using
cpg_network_add_from_template.
This adds a new object to the network based on the specified template and
returns that object. You can than manipulate it as usual. Adding a link from
a template is done using