00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #ifndef VRS_CONTAINER_LINEARITERATOR_H
00054 #define VRS_CONTAINER_LINEARITERATOR_H
00055
00056 #include <vrs/container/iterator.h>
00057
00058 namespace VRS {
00059
00061 template<typename T>
00062 class LinearIterator : public Iterator<T> {
00063 public:
00064 LinearIterator(const T& startValue, const T& endValue, unsigned int size = 0)
00065 : startValue_(startValue), endValue_(endValue), size_(size) {
00066 }
00070 void setStartValue(const T& startValue) {
00071 if(startValue_ != startValue) {
00072 startValue_ = startValue;
00073 SharedObj::modified();
00074 }
00075 }
00076 const T& getStartValue() const { return startValue_; }
00078 void setEndValue(const T& endValue) {
00079 if(endValue_ != endValue) {
00080 endValue_ = endValue;
00081 SharedObj::modified();
00082 }
00083 }
00084 const T& getEndValue() const { return endValue_; }
00087 virtual unsigned int size() const { return size_; }
00088 void setSize(unsigned int size) {
00089 if(size_ != size) {
00090 size_ = size;
00091 SharedObj::modified();
00092 }
00093 }
00094 virtual T get(unsigned int index) const {
00095 VRS_CheckArg(index < size_, "index out of range");
00096 if(size_ == 1u) { return startValue_; }
00097 const double factor = static_cast<double>(index) / static_cast<double>(size_ - 1u);
00098 return ((1.0 - factor) * startValue_) + (factor * endValue_);
00099 }
00100
00101 VRS_TYPEINFO(LinearIterator, Iterator<T>);
00102 VRS_SERIALIZABLE(LinearIterator);
00103
00104 protected:
00105 LinearIterator() { }
00106
00107 private:
00108 T startValue_;
00109 T endValue_;
00110 unsigned int size_;
00111 };
00112
00113 template<class T>
00114 inline void LinearIterator<T>::serialize(SerializationManager& doc) {
00115 UINT8 version = 0;
00116 doc.classVersion(version);
00117
00118 VRS_SERIALIZATION_PARENT_CLASS(doc, Iterator<T>);
00119 serialization(doc, "Size", size_);
00120 serialization(doc, "StartValue", startValue_);
00121 serialization(doc, "EndValue", endValue_);
00122 }
00123
00124 VRS_SERIALIZATION_REGISTRATION_TEMPLATE(LinearIterator);
00125
00126 }
00127
00128 #endif // VRS_CONTAINER_LINEARITERATOR_H