Skip to content
Snippets Groups Projects
Commit 11650a65 authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

Add new constructor for SubItemValuePerItem using an Array of values

Also make some clean-up and update tests and add a bunch of missing
qualifiers to functions
parent 2056ed42
No related branches found
No related tags found
1 merge request!133Simplify access functions to the number of items
......@@ -48,7 +48,7 @@ class SubItemValuePerItem
friend SubItemValuePerItem<std::remove_const_t<DataType>, ItemOfItem, ConnectivityWeakPtr>;
public:
friend PUGS_INLINE SubItemValuePerItem<std::remove_const_t<DataType>, ItemOfItem, ConnectivityPtr>
[[nodiscard]] friend PUGS_INLINE SubItemValuePerItem<std::remove_const_t<DataType>, ItemOfItem, ConnectivityPtr>
copy(const SubItemValuePerItem<DataType, ItemOfItem, ConnectivityPtr>& source)
{
SubItemValuePerItem<std::remove_const_t<DataType>, ItemOfItem, ConnectivityPtr> image;
......@@ -59,15 +59,13 @@ class SubItemValuePerItem
return image;
}
PUGS_INLINE
bool
[[nodiscard]] PUGS_INLINE bool
isBuilt() const noexcept
{
return m_connectivity_ptr.use_count() != 0;
}
PUGS_INLINE
std::shared_ptr<const IConnectivity>
[[nodiscard]] PUGS_INLINE std::shared_ptr<const IConnectivity>
connectivity_ptr() const noexcept
{
if constexpr (std::is_same_v<ConnectivityPtr, ConnectivitySharedPtr>) {
......@@ -78,18 +76,19 @@ class SubItemValuePerItem
}
template <typename IndexType, typename SubIndexType>
PUGS_FORCEINLINE DataType&
[[nodiscard]] PUGS_INLINE DataType&
operator()(IndexType item_id, SubIndexType i) const noexcept(NO_ASSERT)
{
static_assert(std::is_same_v<IndexType, ItemId>, "first index must be of the correct ItemId type");
static_assert(std::is_integral_v<SubIndexType>, "second index must be an integral type");
Assert(this->isBuilt());
Assert(i + m_row_map[size_t{item_id}] < m_row_map[size_t{item_id} + 1]);
Assert(this->isBuilt(), "SubItemValuePerItem is not built");
Assert(item_id < this->numberOfItems(), "invalid item_id");
Assert(i + m_row_map[size_t{item_id}] < m_row_map[size_t{item_id} + 1], "invalid index");
return m_values[m_row_map[size_t{item_id}] + i];
}
template <ItemType item_t>
typename Array<DataType>::UnsafeArrayView
[[nodiscard]] PUGS_INLINE typename Array<DataType>::UnsafeArrayView
operator[](const ItemIdT<item_t>& item_id) const noexcept(NO_ASSERT)
{
static_assert(item_t == item_type, "invalid ItemId type");
......@@ -97,39 +96,37 @@ class SubItemValuePerItem
}
template <typename ArrayIndexType>
DataType&
[[nodiscard]] PUGS_INLINE DataType&
operator[](const ArrayIndexType& i) const noexcept(NO_ASSERT)
{
static_assert(std::is_integral_v<ArrayIndexType>, "index must be an integral type");
Assert(this->isBuilt());
Assert(static_cast<size_t>(i) < m_values.size());
Assert(this->isBuilt(), "SubItemValuePerItem is not built");
Assert(static_cast<size_t>(i) < m_values.size(), "invalid index");
return m_values[i];
}
PUGS_INLINE
size_t
[[nodiscard]] PUGS_INLINE size_t
numberOfValues() const noexcept(NO_ASSERT)
{
Assert(this->isBuilt());
Assert(this->isBuilt(), "SubItemValuePerItem is not built");
return m_values.size();
}
PUGS_INLINE
size_t
[[nodiscard]] PUGS_INLINE size_t
numberOfItems() const noexcept(NO_ASSERT)
{
Assert(this->isBuilt());
Assert(m_row_map.size() > 0);
Assert(this->isBuilt(), "SubItemValuePerItem is not built");
Assert(m_row_map.size() > 0, "invalid row map");
return m_row_map.size() - 1;
}
template <typename IndexType>
PUGS_INLINE size_t
[[nodiscard]] PUGS_INLINE size_t
numberOfSubValues(IndexType item_id) const noexcept(NO_ASSERT)
{
static_assert(std::is_same_v<IndexType, ItemId>, "index must be an ItemId");
Assert(this->isBuilt());
Assert(item_id < this->numberOfItems());
Assert(this->isBuilt(), "SubItemValuePerItem is not built");
Assert(item_id < this->numberOfItems(), "invalid item_id");
return m_row_map[size_t{item_id} + 1] - m_row_map[size_t{item_id}];
}
......@@ -142,12 +139,12 @@ class SubItemValuePerItem
}
template <typename IndexType>
PUGS_INLINE typename Array<DataType>::UnsafeArrayView
[[nodiscard]] PUGS_INLINE typename Array<DataType>::UnsafeArrayView
itemArray(const IndexType& item_id) const noexcept(NO_ASSERT)
{
static_assert(std::is_same_v<IndexType, ItemId>, "index must be an ItemId");
Assert(this->isBuilt());
Assert(item_id < this->numberOfItems());
Assert(this->isBuilt(), "SubItemValuePerItem is not built");
Assert(item_id < this->numberOfItems(), "invalid item_id");
const auto& item_begin = m_row_map[size_t{item_id}];
const auto& item_end = m_row_map[size_t{item_id} + 1];
return subArrayView(m_values, item_begin, item_end - item_begin);
......@@ -198,6 +195,14 @@ class SubItemValuePerItem
m_values = Array<DataType>(connectivity_matrix.numberOfValues());
}
SubItemValuePerItem(const IConnectivity& connectivity, const Array<DataType>& values) noexcept(NO_ASSERT)
: m_connectivity_ptr{connectivity.shared_ptr()}, m_values{values}
{
Assert(m_values.size() == connectivity.getMatrix(item_type, sub_item_type).numberOfValues(),
"invalid size of provided values");
m_row_map = connectivity.getMatrix(item_type, sub_item_type).rowsMap();
}
~SubItemValuePerItem() = default;
};
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment