#ifndef PLOT_DATA_H #define PLOT_DATA_H #include #include "Range.h" #include class Data { using Key = float; using Value = float; public: struct KeyVal { Key key; Value val; KeyVal(const Key& key, const Value& val) : key(key), val(val) {;} }; private: /** contained data */ std::vector data; public: /** add a new value */ void add(const Key key, const Value val) { data.push_back(KeyVal(key,val)); } /** remove the given index */ void remove(const int idx) { data.erase(data.begin()+idx); } Key getKey(const int idx) const { return data[idx].key; } Value getValue(const int idx) const { return data[idx].val; } const KeyVal& getKeyValue(const int idx) const { return data[idx]; } const KeyVal& operator [] (const int idx) const { return data[idx]; } const KeyVal& front() const {return data.front();} const KeyVal& back() const {return data.back();} /** get the range (min/max) for the key-data (x-axes) */ Range getKeyRange() const { Range range(+INFINITY,-INFINITY); for (const KeyVal& kv : data) {range.adjust(kv.key);} return range; } /** get the range (min/max) for the value-data (y-axes) */ Range getValueRange() const { Range range(+INFINITY,-INFINITY); for (const KeyVal& kv : data) {range.adjust(kv.val);} return range; } /** get the number of entries */ size_t size() const { return data.size(); } }; #endif // PLOT_DATA_H