001/*-
002 * Copyright 2016 Diamond Light Source Ltd.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 */
009
010package org.eclipse.january.dataset;
011
012/**
013 * Base class for all broadcast iterators. For speed, there are public members. Note, index is not updated
014 */
015public abstract class BroadcastIteratorBase extends IndexIterator {
016
017        /**
018         * Index in first dataset
019         */
020        public int aIndex;
021        /**
022         * Index in second dataset
023         */
024        public int bIndex;
025        /**
026         * Current value in second dataset
027         */
028        public double bDouble;
029        /**
030         * Current value in second dataset
031         */
032        public long bLong;
033
034        protected boolean asDouble = true;
035        protected boolean read = true;
036
037        protected int[] maxShape;
038
039        /**
040         * position in dataset
041         */
042        protected int[] pos;
043
044        protected Dataset aDataset;
045        protected Dataset bDataset;
046
047        public BroadcastIteratorBase(Dataset a, Dataset b) {
048                aDataset = a;
049                bDataset = b;
050        }
051
052        @Override
053        public int[] getShape() {
054                return maxShape;
055        }
056
057        @Override
058        public int[] getPos() {
059                return pos;
060        }
061
062        /**
063         * @return true if output from iterator is double
064         */
065        public boolean isOutputDouble() {
066                return asDouble;
067        }
068
069        /**
070         * Set to output doubles
071         * @param asDouble
072         */
073        public void setOutputDouble(boolean asDouble) {
074                if (this.asDouble != asDouble) {
075                        this.asDouble = asDouble;
076                        storeCurrentValues();
077                }
078        }
079
080        /**
081         * Read and store current values
082         */
083        abstract protected void storeCurrentValues();
084
085}