/* Copyright 2018 Michal Fratczak This file is part of habdec. habdec 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. habdec 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 habdec. If not, see . */ #pragma once #include #include #include namespace habdec { template class CompressedVector { public: typedef T TValue; mutable double min_ = 0; mutable double max_ = 0; std::vector values_; virtual ~CompressedVector() = default; CompressedVector() = default; template CompressedVector(const CompressedVector& rhs) : min_(rhs.min_), max_(rhs.max_) // normalized_(rhs.normalized_) { copyValues(rhs); } template CompressedVector(const std::vector& rhs_vec) { min_ = *std::min_element(rhs_vec.begin(), rhs_vec.end()); max_ = *std::max_element(rhs_vec.begin(), rhs_vec.end()); copyValues(rhs_vec, min_, max_); } template const CompressedVector& operator=(const CompressedVector& rhs) { min_ = rhs.min_; max_ = rhs.max_; copyValues(rhs); return *this; } double calcMin() const { if(!values_.size()) return 0; min_ = *std::min_element(values_.begin(), values_.end()); return min_; } double calcMax() const { if(!values_.size()) return 0; max_ = *std::max_element(values_.begin(), values_.end()); return max_; } private: template void copyValues(const std::vector& rhs, double i_min, double i_max) { if(!rhs.size()) { values_.clear(); return; } values_.resize(rhs.size()); std::copy(rhs.begin(), rhs.end(), values_.begin()); } }; // specialization: float --> double template<> template<> void CompressedVector::copyValues(const std::vector& rhs, double i_min, double i_max) { if(!rhs.size()) { values_.clear(); return; } values_.resize(rhs.size()); std::copy(rhs.begin(), rhs.end(), values_.begin()); } // specialization: double --> float template<> template<> void CompressedVector::copyValues(const std::vector& rhs, double i_min, double i_max) { // std::cout<<"specialization: double --> float"< unsigned char template<> template<> void CompressedVector::copyValues(const std::vector& rhs, double i_min, double i_max) { // std::cout<<"specialization: float --> unsigned char"<::max(); values_.push_back(v_out); } } // specialization: float --> uint16_t template<> template<> void CompressedVector::copyValues(const std::vector& rhs, double i_min, double i_max) { // std::cout<<"specialization: float --> uint16_t"<::max(); values_.push_back(v_out); } } // specialization: double --> unsigned char template<> template<> void CompressedVector::copyValues(const std::vector& rhs, double i_min, double i_max) { // std::cout<<"specialization: double --> unsigned char"<::max(); values_.push_back(v_out); } } // specialization: double --> uint16_t template<> template<> void CompressedVector::copyValues(const std::vector& rhs, double i_min, double i_max) { // std::cout<<"specialization: double --> uint16_t"<::max(); values_.push_back(v_out); } } // specialization: unsigned char --> float template<> template<> void CompressedVector::copyValues(const std::vector& rhs, double i_min, double i_max) { // std::cout<<"specialization: unsigned char --> float"<::max(); values_.push_back(rhs_v_0_1); } } // specialization: uint16_t --> float template<> template<> void CompressedVector::copyValues(const std::vector& rhs, double i_min, double i_max) { // std::cout<<"specialization: uint16_t --> float"<::max(); values_.push_back(rhs_v_0_1); } } // specialization: unsigned char --> double template<> template<> void CompressedVector::copyValues(const std::vector& rhs, double i_min, double i_max) { // std::cout<<"specialization: unsigned char --> double"<::max(); values_.push_back(rhs_v_0_1); } } // specialization: uint16_t --> double template<> template<> void CompressedVector::copyValues(const std::vector& rhs, double i_min, double i_max) { // std::cout<<"specialization: uint16_t --> double"<::max(); values_.push_back(rhs_v_0_1); } } } // namespace habdec