OGS
MeshLib::PropertyVector< T * > Class Template Reference

Detailed Description

template<typename T>
class MeshLib::PropertyVector< T * >

Class template PropertyVector is a std::vector with template parameter T, where T is a pointer type. The behaviour has changed for the constructor, destructor and the operator[]. The user has to provide the size and an item to group mapping for construction. The destructor takes care to delete the entries of the vector. The operator[] uses an item-to-group property map to access the correct property.

Template Parameters
Tpointer type, the type the type points to is typical a scalar, a vector or a matrix type

Definition at line 214 of file PropertyVector.h.

#include <PropertyVector.h>

Inheritance diagram for MeshLib::PropertyVector< T * >:
[legend]
Collaboration diagram for MeshLib::PropertyVector< T * >:
[legend]

Public Types

using value_type

Public Member Functions

 ~PropertyVector () override
 Destructor ensures the deletion of the heap-constructed objects.
T *const & operator[] (std::size_t id) const
T *& operator[] (std::size_t id)
void initPropertyValue (std::size_t group_id, T const &value)
void initPropertyValue (std::size_t group_id, std::vector< T > const &values)
std::size_t getNumberOfTuples () const
std::size_t size () const
PropertyVectorBaseclone (std::vector< std::size_t > const &exclude_positions) const override
T const & getComponent (std::size_t tuple_index, int component) const
 Returns the value for the given component stored in the given tuple.
constexpr std::ptrdiff_t ssize () const
constexpr const T ** data () const
constexpr T ** begin ()
constexpr T ** end ()
constexpr const T ** cbegin () const
constexpr const T ** cend () const
constexpr void resize (std::size_t const size)
constexpr void assign (R &&r)
constexpr void push_back (const T *&value)
constexpr void clear ()
constexpr bool empty () const
Public Member Functions inherited from MeshLib::PropertyVectorBase
virtual ~PropertyVectorBase ()=default
MeshItemType getMeshItemType () const
std::string const & getPropertyName () const
int getNumberOfGlobalComponents () const

Protected Member Functions

 PropertyVector (std::size_t n_prop_groups, std::vector< std::size_t > item2group_mapping, std::string const &property_name, MeshItemType mesh_item_type, std::size_t n_components)
 The constructor taking meta information for the data.
Protected Member Functions inherited from MeshLib::PropertyVectorBase
 PropertyVectorBase (std::string property_name, MeshItemType mesh_item_type, std::size_t n_components)

Private Member Functions

T * at (std::size_t)

Private Attributes

std::vector< std::size_t > _item2group_mapping
std::vector< T * > _values
std::vector< T * > data_

Friends

class Properties

Additional Inherited Members

Public Attributes inherited from MeshLib::PropertyVectorBase
bool is_for_output = true
Protected Attributes inherited from MeshLib::PropertyVectorBase
int const _n_components
MeshItemType const _mesh_item_type
std::string const _property_name

Member Typedef Documentation

◆ value_type

using MeshLib::PropertyVector< T * >::value_type

Definition at line 62 of file PropertyVector.h.

Constructor & Destructor Documentation

◆ ~PropertyVector()

template<typename T>
MeshLib::PropertyVector< T * >::~PropertyVector ( )
inlineoverride

Destructor ensures the deletion of the heap-constructed objects.

Definition at line 220 of file PropertyVector.h.

221 {
222 for (auto v : _values)
223 {
224 delete[] v;
225 }
226 }

References _values.

◆ PropertyVector()

template<typename T>
MeshLib::PropertyVector< T * >::PropertyVector ( std::size_t n_prop_groups,
std::vector< std::size_t > item2group_mapping,
std::string const & property_name,
MeshItemType mesh_item_type,
std::size_t n_components )
inlineprotected

The constructor taking meta information for the data.

