/*
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 .
*/
#ifndef idid0528646832E04CF08E9785B66CFE0BD1
#define idid0528646832E04CF08E9785B66CFE0BD1
#include "compatibility.h"
#include
#include
#include
#include
#include
#if !defined(NDEBUG)
#include
#endif
#if defined(__INTEL_COMPILER)
# define DONT_GUESS_NOEXCEPT
#endif
namespace cloonel {
template
class Vector {
template friend class Vector;
public:
typedef T value_type;
#if defined(DONT_GUESS_NOEXCEPT)
Vector ( void ) = default;
explicit Vector ( T parValue );
template explicit Vector ( const Vector& parOther );
#else
Vector ( void ) noexcept(noexcept(T())) = default;
explicit Vector ( T parValue ) noexcept(noexcept(T()) && noexcept(parValue=parValue));
template explicit Vector ( const Vector& parOther ) noexcept(noexcept(T()) && noexcept(const_cast(parOther.m_mem[0])=T()));
#endif
template > Vector ( T parX, T parY ) noexcept : m_mem {parX, parY} {}
template > Vector ( T parX, T parY, T parZ ) noexcept : m_mem {parX, parY, parZ} {}
template > Vector ( T parX, T parY, T parZ, T parW ) noexcept : m_mem {parX, parY, parZ, parW} {}
~Vector ( void ) noexcept = default;
enum {
Dimension = S
};
template = S> > T& x ( void ) { return m_mem[0]; }
template = S> > const T& x ( void ) const { return m_mem[0]; }
template = 2 and 4 >= S> > T& y ( void ) { return m_mem[1]; }
template = 2 and 4 >= S> > const T& y ( void ) const { return m_mem[1]; }
template = 3 and 4 >= S> > T& z ( void ) { return m_mem[2]; }
template = 3 and 4 >= S> > const T& z ( void ) const { return m_mem[2]; }
template = 4 and 4 >= S> > T& w ( void ) { return m_mem[3]; }
template = 4 and 4 >= S> > const T& w ( void ) const { return m_mem[3]; }
template const Vector& operator+= ( const Vector& parOther );
template const Vector& operator-= ( const Vector& parOther );
template const Vector& operator*= ( const Vector& parOther );
template const Vector& operator/= ( const Vector& parOther );
template const Vector& operator+= ( U parOther );
template const Vector& operator-= ( U parOther );
template const Vector& operator*= ( U parOther );
template const Vector& operator/= ( U parOther );
T& operator[] ( uint32_t parIndex ) { assert(parIndex < S); return m_mem[parIndex]; }
const T& operator[] ( uint32_t parIndex ) const { assert(parIndex < S); return m_mem[parIndex]; }
private:
T m_mem[S];
};
template
Vector::type, S> operator+ ( const Vector& parA, const Vector& parB ) a_pure;
template
Vector::type, S> operator- ( const Vector& parA, const Vector& parB ) a_pure;
template
Vector::type, S> operator* ( const Vector& parA, const Vector& parB ) a_pure;
template
Vector::type, S> operator/ ( const Vector& parA, const Vector& parB ) a_pure;
template ::value>::type>
Vector::type, S> operator+ ( U parA, const Vector& parB ) a_pure;
template ::value>::type>
Vector::type, S> operator- ( U parA, const Vector& parB ) a_pure;
template ::value>::type>
Vector::type, S> operator* ( U parA, const Vector& parB ) a_pure;
template ::value>::type>
Vector::type, S> operator/ ( U parA, const Vector& parB ) a_pure;
template ::value>::type>
Vector::type, S> operator+ ( const Vector& parA, U parB ) a_pure;
template ::value>::type>
Vector::type, S> operator- ( const Vector& parA, U parB ) a_pure;
template ::value>::type>
Vector::type, S> operator* ( const Vector& parA, U parB ) a_pure;
template ::value>::type>
Vector::type, S> operator/ ( const Vector& parA, U parB ) a_pure;
template
bool operator< ( const Vector& parA, const Vector& parB ) a_pure;
template
bool operator> ( const Vector& parA, const Vector& parB ) a_pure;
template
bool operator<= ( const Vector& parA, const Vector& parB ) a_pure;
template
bool operator>= ( const Vector& parA, const Vector& parB ) a_pure;
template
bool operator== ( const Vector& parA, const Vector& parB ) a_pure;
template
bool operator!= ( const Vector& parA, const Vector& parB ) a_pure;
template
Vector operator- ( Vector parOperand ) a_pure;
typedef Vector float2;
typedef Vector ushort2;
#if !defined(NDEBUG)
typedef Vector short2;
#endif
typedef Vector int2;
#if !defined(NDEBUG)
template
std::ostream& operator<< ( std::ostream& parStream, const Vector& parVector ) {
parStream << "<";
for (uint32_t z = 0; z < S - 1; ++z) {
parStream << parVector[z] << ",";
}
parStream << parVector[S - 1] << ">";
return parStream;
}
#endif
namespace implem {
template
struct CategorizeTypes {
typedef typename std::common_type::type CommonType;
typedef typename std::conditional::value, U, T>::type OtherType;
};
template ::value>
struct DoOperation {
static Vector do_mul ( Vector parLho, const Vector& parRho ) {
parLho *= parRho;
return parLho;
}
static Vector do_div ( Vector parLho, const Vector& parRho ) {
parLho /= parRho;
return parLho;
}
static Vector do_sum ( Vector parLho, const Vector& parRho ) {
parLho += parRho;
return parLho;
}
static Vector do_sub ( Vector parLho, const Vector& parRho ) {
parLho -= parRho;
return parLho;
}
};
template
struct DoOperation {
static Vector do_mul ( Vector parLho, const Vector& parRho ) {
parLho *= parRho;
return parLho;
}
static Vector do_mul ( const Vector& parLho, const Vector& parRho ) {
Vector ret(parLho);
ret *= parRho;
return ret;
}
static Vector do_div ( Vector parLho, const Vector& parRho ) {
parLho /= parRho;
return parLho;
}
static Vector do_div ( const Vector& parLho, const Vector& parRho ) {
Vector ret(parLho);
ret /= parRho;
return ret;
}
static Vector do_sum ( Vector parLho, const Vector& parRho ) {
parLho += parRho;
return parLho;
}
static Vector do_sum ( const Vector& parLho, const Vector& parRho ) {
Vector ret(parLho);
ret += parRho;
return ret;
}
static Vector do_sub ( Vector parLho, const Vector& parRho ) {
parLho -= parRho;
return parLho;
}
static Vector do_sub ( const Vector& parLho, const Vector& parRho ) {
Vector ret(parLho);
ret -= parRho;
return ret;
}
};
} //namespace implem
} //namespace cloonel
#include "vector.inl"
#if defined(DONT_GUESS_NOEXCEPT)
#undef DONT_GUESS_NOEXCEPT
#endif
#endif