/**
This file is a part of the rexy/r0nk/atlas project
Copyright (C) 2020 rexy712
This program 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.
This program 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 this program. If not, see .
*/
#ifndef REXY_DETAIL_MATRIX_HPP
#define REXY_DETAIL_MATRIX_HPP
#include //size_t
#include //integer_sequence
namespace math::detail{
template
struct gen_id_tup {
using tup = typename gen_id_tup::tup;
};
template
struct gen_id_tup {
using tup = typename gen_id_tup::tup;
};
template
struct gen_id_tup {
using tup = typename gen_id_tup::tup;
};
template
struct gen_id_tup {
using tup = std::integer_sequence;
};
template
struct gen_zero_tup {
using tup = typename gen_zero_tup::tup;
};
template
struct gen_zero_tup<0,Args...> {
using tup = std::integer_sequence;
};
template
struct id_initialization_matrix {
using tuple = typename gen_id_tup::tup;
};
template
struct default_initialization_matrix {
using tuple = typename gen_zero_tup::tup;
};
template
struct default_initialization_matrix {
using tuple = typename id_initialization_matrix::tuple;
};
template
class mat_ref_obj
{
public:
using size_type = size_t;
protected:
T* m_data = nullptr;
public:
constexpr mat_ref_obj(T* d, size_type i);
constexpr T& operator[](size_type i);
constexpr const T& operator[](size_type i)const;
};
template
class matrix_base
{
static_assert(W > 0, "Cannot have 0 columns matrix");
static_assert(H > 0, "Cannot have 0 rows matrix");
public:
using value_type = T;
using size_type = size_t;
using pointer = value_type*;
using const_pointer = const value_type*;
using reference = value_type&;
using const_reference = const value_type&;
static constexpr size_type Columns = W;
static constexpr size_type Rows = H;
protected:
value_type m_data[W*H];
protected:
template
constexpr matrix_base(std::integer_sequence);
public:
//Default construct as identity when square, zero otherwise
constexpr matrix_base();
//Range initializing constructors
constexpr explicit matrix_base(detail::zero_initialize_t);
constexpr explicit matrix_base(detail::no_initialize_t);
template
constexpr explicit matrix_base(detail::id_initialize_t);
//Value initializing constructors
constexpr explicit matrix_base(value_type v);
template
constexpr explicit matrix_base(Args&&... args);
//Copying constructors
constexpr matrix_base(const matrix_base&) = default;
constexpr matrix_base(matrix_base&&) = default;
template
constexpr matrix_base(const matrix_base& m);
~matrix_base() = default;
//Assignement
template
constexpr matrix_base& operator=(const matrix_base& m);
constexpr matrix_base& operator=(const matrix_base&) = default;
constexpr matrix_base& operator=(matrix_base&&) = default;
//Getters/Setters
constexpr auto operator[](size_type x);
constexpr auto operator[](size_type x)const;
constexpr reference get(size_type x, size_type y);
constexpr const_reference get(size_type x, size_type y)const;
constexpr reference get(size_type i);
constexpr const_reference get(size_type i)const;
constexpr size_type columns()const;
constexpr size_type rows()const;
constexpr size_type size()const;
constexpr pointer raw();
constexpr const_pointer raw()const;
constexpr operator pointer();
constexpr operator const_pointer()const;
};
}
#include "matrix.tpp"
#endif