/* An actor that disassembles a UnionToken to the corresponding output. Copyright (c) 2006-2014 The Regents of the University of California. All rights reserved. Permission is hereby granted, without written agreement and without license or royalty fees, to use, copy, modify, and distribute this software and its documentation for any purpose, provided that the above copyright notice and the following two paragraphs appear in all copies of this software. IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. PT_COPYRIGHT_VERSION_2 COPYRIGHTENDKEY */ package ptolemy.actor.lib; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import ptolemy.actor.Director; import ptolemy.actor.IOPort; import ptolemy.actor.Manager; import ptolemy.actor.TypedAtomicActor; import ptolemy.actor.TypedIOPort; import ptolemy.actor.util.ConstructAssociativeType; import ptolemy.actor.util.ExtractFieldType; import ptolemy.data.Token; import ptolemy.data.UnionToken; import ptolemy.data.type.UnionType; import ptolemy.graph.Inequality; import ptolemy.kernel.CompositeEntity; import ptolemy.kernel.util.IllegalActionException; import ptolemy.kernel.util.NameDuplicationException; import ptolemy.kernel.util.NamedObj; import ptolemy.kernel.util.Workspace; /////////////////////////////////////////////////////////////////// //// UnionDisassembler /** On each firing, read one UnionToken from the input port and send out the value to the output port that matches the label name of the input token. This actor is polymorphic. The labels for the UnionToken must match the names of the output ports. This is achieved using three type constraints:
RecordDisassembler
to force the input
to contain a corresponding field for each output port, is useless for
UnionDisassembler
. This is due to the inverse width subtyping
of UnionToken
.
@author Yang Zhao, Marten Lohstroh
@version $Id: UnionDisassembler.java 70398 2014-10-22 23:44:32Z cxh $
@since Ptolemy II 5.2
@Pt.ProposedRating Yellow (marten)
@Pt.AcceptedRating Red (cxh)
@see RecordDisassembler
@see UnionType
*/
public class UnionDisassembler extends TypedAtomicActor {
/** Construct a UnionDisassembler with the given container and name.
* @param container The container.
* @param name The name of this actor.
* @exception IllegalActionException If this actor cannot be contained
* by the proposed container.
* @exception NameDuplicationException If the container already has an
* actor with this name.
*/
public UnionDisassembler(CompositeEntity container, String name)
throws NameDuplicationException, IllegalActionException {
super(container, name);
input = new TypedIOPort(this, "input", true, false);
_attachText("_iconDescription", "\n");
}
///////////////////////////////////////////////////////////////////
//// ports and parameters ////
/** The input port. */
public TypedIOPort input;
///////////////////////////////////////////////////////////////////
//// public methods ////
/** Clone the actor into the specified workspace.
* @param workspace The workspace for the new object.
* @return A new actor.
* @exception CloneNotSupportedException If a derived class contains
* an attribute that cannot be cloned.
*/
@Override
public Object clone(Workspace workspace) throws CloneNotSupportedException {
UnionDisassembler newObject = (UnionDisassembler) super
.clone(workspace);
newObject._portMap = new HashMapNote that the constraint input <= {|x = GENERAL, y = GENERAL, ..|}
* , which is used in RecordDisassembler to force the input to
* contain a corresponding field for each output port, is useless for
* UnionDisassembler. This is due to the inverse width subtyping of
* UnionToken
.