001/**
002 *
003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved.
004 *
005 * This library is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public
007 * License as published by the Free Software Foundation; either 
008 * version 2.1 of the License, or (at your option) any later version.
009 * 
010 * This library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013 * Lesser General Public License for more details.
014 * 
015 * You should have received a copy of the GNU Lesser General Public 
016 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
017 * 
018 **/
019package lucee.runtime.interpreter.ref.op;
020
021import java.math.BigDecimal;
022
023import lucee.runtime.PageContext;
024import lucee.runtime.exp.PageException;
025import lucee.runtime.interpreter.ref.Ref;
026import lucee.runtime.interpreter.ref.RefSupport;
027import lucee.runtime.interpreter.ref.literal.LBigDecimal;
028import lucee.runtime.op.Caster;
029
030/**
031 * Plus operation
032 */
033public abstract class Big extends RefSupport implements Ref {
034
035        private Ref right;
036        private Ref left;
037
038        /**
039         * constructor of the class
040         * @param left
041         * @param right
042         */
043        public Big(Ref left, Ref right) {
044                
045                
046                this.left=left;
047                this.right=right;
048        }
049
050        protected static BigDecimal toBigDecimal(PageContext pc,Ref ref) throws PageException {
051                if(ref instanceof LBigDecimal) return ((LBigDecimal)ref).getBigDecimal();
052                return new BigDecimal(Caster.toString(ref.getValue(pc)));
053        }
054
055        protected final BigDecimal getLeft(PageContext pc) throws PageException {
056                return toBigDecimal(pc,left);
057        }
058        
059        protected final BigDecimal getRight(PageContext pc) throws PageException {
060                return toBigDecimal(pc,right);
061        }
062
063        @Override
064    public final String getTypeName() {
065                return "operation";
066        }
067
068}