DoorKeeper/include/doorkeeper/implem/vector.hpp

76 lines
2.2 KiB
C++

/* 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 "doorkeeper/implem/configuration.h"
#include "vectorwrapper/vectorwrapper.hpp"
#include <cstdint>
#include <cstddef>
#include <array>
#if defined(WITH_VECTOR_IOSTREAM)
# include <iostream>
#endif
namespace vwr {
template <std::size_t D>
struct VectorWrapperInfo<std::array<dk::CoordinateScalarType, D>> {
enum {
dimensions = D
};
typedef dk::CoordinateScalarType scalar_type;
typedef std::array<dk::CoordinateScalarType, D> vector_type;
typedef std::array<dk::CoordinateScalarType, D+1> higher_vector_type;
typedef std::array<dk::CoordinateScalarType, D-1> lower_vector_type;
static scalar_type& get_at (std::size_t parIndex, vector_type& parVector) {
return parVector[parIndex];
}
};
template <>
struct VectorWrapperInfo<std::array<dk::CoordinateScalarType, 1>> {
enum {
dimensions = 1
};
typedef dk::CoordinateScalarType scalar_type;
typedef std::array<dk::CoordinateScalarType, 1> vector_type;
typedef std::array<dk::CoordinateScalarType, 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