Developing C++ primitive operators
The SPL language supports writing two styles of primitive operators, namely: generic operators and non-generic operators.
Generic operators can handle various stream types, different numbers of ports, and most importantly, can be configured with parameters and output assignments that involve SPL expressions. Alternately, non-generic operators are less configurable and are often used for one-time tasks that do not require high levels of reuse. Both styles are supported under the same development framework, which eases the process of converting non-generic operators to their generic versions when the need arises.
Creating a new primitive operator involves two main tasks:
- Creating an operator model that describes the syntactic and semantic properties common to all instances of the operator. This model is the oper-name.xml file. For more information, see Primitive operator artifacts.
- Creating the header and implementation code generator templates to implement the operator logic. These templates are the oper-name_h.cgt and the oper-name_cpp.cgt files. For more information, see Primitive operator artifacts.
The operator model enables the compiler to check the syntax and semantics for instances of the primitive operator when used in a stream application. For non-generic operators, a default operator model can be used for convenience, as non-generic operators are not designed to be reusable and do not require strict error checking. The default operator model is the most permissive model and avoids most of the compile-time checks done by the SPL compiler.
Primitive operators are implemented as C++ classes that extend
from a base operator class that is provided by the Teracloud® Streams
instance.
Non-generic operators do not require customization that is based on
the specific operator instance that appears in the SPL source. As
a result, they are implemented as pure C++ code. Conversely, generic
operators require specialization. For instance, the filter condition
that appears as part of a Filter operator might
be different for two different instances of the Filter operator.
Thus, generic operators are written as a mixture of C++ (generated
code) and Perl (generator code). The Perl code appears within <%...%>
sections
and has access to a variable named $model that
provides access to the operator instance configuration1 (for
example, the filter condition as a C++ expression). In essence, the
Perl code is used to generate C++ code that is tailored to the operator
instance at hand.
The spl-make-operator command can be used to create skeleton code generator templates and the default operator model as a starting point.
The spl-make-operator script is also used to
create code generators (oper-name_h.pm
and oper-name_cpp.pm
).
This step can be deferred to toolkit indexing or skipped. For more information,
see the spl-make-operator command reference.