/* Below is the copyright agreement for the Ptolemy II system. Copyright (c) 1995-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. Ptolemy II includes the work of others, to see those copyrights, follow the copyright link on the splash page or see copyright.htm. */ package ptolemy.actor.util; import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Set; import ptolemy.actor.IOPort; import ptolemy.actor.TypedIOPort; import ptolemy.data.type.BaseType; import ptolemy.data.type.MonotonicFunction; import ptolemy.data.type.Type; import ptolemy.data.type.TypeLattice; import ptolemy.graph.InequalityTerm; import ptolemy.kernel.util.IllegalActionException; /////////////////////////////////////////////////////////////////// //// GLBFunction /** This class implements a monotonic function that returns the greatest * lower bound (GLB) of its arguments. These arguments are the port type * variables of the destination ports of the TypedIOPort passed to the * constructor. This function is used to define a type constraint asserting * that the type of the output of this port is greater than or equal to the * GLB of its destinations. *
* NOTE: It may seem counterintuitive that the constraint is "greater than
* or equal to" rather than "less than or equal to". But the latter
* constraint is already implied by the connections, since the output port
* type is required to be less than or equal to each destination port type.
* The combination of these constraints has the effect of setting the type
* of the output equal to the GLB of the types of the destination ports.
* This resolved type is, in fact, the most specific type that satisfies the
* constraints of all the downstream ports.
* @author Edward A. Lee, Marten Lohstroh
* @version $Id: GLBFunction.java$
* @since Ptolemy II 10.0
* @Pt.ProposedRating Red (eal)
* @Pt.AcceptedRating Red (cxh)
*/
public class GLBFunction extends MonotonicFunction {
/** Construct a GLBFunction that finds the greatest lower bound of the
* type variable of the destination ports connected to the TypedIOPort
* that is given as an argument. If the boolean argument inside is true
* then the port is required to be an input port and the arguments for
* this GLBFunction
will be the inside destination ports.
* Otherwise, the port is required to be an output port and the arguments
* for this GLBFunction
will be the outside destination ports.
*
* @param sourcePort The port connected to the ports of which their type
* variables are used to calculate the greatest lower bound.
*
*/
public GLBFunction(TypedIOPort sourcePort) {
_sourcePort = sourcePort;
}
///////////////////////////////////////////////////////////////////
//// public methods ////
/** Return the current value of this monotonic function.
* @return A Type.
* @exception IllegalActionException If thrown while getting the
* value of the cached terms.
*/
@Override
public Object getValue() throws IllegalActionException {
_updateArguments();
SetgetValue()
, which are the
* InequalityTerms and Types of the destination ports. The arguments are
* only updated if the workspace version has changed.
*/
protected void _updateArguments() {
List