Parameters
n_prop_groupsnumber of different property values
item2group_mappingClass Mesh has a mapping from the mesh items (Node or Element) to an index (position in the data structure). The vector item2group_mapping must have the same number of entries as the above mapping and the values have to be in the range \([0, \text{n\_prop\_groups})\).
property_namea string describing the property
mesh_item_typethe values of the property are either assigned to nodes or cells (see enumeration MeshItemType)
n_componentsthe number of elements of a tuple

Definition at line 319 of file PropertyVector.h.

328 {
329 }
PropertyVectorBase(std::string property_name, MeshItemType mesh_item_type, std::size_t n_components)
std::vector< std::size_t > _item2group_mapping

References MeshLib::PropertyVectorBase::PropertyVectorBase(), _item2group_mapping, and _values.

Referenced by clone().

Member Function Documentation

◆ assign()

void MeshLib::PropertyVector< T * >::assign ( R && r)
inlineconstexpr

Definition at line 146 of file PropertyVector.h.

147 {
148#if __cpp_lib_containers_ranges >= 202202L
149 data_.assign_range(r);
150#else
151 if constexpr (ranges::common_range<R>)
152 {
153 data_.assign(r.begin(), r.end());
154 }
155 else
156 {
159 }
160#endif
161 }
constexpr PROP_VAL_TYPE * begin()
constexpr PROP_VAL_TYPE * end()

◆ at()

template<typename T>
T * MeshLib::PropertyVector< T * >::at ( std::size_t )
private

◆ begin()

T * * MeshLib::PropertyVector< T * >::begin ( )
inlineconstexpr

Definition at line 107 of file PropertyVector.h.

107{ return data_.data(); }

◆ cbegin()

const T * * MeshLib::PropertyVector< T * >::cbegin ( ) const
inlineconstexpr

Definition at line 110 of file PropertyVector.h.

110{ return data_.data(); }

◆ cend()

const T * * MeshLib::PropertyVector< T * >::cend ( ) const
inlineconstexpr

Definition at line 111 of file PropertyVector.h.

112 {
113 return data_.data() + data_.size();
114 }

◆ clear()

void MeshLib::PropertyVector< T * >::clear ( )
inlineconstexpr

Definition at line 168 of file PropertyVector.h.

168{ data_.clear(); }

◆ clone()

template<typename T>
PropertyVectorBase * MeshLib::PropertyVector< T * >::clone ( std::vector< std::size_t > const & exclude_positions) const
inlineoverridevirtual

◆ data()

const T * * MeshLib::PropertyVector< T * >::data ( ) const
inlineconstexpr

Definition at line 104 of file PropertyVector.h.

104{ return data_.data(); }

◆ empty()

bool MeshLib::PropertyVector< T * >::empty ( ) const
inlineconstexpr

Definition at line 169 of file PropertyVector.h.

169{ return data_.empty(); }

◆ end()

T * * MeshLib::PropertyVector< T * >::end ( )
inlineconstexpr

Definition at line 108 of file PropertyVector.h.

108{ return data_.data() + data_.size(); }

◆ getComponent()

template<typename T>
T const & MeshLib::PropertyVector< T * >::getComponent ( std::size_t tuple_index,
int component ) const
inline

Returns the value for the given component stored in the given tuple.

Definition at line 291 of file PropertyVector.h.

