001/* A logical NOT operator. 002 003 Copyright (c) 1997-2014 The Regents of the University of California. 004 All rights reserved. 005 Permission is hereby granted, without written agreement and without 006 license or royalty fees, to use, copy, modify, and distribute this 007 software and its documentation for any purpose, provided that the above 008 copyright notice and the following two paragraphs appear in all copies 009 of this software. 010 011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 014 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 015 SUCH DAMAGE. 016 017 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 021 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 022 ENHANCEMENTS, OR MODIFICATIONS. 023 024 PT_COPYRIGHT_VERSION_2 025 COPYRIGHTENDKEY 026 027 */ 028package ptolemy.actor.lib.logic; 029 030import ptolemy.actor.lib.Transformer; 031import ptolemy.data.BooleanToken; 032import ptolemy.data.type.BaseType; 033import ptolemy.kernel.CompositeEntity; 034import ptolemy.kernel.util.IllegalActionException; 035import ptolemy.kernel.util.NameDuplicationException; 036 037/////////////////////////////////////////////////////////////////// 038//// LogicalNot 039 040/** 041 This actor implements a logical NOT operator. It has one input and 042 one output port, neither of which is a multiport, and both of which have 043 type boolean. A BooleanToken that arrives in the <i>input</i> 044 will be negated and sent on the <i>output</i>. 045 If no input token is available, then no output is produced. 046 047 @author John Li 048 @version $Id$ 049 @since Ptolemy II 0.4 050 @Pt.ProposedRating Green (pwhitake) 051 @Pt.AcceptedRating Green (pwhitake) 052 */ 053public class LogicalNot extends Transformer { 054 /** Construct an actor in the specified container with the specified 055 * name. 056 * @param container The container. 057 * @param name The name of this actor within the container. 058 * @exception IllegalActionException If the actor cannot be contained 059 * by the proposed container. 060 * @exception NameDuplicationException If the name coincides with 061 * an actor already in the container. 062 */ 063 public LogicalNot(CompositeEntity container, String name) 064 throws IllegalActionException, NameDuplicationException { 065 super(container, name); 066 input.setTypeEquals(BaseType.BOOLEAN); 067 output.setTypeEquals(BaseType.BOOLEAN); 068 069 _attachText("_iconDescription", 070 "<svg>\n" + "<rect x=\"-15\" y=\"-15\" " 071 + "width=\"30\" height=\"30\" " 072 + "style=\"fill:white\"/>\n" + "<text x=\"-4\" y=\"8\"" 073 + "style=\"font-size:24\">!</text>\n" + "</svg>\n"); 074 } 075 076 /////////////////////////////////////////////////////////////////// 077 //// public methods //// 078 079 /** Consume exactly one token from the input, negate it, and send 080 * it to the output. 081 * @exception IllegalActionException If there is no director. 082 */ 083 @Override 084 public void fire() throws IllegalActionException { 085 super.fire(); 086 if (input.hasToken(0)) { 087 output.send(0, ((BooleanToken) input.get(0)).not()); 088 } 089 } 090}