Commit 0de4e21d authored by Quentin Khan's avatar Quentin Khan

FGenericData: simplify code

Remove the `up` and `down` attribute pointers. They were used to be
able, in the future, to build a cell from separate parts. In the
meantime, they were made to point to local attributes `m_data` and
`l_data`.

Add setters and getters {set,get}{MultiopoleData,LocalExpansionData}.

Add setter and getters {set,get}Data{Up,Down} for leagecy purpose. These
should be deprecated and removed in the future.
parent 3e12cd1e
......@@ -3,41 +3,121 @@
#include "Components/FBasicCell.hpp"
template<class Multipole, class LocalExpansion>
class FGenericData : public FBasicCell {
public:
using multipole_t = Multipole;
using local_expansion_t = LocalExpansion;
private:
multipole_t m_data {};
local_expansion_t l_data {};
public:
multipole_t* up = &m_data;
local_expansion_t* down = &l_data;
bool hasMultipoleData() const noexcept {
return up != nullptr;
return true;
}
bool hasLocalExpansionData() const noexcept {
return up != nullptr;
return true;
}
multipole_t& getMultipoleData() noexcept {
return *up;
return m_data;
}
const multipole_t& getMultipoleData() const noexcept {
return *up;
return m_data;
}
void setMultipoleData(const multipole_t& value) noexcept(noexcept(m_data = value)) {
m_data = value;
}
void setMultipoleData(multipole_t&& value) noexcept(noexcept(m_data = std::move(value))) {
m_data = std::move(value);
}
local_expansion_t& getLocalExpansionData() noexcept {
return *down;
return l_data;
}
const local_expansion_t& getLocalExpansionData() const noexcept {
return *down;
return l_data;
}
void setLocalExpansionData(const local_expansion_t& value) noexcept(noexcept(l_data = value)) {
l_data = value;
}
void setLocalExpansionData(local_expansion_t&& value) noexcept(noexcept(l_data = std::move(value))) {
l_data = std::move(value);
}
multipole_t& getDataUp() noexcept {
return m_data;
}
const multipole_t& getDataUp() const noexcept {
return m_data;
}
void setDataUp(const multipole_t& value) noexcept(noexcept(m_data = value)) {
m_data = value;
}
void setDataUp(multipole_t&& value) noexcept(noexcept(m_data = std::move(value))) {
m_data = std::move(value);
}
local_expansion_t& getDataDown() noexcept {
return l_data;
}
const local_expansion_t& getDataDown() const noexcept {
return l_data;
}
void setDataDown(const local_expansion_t& value) noexcept(noexcept(l_data = value)) {
l_data = value;
}
void setDataDown(local_expansion_t&& value) noexcept(noexcept(l_data = std::move(value))) {
l_data = std::move(value);
}
/* TODO: Add getSavedSize if multipole and local_exp have it */
template<class T>
struct has_getSavedSize {
template<class U, class V = decltype(std::declval<U>().getSavedSize())>
static constexpr bool check(U*) {return true;}
static constexpr bool check(...) {return false;}
enum {value = check(static_cast<T*>(nullptr))};
};
template<class T,
typename std::enable_if<has_getSavedSize<T>::value, int>::type = 0
>
auto call_getSavedSize(const T& obj) const noexcept -> decltype(obj.getSavedSize()) {
return obj.getSavedSize();
}
template<class T,
typename std::enable_if<! has_getSavedSize<T>::value, int>::type = 0,
typename std::enable_if<std::is_trivially_copyable<T>::value, int>::type = 0
>
FSize call_getSavedSize(const T&) const noexcept {
return sizeof(T);
}
FSize getSavedSize() const noexcept {
return call_getSavedSize(m_data) + call_getSavedSize(l_data)
+ FBasicCell::getSavedSize();
}
FSize getSavedSizeUp() const noexcept {
return call_getSavedSize(m_data);
}
FSize getSavedSizeDown() const noexcept {
return call_getSavedSize(l_data);
}
/* TODO: Add save/restore if multipole and local_exp have it */
......@@ -45,23 +125,23 @@ public:
// to extend FAbstractSendable
///////////////////////////////////////////////////////
template <class BufferWriterClass>
void serializeUp(BufferWriterClass& buffer) const{
up->serialize(buffer);
void serializeUp(BufferWriterClass& buffer) const {
m_data.serialize(buffer);
}
template <class BufferReaderClass>
void deserializeUp(BufferReaderClass& buffer){
up->deserialize(buffer);
void deserializeUp(BufferReaderClass& buffer) {
m_data.deserialize(buffer);
}
template <class BufferWriterClass>
void serializeDown(BufferWriterClass& buffer) const{
down->serialize(buffer);
void serializeDown(BufferWriterClass& buffer) const {
l_data.serialize(buffer);
}
template <class BufferReaderClass>
void deserializeDown(BufferReaderClass& buffer){
down->deserialize(buffer);
void deserializeDown(BufferReaderClass& buffer) {
l_data.deserialize(buffer);
}
};
......
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