Example: Creating an operator with a dynamic interface

By using the example operator, a user can specify up to two fields of the input interface schema.

The following figure shows an example of an operator with a dynamic interface schema:

Figure 1. Operator with a dynamic interfaceOperator with a dynamic interface

The constructor for this operator takes as input a string defining these two fields. This string must be incorporated into the complete schema definition statement required by setInputInterfaceSchema() in describeOperator().

For example, if the constructor is called as:
ADynamicOperator myOp("field1:int32; field2:int16; ");
the complete input schema definition for this operator would be:
"record (field1:int32; field2:int16; inRec:*;) "
ADynamicOperator is derived from APT_Operator, as shown in the following table:
Table 1. Example of an operator with a dynamic interface
Comment Code
#include <apt_framework/orchestrate.h>

class ADynamicOperator : public APT_Operator
{

	APT_DECLARE_RTTI(ADynamicOperator);
	APT_DECLARE_PERSISTENT(ADynamicOperator);
 

8
9
 
	public:
		ADynamicOperator(char * inSchema);
		ADynamicOperator();

	protected:
		virtual APT_Status describeOperator();
		virtual APT_Status runLocally();
		virtual APT_Status initializeFromArgs_(const APT_PropertyList 
			&args,  APT_Operator::InitializeContext context); 
  
15
	private:
		APT_String inputSchema;
};
16
#define ARGS_DESC "{}"
17
APT_DEFINE_OSH_NAME(ADynamicOperator, dynamicOp, ARGS_DESC);
18
19
APT_IMPLEMENT_RTTI_ONEBASE(ADynamicOperator, APT_Operator);
APT_IMPLEMENT_PERSISTENT(ADynamicOperator);
20
ADynamicOperator::ADynamicOperator(char * inSchema)
{
	inputSchema = APT_String("record(") + inSchema + "inRec:*;)";
}
24
APT_Status ADynamicOperator::initializeFromArgs_(const APT_PropertyList
	&args, APT_Operator::InitializeContext context) 
{ 
	return APT_StatusOk; 
}

APT_Status ADynamicOperator::describeOperator()
{
	setInputDataSets(1);
	setOutputDataSets(1);

	setInputInterfaceSchema(inputSchema.data(), 0);
	setOutputInterfaceSchema("record (outRec:*;)", 0);

	declareTransfer("inRec", "outRec", 0, 0);

	return APT_StatusOk;
}

APT_Status ADynamicOperator::runLocally()
{
	APT_InputCursor inCur;
	APT_OutputCursor outCur;

	setupInputCursor(&inCur, 0); 
	setupOutputCursor(&outCur, 0);
43
	APT_MultiFieldAccessor inAccessor(inputInterfaceSchema(0)); 
44







	inAccessor.setup(&inCur); 

	while (inCur.getRecord()) 
  { 
		transfer(0);
		outCur.putRecord();
	}
	return APT_StatusOk;
}
52
void ADynamicOperator::serialize(APT_Archive& archive, APT_UInt8)
{
	archive || inputSchema;
}
8
Declare a constructor that takes a string defining part of the input interface schema.
9
Declare a default constructor. This constructor is required by the persistence mechanism.
15
Define inputSchema, an instance of APT_String, to hold the complete input interface schema of this operator. The complete input interface schema is equal to the schema passed in to the constructor, plus the definition of the schema variable inRec.
16
See the header file argvcheck.h for documentation on the ARGS_DESC string.
17
With APT_DEFINE_OSH_NAME, you connect the class name to the name used to invoke the operator from osh and pass your argument description string. See osh_name.h for documentation on this macro.
18 - 19
APT_IMPLEMENT_RTTI_ONEBASE and APT_IMPLEMENT_PERSISTENT are required macros that implement run-time type information and persistent object processing.
20
The constructor creates the complete schema definition statement and writes it to the private data member inputSchema.
24
With your override of initializeFromArgs_(), you transfer information from the arguments to the class instance. Because there are no arguments for this example, initializeFromArgs_() returns APT_StatusOk. See the header file operator.h for documentation on this function.
43
Define inAccessor, an instance of APT_MultiFieldAccessor. The constructor for APT_MultiFieldAccessor takes a single argument containing a schema definition. In this example, you use APT_Operator::inputInterfaceSchema() to return the schema of the input interface as set by setInputInterfaceSchema() in describeOperator().
44
Use APT_MultiFieldAccessor::setup() to initialize the multifield accessor for all components of the input interface schema.
52
ADynamicOperator defines a single data member, inputSchema. You must serialize inputSchema within serialize()