ANYTYPE
. A star Fork
star, or if it calls a generic function that is overloaded by every data type, such The following is an example of a star that operates on
ANYTYPE
particles:
Notice how in the definition of the output type, the star simply says that its output type will be the same as the input type. ptlang translates this definition into an
ANYTYPE
output porthole and a statement in the star constructor that reads
.cc
file generated for SDFFork
.During galaxy setup, the Ptolemy kernel assigns actual types to
ANYTYPE
portholes, making use of the types of connected portholes and inheritTypeFrom connections. For example, if a Fork's input is connected to an output porthole of type INT
, the Fork's input becomes type INT
, and then so do its output(s) thanks to the inheritTypeFrom connection. At runtime there is no such thing as an ANYTYPE
porthole; every porthole has been resolved to some specific data type, which can be obtained from the porthole using the resolvedType()
method. (However, this mechanism does not distinguish among the various subclasses of Message
, so if you are using Message
particles you still need to check the actual type of each Message
received.)Porthole type assignment is really a fairly complex and subtle algorithm, which is discussed further in the Ptolemy Kernel Manual. The important properties for a star writer to know are these:
out%0 << t;
because this expands into a call of the particle's virtual method for loading a value of the given type. But assuming that you know the exact type of particle in the porthole --- say by writing something like (FloatParticle&) (out%0)
--- is very unsafe.
ANYTYPE
, its component portholes might have different types at runtime. (This was not true in Ptolemy versions preceding 0.7.) The component portholes of an output multiporthole can have different resolved types in any case, because they might be connected to inputs of different types.
ANYTYPE
output porthole; rather, its type should be equated to some input porthole using the ptlang = port
notation or an explicit inheritTypeFrom call. This ensures that the type resolution algorithm can succeed. A "pure ANYTYPE
" output will work only if connected to an input of determinable type; if it's connected to an ANYTYPE
input, the kernel will be unable to resolve a type for the connection. By providing an = type
declaration, you allow the kernel to choose an appropriate particle type for an ANYTYPE
-to-ANYTYPE
connection.