Skip to content
Snippets Groups Projects
Axis.h 4.09 KiB
Newer Older
#ifndef MANTID_API_AXIS_H_
#define MANTID_API_AXIS_H_

#include <boost/shared_ptr.hpp>
namespace Mantid {
namespace Kernel {
class Unit;
}
namespace API {
//----------------------------------------------------------------------
// Forward declaration
//----------------------------------------------------------------------

/** Class to represent the axis of a workspace.

    @author Russell Taylor, Tessella Support Services plc
    @date 16/05/2008
    Copyright &copy; 2008 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
   National Laboratory & European Spallation Source
    Mantid is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    Mantid is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    File change history is stored at: <https://github.com/mantidproject/mantid>.
    Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class MANTID_API_DLL Axis {
  virtual ~Axis() = default;
  /// Virtual constructor
  virtual Axis *clone(const MatrixWorkspace *const parentWorkspace) = 0;
  /// Virtual constructor for axis of different length
  virtual Axis *clone(const std::size_t length,
                      const MatrixWorkspace *const parentWorkspace) = 0;
  const std::string &title() const;
  std::string &title();
  const boost::shared_ptr<Kernel::Unit> &unit() const;
  boost::shared_ptr<Kernel::Unit> &unit();
  virtual const boost::shared_ptr<Kernel::Unit> &
  setUnit(const std::string &unitName);
Nick Draper's avatar
Nick Draper committed
  /// Returns true is the axis is a Spectra axis
  virtual bool isSpectra() const { return false; }
Nick Draper's avatar
Nick Draper committed
  /// Returns true if the axis is numeric
  virtual bool isNumeric() const { return false; }
  /// Returns true if the axis is Text
  virtual bool isText() const { return false; }
Nick Draper's avatar
Nick Draper committed
  /// Returns the value at a specified index
  /// @param index :: the index
  /// @param verticalIndex :: The verticalIndex
  virtual double operator()(const std::size_t &index,
                            const std::size_t &verticalIndex = 0) const = 0;
  /// Gets the value at the specified index. Just calls operator() but is easier
  /// to use with Axis pointers
  double getValue(const std::size_t &index,
                  const std::size_t &verticalIndex = 0) const;
  /// returns min value defined on axis
  virtual double getMin() const = 0;
  /// returns max value defined on axis
  virtual double getMax() const = 0;
Nick Draper's avatar
Nick Draper committed
  /// Sets the value at the specified index
  /// @param index :: The index
  /// @param value :: The new value
  virtual void setValue(const std::size_t &index, const double &value) = 0;
  /// Find the index of the given double value
  virtual size_t indexOfValue(const double value) const = 0;

  /// Get the spectrum number
  virtual specnum_t spectraNo(const std::size_t &index) const;
  /// Get the length of the axis
Peterson, Peter's avatar
Peterson, Peter committed
  virtual std::size_t length() const = 0;
  /// Check whether two axis are the same, i.e same length and same
  /// spectra_values for all elements in the axis
  virtual bool operator==(const Axis &) const = 0;
Laurent Chapon's avatar
Laurent Chapon committed

  /// Returns a text label of for a value
  virtual std::string label(const std::size_t &index) const = 0;
Hahn, Steven's avatar
Hahn, Steven committed
  Axis(const Axis &) = default;
private:
  /// Private, undefined copy assignment operator
  const Axis &operator=(const Axis &) = delete;
  /// The user-defined title for this axis
  std::string m_title;
  /// The unit for this axis
  boost::shared_ptr<Kernel::Unit> m_unit;
};

} // namespace API
} // namespace Mantid

#endif /*MANTID_API_AXIS_H_*/