Knowledge of C++ is required when reading this section. Furthermore, reading Infrastructure for Primitive Definition is highly recommended, since it explains some of the more generic and useful classes defined in the MLDesigner kernel. Many of these can be useful in primitives.
C++ code segments are an important part of any primitive definition. They can appear in the setup, begin, go, wrapup, constructor, destructor, exectime, header, code and method items of primitive source code. These items all include a body of arbitrary C++ code, enclosed by curly braces, { and }. In all but the code and header items, the C++ code between braces defines the body of a method of the primitive class. Methods can access any member of the class, including ports for input and output, parameters, and members defined with the public, protected or private items.
In general, the task of an MLDesigner primitive is to receive input particles and/or produce output particles. In addition, there may be side effects (reading or writing files, displaying graphs, or even updating shared data structures). As for all C++ objects, the constructor is called when the primitive is created, and the destructor is called when it is destroyed. In addition, the setup and begin methods - if any - are called every time a new simulation run is started, the go method (which always exists except for primitives like BlackHole and Null) is called each time a primitive is executed, and the wrapup and cleanup methods are called after the simulation run completes.