/* Copyright 2014 Michele "King_DuckZ" Santullo This file is part of CloonelJump. CloonelJump 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. CloonelJump 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 CloonelJump. If not, see . */ namespace cloonel { ///------------------------------------------------------------------------- ///------------------------------------------------------------------------- template #if defined(DONT_GUESS_NOEXCEPT) Vector::Vector (T parValue) { #else Vector::Vector (T parValue) noexcept(noexcept(T()) && noexcept(parValue=parValue)) { #endif std::fill(m_mem, m_mem + S, parValue); } ///------------------------------------------------------------------------- ///------------------------------------------------------------------------- template template #if defined(DONT_GUESS_NOEXCEPT) Vector::Vector (const Vector& parOther) { #else Vector::Vector (const Vector& parOther) noexcept(noexcept(T()) && noexcept(const_cast(parOther.m_mem[0])=T())) { #endif std::copy(parOther.m_mem, parOther.m_mem + S, m_mem); } #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wconversion" ///------------------------------------------------------------------------- ///------------------------------------------------------------------------- template template const Vector& Vector::operator+= (const Vector& parOther) { for (uint32_t z = 0; z < S; ++z) { m_mem[z] += parOther.m_mem[z]; } return *this; } template template const Vector& Vector::operator-= (const Vector& parOther) { for (uint32_t z = 0; z < S; ++z) { m_mem[z] -= parOther.m_mem[z]; } return *this; } template template const Vector& Vector::operator*= (const Vector& parOther) { for (uint32_t z = 0; z < S; ++z) { m_mem[z] *= parOther.m_mem[z]; } return *this; } template template const Vector& Vector::operator/= (const Vector& parOther) { for (uint32_t z = 0; z < S; ++z) { m_mem[z] /= parOther.m_mem[z]; } return *this; } #pragma GCC diagnostic pop #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wconversion" ///------------------------------------------------------------------------- ///------------------------------------------------------------------------- template template const Vector& Vector::operator+= (U parOther) { for (uint32_t z = 0; z < S; ++z) { m_mem[z] += parOther; } return *this; } template template const Vector& Vector::operator-= (U parOther) { for (uint32_t z = 0; z < S; ++z) { m_mem[z] -= parOther; } return *this; } template template const Vector& Vector::operator*= (U parOther) { for (uint32_t z = 0; z < S; ++z) { m_mem[z] *= parOther; } return *this; } template template const Vector& Vector::operator/= (U parOther) { for (uint32_t z = 0; z < S; ++z) { m_mem[z] /= parOther; } return *this; } #pragma GCC diagnostic pop ///------------------------------------------------------------------------- ///------------------------------------------------------------------------- template inline Vector::type, S> operator+ (const Vector& parA, const Vector& parB) { return implem::DoOperation, S>::do_sum(parA, parB); } template inline Vector::type, S> operator- (const Vector& parA, const Vector& parB) { return implem::DoOperation, S>::do_sub(parA, parB); } template inline Vector::type, S> operator* (const Vector& parA, const Vector& parB) { return implem::DoOperation, S>::do_mul(parA, parB); } template inline Vector::type, S> operator/ (const Vector& parA, const Vector& parB) { return implem::DoOperation, S>::do_div(parA, parB); } ///------------------------------------------------------------------------- ///------------------------------------------------------------------------- template Vector::type, S> operator+ (U parA, const Vector& parB) { return parB + parA; } template Vector::type, S> operator- (U parA, const Vector& parB) { return Vector(parA) - parB; } template Vector::type, S> operator* (U parA, const Vector& parB) { return parB * parA; } template Vector::type, S> operator/ (U parA, const Vector& parB) { return Vector(parA) / parB; } template Vector::type, S> operator+ (const Vector& parA, U parB) { typedef typename std::common_type::type RetType; Vector retVal; for (uint32_t z = 0; z < S; ++z) { retVal[z] = parA[z] + parB; } return retVal; } template Vector::type, S> operator- (const Vector& parA, U parB) { typedef typename std::common_type::type RetType; Vector retVal; for (uint32_t z = 0; z < S; ++z) { retVal[z] = parA[z] - parB; } return retVal; } template Vector::type, S> operator* (const Vector& parA, U parB) { typedef typename std::common_type::type RetType; Vector retVal; for (uint32_t z = 0; z < S; ++z) { retVal[z] = parA[z] * parB; } return retVal; } template Vector::type, S> operator/ (const Vector& parA, U parB) { typedef typename std::common_type::type RetType; Vector retVal; for (uint32_t z = 0; z < S; ++z) { retVal[z] = parA[z] / parB; } return retVal; } ///-------------------------------------------------------------------------- ///-------------------------------------------------------------------------- template inline bool operator< (const Vector& parA, const Vector& parB) { bool retVal = false; for (uint32_t z = 0; z < S; ++z) { retVal |= static_cast(parA[z] < parB[z]); } return retVal; } template inline bool operator> (const Vector& parA, const Vector& parB) { bool retVal = false; for (uint32_t z = 0; z < S; ++z) { retVal |= static_cast(parA[z] > parB[z]); } return retVal; } template inline bool operator<= (const Vector& parA, const Vector& parB) { bool retVal = false; for (uint32_t z = 0; z < S; ++z) { retVal |= static_cast(parA[z] <= parB[z]); } return retVal; } template inline bool operator>= (const Vector& parA, const Vector& parB) { bool retVal = false; for (uint32_t z = 0; z < S; ++z) { retVal |= static_cast(parA[z] >= parB[z]); } return retVal; } template inline bool operator== (const Vector& parA, const Vector& parB) { bool retVal = true; for (uint32_t z = 0; z < S; ++z) { retVal &= static_cast(parA[z] == parB[z]); } return retVal; } template inline bool operator!= (const Vector& parA, const Vector& parB) { return not operator==(parA, parB); } template Vector operator- (Vector parOperand) { for (uint32_t z = 0; z < S; ++z) { parOperand[z] = -parOperand[z]; } return parOperand; } } //namespace cloonel