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 208 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 56 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 214 of file PropertyVector.h.

215 {
216 for (auto v : _values)
217 {
218 delete[] v;
219 }
220 }

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 313 of file PropertyVector.h.

322 {
323 }
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 140 of file PropertyVector.h.

141 {
142#if __cpp_lib_containers_ranges >= 202202L
143 data_.assign_range(r);
144#else
145 if constexpr (ranges::common_range<R>)
146 {
147 data_.assign(r.begin(), r.end());
148 }
149 else
150 {
153 }
154#endif
155 }
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 101 of file PropertyVector.h.

101{ return data_.data(); }

◆ cbegin()

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

Definition at line 104 of file PropertyVector.h.

104{ return data_.data(); }

◆ cend()

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

Definition at line 105 of file PropertyVector.h.

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

◆ clear()

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

Definition at line 162 of file PropertyVector.h.

162{ 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 98 of file PropertyVector.h.

98{ return data_.data(); }

◆ empty()

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

Definition at line 163 of file PropertyVector.h.

163{ return data_.empty(); }

◆ end()

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

Definition at line 102 of file PropertyVector.h.

102{ 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 285 of file PropertyVector.h.

286 {
289
290 const double* p = this->operator[](tuple_index);
291 if (p == nullptr)
292 {
293 OGS_FATAL(
294 "No data found in the property vector {:s} "
295 "for the tuple index {:d} and component {:d}",
297 }
298 return p[component];
299 }
#define OGS_FATAL(...)
Definition Error.h:19
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 261 of file PropertyVector.h.

261{ 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 244 of file PropertyVector.h.

245 {
246 if (_n_components != static_cast<int>(values.size()))
247 {
248 OGS_FATAL(
249 "The size of provided values in initPropertyValue() is "
250 "not same as the number of components in PropertyVector<T*>");
251 }
252
253 auto* p = new T[values.size()];
254 for (unsigned i = 0; i < values.size(); i++)
255 {
256 p[i] = values[i];
257 }
258 _values[group_id] = p;
259 }
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 231 of file PropertyVector.h.

232 {
233 if (_n_components != 1)
234 {
235 OGS_FATAL(
236 "Single-component version of initPropertyValue() is called "
237 "for a multi-components PropertyVector<T*>");
238 }
239 auto* p = new T[1];
240 p[0] = value;
241 _values[group_id] = p;
242 }

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 229 of file PropertyVector.h.

229{ 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 224 of file PropertyVector.h.

225 {
227 }

References _item2group_mapping, and _values.

Referenced by getComponent().

◆ push_back()

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

Definition at line 157 of file PropertyVector.h.

158 {
159 data_.push_back(value);
160 }

◆ resize()

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

Definition at line 130 of file PropertyVector.h.

130{ 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 265 of file PropertyVector.h.

265{ return _n_components * getNumberOfTuples(); }

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

◆ ssize()

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

Definition at line 94 of file PropertyVector.h.

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

◆ Properties

template<typename T>
friend class Properties
friend

Definition at line 210 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 326 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 195 of file PropertyVector.h.


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