292 {
295
296 const double* p = this->operator[](tuple_index);
297 if (p == nullptr)
298 {
299 OGS_FATAL(
300 "No data found in the property vector {:s} "
301 "for the tuple index {:d} and component {:d}",
303 }
304 return p[component];
305 }
#define OGS_FATAL(...)
Definition Error.h:26
std::string const & getPropertyName() const
T *const & operator[](std::size_t id) const
std::size_t getNumberOfTuples() const

References MeshLib::PropertyVectorBase::_n_components, getNumberOfTuples(), MeshLib::PropertyVectorBase::getPropertyName(), OGS_FATAL, and operator[]().

◆ getNumberOfTuples()

template<typename T>
std::size_t MeshLib::PropertyVector< T * >::getNumberOfTuples ( ) const
inline

Definition at line 267 of file PropertyVector.h.

267{ return _item2group_mapping.size(); }

References _item2group_mapping.

Referenced by getComponent(), and size().

◆ initPropertyValue() [1/2]

template<typename T>
void MeshLib::PropertyVector< T * >::initPropertyValue ( std::size_t group_id,
std::vector< T > const & values )
inline

Definition at line 250 of file PropertyVector.h.

251 {
252 if (_n_components != static_cast<int>(values.size()))
253 {
254 OGS_FATAL(
255 "The size of provided values in initPropertyValue() is "
256 "not same as the number of components in PropertyVector<T*>");
257 }
258
259 auto* p = new T[values.size()];
260 for (unsigned i = 0; i < values.size(); i++)
261 {
262 p[i] = values[i];
263 }
264 _values[group_id] = p;
265 }
constexpr std::size_t size() const

References MeshLib::PropertyVectorBase::_n_components, _values, and OGS_FATAL.

◆ initPropertyValue() [2/2]

template<typename T>
void MeshLib::PropertyVector< T * >::initPropertyValue ( std::size_t group_id,
T const & value )
inline

Definition at line 237 of file PropertyVector.h.

238 {
239 if (_n_components != 1)
240 {
241 OGS_FATAL(
242 "Single-component version of initPropertyValue() is called "
243 "for a multi-components PropertyVector<T*>");
244 }
245 auto* p = new T[1];
246 p[0] = value;
247 _values[group_id] = p;
248 }

References MeshLib::PropertyVectorBase::_n_components, _values, and OGS_FATAL.

◆ operator[]() [1/2]

template<typename T>
T *& MeshLib::PropertyVector< T * >::operator[] ( std::size_t id)
inline

Definition at line 235 of file PropertyVector.h.

235{ return _values[_item2group_mapping[id]]; }

References _item2group_mapping, and _values.

◆ operator[]() [2/2]

template<typename T>
T *const & MeshLib::PropertyVector< T * >::operator[] ( std::size_t id) const
inline

The operator[] uses the item to group property map to access to the correct property value/object.

Definition at line 230 of file PropertyVector.h.

231 {
233 }

References _item2group_mapping, and _values.

Referenced by getComponent().

◆ push_back()

void MeshLib::PropertyVector< T * >::push_back ( const T * & value)
inlineconstexpr

Definition at line 163 of file PropertyVector.h.

164 {
165 data_.push_back(value);
166 }

◆ resize()

void MeshLib::PropertyVector< T * >::resize ( std::size_t const size)
inlineconstexpr

Definition at line 136 of file PropertyVector.h.

136{ data_.resize(size); }

◆ size()

template<typename T>
std::size_t MeshLib::PropertyVector< T * >::size ( ) const
inline

Method returns the number of tuples times the number of tuple components.

Definition at line 271 of file PropertyVector.h.

271{ return _n_components * getNumberOfTuples(); }

References MeshLib::PropertyVectorBase::_n_components, and getNumberOfTuples().

◆ ssize()

std::ptrdiff_t MeshLib::PropertyVector< T * >::ssize ( ) const
inlineconstexpr

Definition at line 100 of file PropertyVector.h.

100{ return std::ssize(data_); }

◆ Properties

template<typename T>
friend class Properties
friend

Definition at line 216 of file PropertyVector.h.

References Properties.

Referenced by Properties.

Member Data Documentation

◆ _item2group_mapping

template<typename T>
std::vector<std::size_t> MeshLib::PropertyVector< T * >::_item2group_mapping
private

Definition at line 332 of file PropertyVector.h.

Referenced by PropertyVector(), clone(), getNumberOfTuples(), operator[](), and operator[]().

◆ _values

template<typename T>
std::vector<T*> MeshLib::PropertyVector< T * >::_values
private

◆ data_

std::vector<T *> MeshLib::PropertyVector< T * >::data_
private

Definition at line 201 of file PropertyVector.h.


The documentation for this class was generated from the following file: