1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| #ifndef POINT_H_INCLUDED
#define POINT_H_INCLUDED
//==============================================================================
#include <array>
#include <cassert>
#include "Tag.h"
//==============================================================================
enum Side{ X = 0, Y = 1, Z = 2 };
//==============================================================================
template<typename Type, int dim, typename Tag>
class Point
{
//------------------------------------------------------------------------------
public:
Point(const Type x, const Type y, const Type z)
: point_({{x, y, z}})
{
if(std::is_same<Tag, SizeTag>::value) assert(x > 0 && y > 0 && z > 0);
static_assert(dim == 3, "3 parameters requested");
}
//--------------------------------------------------------------------------
Point(const Type x, const Type y)
: point_({{x, y}})
{
if(std::is_same<Tag, SizeTag>::value) assert(x > 0 && y > 0);
static_assert(dim == 2, "2 parameters requested");
}
//--------------------------------------------------------------------------
Point(const Type x)
: point_({{x}})
{
if(std::is_same<Tag, SizeTag>::value) assert(x > 0);
static_assert(dim == 1, "1 parameters requested");
}
//--------------------------------------------------------------------------
Type operator[](const Side side) const
{
assert(side < dim && side >= 0);
return point_[side];
}
//------------------------------------------------------------------------------
private:
std::array<Type, dim> point_;
};
//==============================================================================
#endif // POINT_H_INCLUDED |
Partager