DoorKeeper/include/doorkeeper/implem/vector.hpp

75 lines
2 KiB
C++
Raw Normal View History

2015-08-19 19:06:58 +00:00
/* Copyright 2015, Michele Santullo
* This file is part of DoorKeeper.
*
* DoorKeeper 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.
*
* DoorKeeper 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 DoorKeeper. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef id134A9223C9F7403B9BC600DCAC4875BC
#define id134A9223C9F7403B9BC600DCAC4875BC
#include "vectorwrapper/vectorwrapper.hpp"
#include <cstdint>
#include <cstddef>
#include <array>
#if defined(WITH_VECTOR_IOSTREAM)
# include <iostream>
#endif
namespace vwr {
2015-08-25 20:16:57 +00:00
template <typename T, std::size_t D>
struct VectorWrapperInfo<std::array<T, D>> {
enum {
dimensions = D
};
2015-08-25 20:16:57 +00:00
typedef T scalar_type;
typedef std::array<T, D> vector_type;
typedef std::array<T, D+1> higher_vector_type;
typedef std::array<T, D-1> lower_vector_type;
static scalar_type& get_at (std::size_t parIndex, vector_type& parVector) {
return parVector[parIndex];
}
};
2015-08-25 20:16:57 +00:00
template <typename T>
struct VectorWrapperInfo<std::array<T, 1>> {
enum {
dimensions = 1
};
2015-08-25 20:16:57 +00:00
typedef T scalar_type;
typedef std::array<T, 1> vector_type;
typedef std::array<T, 2> higher_vector_type;
static scalar_type& get_at (std::size_t, vector_type& parVector) {
return parVector[0];
}
};
#if defined(WITH_VECTOR_IOSTREAM)
template <typename V>
std::ostream& operator<< (std::ostream& parStream, const vwr::Vec<V>& parVec) {
const int dim = vwr::Vec<V>::dimensions;
parStream << '<';
for (int z = 0; z < dim - 1; ++z) {
parStream << parVec[z] << ", ";
}
parStream << parVec[dim - 1] << '>';
return parStream;
}
#endif
} //namespace vwr
#endif