From 60a0bfb863aa2a05bafd943423c284f5c2d68863 Mon Sep 17 00:00:00 2001 From: Samuel Fadel Date: Mon, 25 Jan 2016 19:55:52 +0100 Subject: Scatterplots & splat now share the same scaling. --- numericrange.h | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 numericrange.h (limited to 'numericrange.h') diff --git a/numericrange.h b/numericrange.h new file mode 100644 index 0000000..d86e578 --- /dev/null +++ b/numericrange.h @@ -0,0 +1,79 @@ +#ifndef NUMERICRANGE_H +#define NUMERICRANGE_H + +#include +#include + +/* + * A range in [first, last) in steps of 1. + */ +template +class NumericRange +{ +public: + class iterator + { + friend class NumericRange; + public: + typedef iterator self_type; + typedef T value_type; + typedef T& reference; + typedef T* pointer; + typedef std::bidirectional_iterator_tag iterator_category; + typedef int difference_type; + + iterator(const T &first): m_value(first) {} + + T operator *() const { return m_value; } + const iterator &operator ++() { + ++m_value; + return *this; + } + iterator operator++(int) { + iterator copy(*this); + ++m_value; + return copy; + } + const iterator &operator --() { + --m_value; + return *this; + } + iterator operator--(int) { + iterator copy(*this); + --m_value; + return copy; + } + + bool operator ==(const iterator &other) const { + return m_value == other.m_value; + } + bool operator !=(const iterator &other) const { + return m_value != other.m_value; + } + + private: + T m_value; + }; + + NumericRange(const T &first, const T &last) + : m_begin(first) + , m_end(last) + { + if (first > last) { + throw std::logic_error("first > last"); + } + } + + typedef const iterator const_iterator; + + iterator begin() const { return m_begin; } + iterator end() const { return m_end; } + + const_iterator cbegin() const { return m_begin; } + const_iterator cend() const { return m_end; } + +private: + iterator m_begin, m_end; +}; + +#endif // NUMERICRANGE_H -- cgit v1.2.3