Share

Write your source code

You can find the complete source code at the bottom of this page.

Operators are implemented as functions. The parameters passed to the function become the ports on the operator. The type of port a parameter is instantiated into is determined by the order in which it appears in the parameter list, and whether it is passed by const or non-const reference.

Parameters that come first in the parameter list, and that are passed by value or const reference are instantiated into input ports. Parameters that come last in the list and that are passed by non-const reference are instantiated into output ports.

integer_to_string takes an int as input and converts it to an Amino::String. The int comes first in the parameter list and because int is a primitive type, it does not need to be explicitly declared as const for it to be interpreted as an input. The Amino::String output comes last in the parameter list and is passed by non-const reference.

void Examples::SDK::integer_to_string (int original_int, Amino::String& string_from_int)

join_strings has two Amino::String inputs. In addition to needing to come first in the parameter list before the output parameter, these two parameters need to be declared as const references to be interpreted as inputs. The output Amino::String parameter comes last and is declared as a non-const reference.

void Examples::SDK::join_strings (const Amino::String& first_string,
                                  const Amino::String& second_string,
                                  Amino::String& concatenated)

The source code for both operators will be in the same file for convenience. However, the source code for operators that will be distributed together can be in multiple files as long as they are compiled into one library.

integer_to_string converts an integer input to an Amino::String. To do this, it takes the input int and convert it to a C++ std::string. It then instantiates an Amino::String with the std::string.

Assigning a value to the output parameter automatically places that value on the corresponding output port.

std::string converted_int = std::to_string(original_int);
string_from_int = Amino::String(converted_int.c_str(), converted_int.size());

The second node takes two Amino::String inputs, and outputs a third Amino string. This is very straightforward and uses the additive property of Amino::String to concatenate the inputs.

Again, as soon as the output parameter is assigned a value, that value is placed on its corresponding output port.

concatenated = first_string + second_string;

Continue to writing your header file.

The complete source code

#include "SimpleString.h"
#include <string>

//------------------------------------------------------------------------------
//
void Examples::SDK::join_strings (const Amino::String& first_string,
                                  const Amino::String& second_string,
                                  Amino::String& concatenated) {

    concatenated = first_string + second_string;

}

//------------------------------------------------------------------------------
//
void Examples::SDK::integer_to_string (int original_int, Amino::String& string_from_int) {

    std::string converted_int = std::to_string(original_int);
    string_from_int = Amino::String(converted_int.c_str(), converted_int.size());
}

Was this information helpful?