Commit 2bd669db authored by Quentin Khan's avatar Quentin Khan
Browse files

FBasicParticle: add documentation

parent 15ea9a26
/**
* \brief Implementation file of FBasicParticle class
* \author Quentin Khan
*
* \file
*/
#ifndef FBASIC_PARTICLE_HPP
#define FBASIC_PARTICLE_HPP
......@@ -6,7 +12,53 @@
#include "Utils/FPoint.hpp"
#include "Utils/FTypePack.hpp"
/**
* \brief Multi-purpose particle implementation
*
* This template implementation of a particle allows simple reuse for several
* use cases. The aim it to provide an interface that is compatible with the
* rest of ScalFMM. It is mainly intended to be used as an interface for the
* particle containers.
*
* The Types parameter pack can accept any type that is to be considered as a
* particle attribute. You can also specify scalfmm::pack type to factorise
* several types.
*
* In the following example, the two specialisations of the class will give the
* same final structure.
*
* ```
* using FReal = double;
* static constexpr std::size_t Dim = 3;
*
* FBasicParticle<FReal, Dim, int, float, float, float, float>;
* FBasicParticle<FReal, Dim, int, scalfmm::pack<4, float> >;
* ```
*
* The base of these two classes is
* ```
* std::tuple<double, double, double, int, float, float, float, float>;
* ```
*
* \warning Although the classes will have the same final layout, C++ considers
* these two classes to be different !
*
* ##### Example
*
* ```
* // Define a 3D particle with an int attribute
* using Particle = FBasicParticle<double, 3, int>;
*
* Particle p;
* p.get<>
* ```
*
*
* \tparam FReal Floating point type
* \tparam Dim Space dimension count
* \tparam Types Attributes type list
*
*/
template<typename _FReal, std::size_t _Dim = 3, typename... Types>
class FBasicParticle : public scalfmm::pack_expand_tuple< scalfmm::pack<_Dim, _FReal>, Types... >{
......@@ -15,6 +67,7 @@ public:
using data_t = scalfmm::
pack_expand_tuple< scalfmm::pack<_Dim, _FReal>, Types... >;
/// Expanded the Types list
using types_tuple_t = scalfmm::
pack_expand_tuple< Types... >;
......@@ -30,7 +83,7 @@ public:
* size + the dimension
*/
template<typename... Ts>
constexpr static bool correct_size() {
constexpr static bool correct_attribute_list_size() {
return std::tuple_size<data_t>::value >= sizeof...(Ts) + Dim;
}
......@@ -69,7 +122,7 @@ public:
* that case the missing ones are zero constructed.
*/
template<typename... Ts,
sfinae_check<correct_size<Ts...>()> = 0>
sfinae_check<correct_attribute_list_size<Ts...>()> = 0>
FBasicParticle(const position_t& pos, Ts&&... ts) :
FBasicParticle(std::make_index_sequence<Dim>(),
std::make_index_sequence<std::tuple_size<data_t>::value-sizeof...(ts)-Dim>(),
......@@ -87,7 +140,7 @@ public:
* \tparam Ts attribute parameter pack
*/
template<typename... Ts,
sfinae_check<!correct_size<Ts...>()> = 0>
sfinae_check<!correct_attribute_list_size<Ts...>()> = 0>
FBasicParticle(const position_t&, Ts&&...)
{
static_assert(!sizeof...(Ts), "To many attributes given to particle constructor");
......@@ -99,7 +152,8 @@ public:
data_t(ts)
{}
/** \brief Position getter
/**
* \brief Position getter
*
* The position is stored in the #_data tuple, to extract it we need to
* recreate a position_t object. This is done by the position_impl() method.
......@@ -114,6 +168,10 @@ public:
return setPosition_impl(pos, std::make_index_sequence<Dim>());
}
/**
* \brief Get a tuple filled with copies of the attributes
*/
types_tuple_t attributes() const {
return attributes_impl(
std::make_index_sequence<std::tuple_size<types_tuple_t>::value>(),
......@@ -121,10 +179,16 @@ public:
);
}
/**
* \brief Convert particle to a tuple
*/
data_t& data() {
return *this;
}
/**
* \brief Convert particle to a tuple
*/
const data_t& data() const {
return *this;
}
......@@ -134,7 +198,6 @@ public:
return std::get<I>(this->data());
}
template<std::size_t I>
auto get() const -> decltype(std::get<I>(this->data())) {
return std::get<I>(this->data());
......@@ -159,11 +222,25 @@ private:
//static_assert(sizeof...(Ts) == NbAttributes, "Parameter count is incorrect");
}
/**
* \brief #position method implementation
*
* \tparam Is Index sequence of the position elements in the tuple, deduced
* using arguments
*/
template<std::size_t... Is>
position_t position_impl(std::index_sequence<Is...>) const{
return position_t(std::get<Is>(this->data())...);
}
/**
* \brief #setPosition method implementation
*
* \tparam Is Index sequence of the position elements in the tuple, deduced
* using arguments
*
* \param pos new position
*/
template<std::size_t... Is>
void setPosition_impl(const position_t& pos, std::index_sequence<Is...>) {
auto l = {std::get<Is>(this->data()) = pos[Is] ...};
......@@ -171,6 +248,14 @@ private:
}
/**
* \brief #attributes method implementation
*
* \tparam Is Index sequence of the attributes in the tuple, deduced using
* arguments
*
* \param pos new position
*/
template<std::size_t... Is, typename... Attributes>
std::tuple<Attributes...> attributes_impl(std::index_sequence<Is...>,
std::tuple<Attributes...>)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment