diff options
author | Marius Kintel <marius@kintel.net> | 2013-12-09 04:12:13 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2013-12-09 04:12:13 (GMT) |
commit | 462d4d447885594629fefb8a658f9f1d079bcc44 (patch) | |
tree | 6690951e4f814b87a1a372a913b75ceda1f6cc1a /src/value.h | |
parent | 435e0c021c5018ee5de69d3218c3e31c8ab75be5 (diff) | |
parent | 33c34b6f7c43d19bbfa3bf91e7b577bcc062e5bd (diff) |
Merge branch 'master' into travis
Diffstat (limited to 'src/value.h')
-rw-r--r-- | src/value.h | 76 |
1 files changed, 54 insertions, 22 deletions
diff --git a/src/value.h b/src/value.h index 388b721..75dff2b 100644 --- a/src/value.h +++ b/src/value.h @@ -11,6 +11,7 @@ #include <boost/variant.hpp> #include <boost/lexical_cast.hpp> #endif +#include <boost/cstdint.hpp> class QuotedString : public std::string { @@ -31,33 +32,64 @@ std::ostream &operator<<(std::ostream &stream, const Filename &filename); class Value { public: - struct RangeType { + class RangeType { + private: + double begin_val; + double step_val; + double end_val; + + /// inverse begin/end if begin is upper than end + void normalize(); + + public: + typedef enum { RANGE_TYPE_BEGIN, RANGE_TYPE_RUNNING, RANGE_TYPE_END } type_t; + + class iterator { + public: + typedef iterator self_type; + typedef double value_type; + typedef double& reference; + typedef double* pointer; + typedef std::forward_iterator_tag iterator_category; + typedef double difference_type; + iterator(RangeType &range, type_t type); + self_type operator++(); + self_type operator++(int junk); + reference operator*(); + pointer operator->(); + bool operator==(const self_type& other) const; + bool operator!=(const self_type& other) const; + private: + RangeType ⦥ + double val; + type_t type; + + void update_type(); + }; + + RangeType(double begin, double end) + : begin_val(begin), step_val(1.0), end_val(end) + { + normalize(); + } + RangeType(double begin, double step, double end) - : begin(begin), step(step), end(end) {} + : begin_val(begin), step_val(step), end_val(end) {} bool operator==(const RangeType &other) const { - return this->begin == other.begin && - this->step == other.step && - this->end == other.end; + return this->begin_val == other.begin_val && + this->step_val == other.step_val && + this->end_val == other.end_val; } - /// inverse begin/end if begin is upper than end - void normalize() { - if ((step>0) && (end < begin)) { - std::swap(begin,end); - } - } - /// return number of steps, max int value if step is null - int nbsteps() const { - if (step<=0) { - return std::numeric_limits<int>::max(); - } - return (int)((begin-end)/step); - } - - double begin; - double step; - double end; + iterator begin() { return iterator(*this, RANGE_TYPE_BEGIN); } + iterator end() { return iterator(*this, RANGE_TYPE_END); } + + /// return number of steps, max uint32_t value if step is 0 + uint32_t nbsteps() const; + + friend class tostring_visitor; + friend class bracket_visitor; }; typedef std::vector<Value> VectorType; |