MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
mfem::ArraysByName< T > Class Template Reference

#include <arrays_by_name.hpp>

Collaboration diagram for mfem::ArraysByName< T >:
[legend]

Public Member Functions

 ArraysByName ()=default
 Default constructor.
 
 ArraysByName (const ArraysByName &src)=default
 Copy constructor: deep copy from src.
 
 ArraysByName (ArraysByName &&src) noexcept=default
 Move constructor.
 
int Size () const
 Return the number of named arrays in the container.
 
std::set< std::string > GetNames () const
 Return an STL set of strings giving the names of the arrays.
 
bool EntryExists (const std::string &name) const
 Return true if an array with the given name is present in the container.
 
Array< T > & operator[] (const std::string &name)
 Reference access to the named entry.
 
const Array< T > & operator[] (const std::string &name) const
 Const reference access to the named entry.
 
Array< T > & CreateArray (const std::string &name)
 Create a new empty array with the given name.
 
void DeleteAll ()
 Delete all named arrays from the container.
 
void DeleteArray (const std::string &name)
 Delete the named array from the container.
 
ArraysByName< T > & operator= (const ArraysByName< T > &src)=default
 Copy assignment operator: deep copy from 'src'.
 
ArraysByName< T > & operator= (ArraysByName< T > &&src) noexcept=default
 Move assignment operator.
 
void Print (std::ostream &out=mfem::out, int width=-1) const
 Print the contents of the container to an output stream.
 
void Load (std::istream &in)
 Load the contents of the container from an input stream.
 
void SortAll ()
 Sort each named array in the container.
 
void UniqueAll ()
 Remove duplicates from each, previously sorted, named array.
 
iterator begin ()
 STL-like begin. Returns pointer to the first entry of the container.
 
iterator end ()
 STL-like end. Returns pointer after the last entry of the container.
 
const_iterator begin () const
 STL-like begin. Returns const pointer to the first entry of the container.
 
const_iterator end () const
 STL-like end. Returns const pointer after the last entry of the container.
 

Protected Types

using container = std::map<std::string,Array<T> >
 Reusing STL map iterators.
 
using iterator = typename container::iterator
 
using const_iterator = typename container::const_iterator
 

Protected Attributes

container data
 Map containing the data sorted alphabetically by name.
 

Detailed Description

template<class T>
class mfem::ArraysByName< T >

Container class for storing arrays indexed by strings.

The Array<T> objects stored within this container must all be based on the same underlying generic type T, which must be a trivial type, see std::is_trivial.

In order to provide some level of protection against typos this class will not create new named arrays when access to unrecognized names is requested. New named arrays must be explicitly created using CreateArray(). To facilitate this behavior and avoid such errors the method EntryExists() is provided.

This container does not store pointers to pre-existing arrays. It will copy or move entries as appropriate from existing Array<T> objects into new Array<T> objects stored within this container.

Definition at line 44 of file arrays_by_name.hpp.

Member Typedef Documentation

◆ const_iterator

template<class T >
using mfem::ArraysByName< T >::const_iterator = typename container::const_iterator
protected

Definition at line 50 of file arrays_by_name.hpp.

◆ container

template<class T >
using mfem::ArraysByName< T >::container = std::map<std::string,Array<T> >
protected

Reusing STL map iterators.

Definition at line 48 of file arrays_by_name.hpp.

◆ iterator

template<class T >
using mfem::ArraysByName< T >::iterator = typename container::iterator
protected

Definition at line 49 of file arrays_by_name.hpp.

Constructor & Destructor Documentation

◆ ArraysByName() [1/3]

template<class T >
mfem::ArraysByName< T >::ArraysByName ( )
default

Default constructor.

◆ ArraysByName() [2/3]

template<class T >
mfem::ArraysByName< T >::ArraysByName ( const ArraysByName< T > & src)
default

Copy constructor: deep copy from src.

◆ ArraysByName() [3/3]

template<class T >
mfem::ArraysByName< T >::ArraysByName ( ArraysByName< T > && src)
defaultnoexcept

Move constructor.

Member Function Documentation

◆ begin() [1/2]

template<class T >
iterator mfem::ArraysByName< T >::begin ( )
inline

STL-like begin. Returns pointer to the first entry of the container.

Definition at line 141 of file arrays_by_name.hpp.

◆ begin() [2/2]

template<class T >
const_iterator mfem::ArraysByName< T >::begin ( ) const
inline

STL-like begin. Returns const pointer to the first entry of the container.

Definition at line 148 of file arrays_by_name.hpp.

◆ CreateArray()

template<class T >
Array< T > & mfem::ArraysByName< T >::CreateArray ( const std::string & name)
inline

Create a new empty array with the given name.

Note
Passing a name for an already existent array will print an error message and halt execution. This is intended to call attention to possible typos or other errors. To handle such errors more gracefully consider first calling EntryExists.

Definition at line 203 of file arrays_by_name.hpp.

◆ DeleteAll()

template<class T >
void mfem::ArraysByName< T >::DeleteAll ( )
inline

Delete all named arrays from the container.

Definition at line 213 of file arrays_by_name.hpp.

◆ DeleteArray()

template<class T >
void mfem::ArraysByName< T >::DeleteArray ( const std::string & name)
inline

Delete the named array from the container.

Note
Passing a name for a nonexistent array will print an error message and halt execution. This is intended to call attention to possible typos or other errors. To handle such errors more gracefully consider first calling EntryExists.

Definition at line 219 of file arrays_by_name.hpp.

◆ end() [1/2]

template<class T >
iterator mfem::ArraysByName< T >::end ( )
inline

STL-like end. Returns pointer after the last entry of the container.

Definition at line 144 of file arrays_by_name.hpp.

◆ end() [2/2]

template<class T >
const_iterator mfem::ArraysByName< T >::end ( ) const
inline

STL-like end. Returns const pointer after the last entry of the container.

Definition at line 152 of file arrays_by_name.hpp.

◆ EntryExists()

template<class T >
bool mfem::ArraysByName< T >::EntryExists ( const std::string & name) const
inline

Return true if an array with the given name is present in the container.

Definition at line 180 of file arrays_by_name.hpp.

◆ GetNames()

template<class T >
std::set< std::string > mfem::ArraysByName< T >::GetNames ( ) const
inline

Return an STL set of strings giving the names of the arrays.

Definition at line 169 of file arrays_by_name.hpp.

◆ Load()

template<class T >
void mfem::ArraysByName< T >::Load ( std::istream & in)

Load the contents of the container from an input stream.

Note
This method will not first empty the container. First call DeleteAll if this behavior is needed.

Definition at line 256 of file arrays_by_name.hpp.

◆ operator=() [1/2]

template<class T >
ArraysByName< T > & mfem::ArraysByName< T >::operator= ( ArraysByName< T > && src)
defaultnoexcept

Move assignment operator.

◆ operator=() [2/2]

template<class T >
ArraysByName< T > & mfem::ArraysByName< T >::operator= ( const ArraysByName< T > & src)
default

Copy assignment operator: deep copy from 'src'.

◆ operator[]() [1/2]

template<class T >
Array< T > & mfem::ArraysByName< T >::operator[] ( const std::string & name)
inline

Reference access to the named entry.

Note
Passing a name for a nonexistent array will print an error message and halt execution. This is intended to call attention to possible typos or other errors. To handle such errors more gracefully consider first calling EntryExists.

Definition at line 186 of file arrays_by_name.hpp.

◆ operator[]() [2/2]

template<class T >
const Array< T > & mfem::ArraysByName< T >::operator[] ( const std::string & name) const
inline

Const reference access to the named entry.

Note
Passing a name for a nonexistent array will print an error message and halt execution. This is intended to call attention to possible typos or other errors. To handle such errors more gracefully consider first calling EntryExists.

Definition at line 194 of file arrays_by_name.hpp.

◆ Print()

template<class T >
void mfem::ArraysByName< T >::Print ( std::ostream & out = mfem::out,
int width = -1 ) const
inline

Print the contents of the container to an output stream.

Note
Each array will be printed on at least three lines; the name on one line, the length of the associated array, lastly the array contents with width entries per line. A specific number of entries per line can be used by changing the width argument.

Definition at line 245 of file arrays_by_name.hpp.

◆ Size()

template<class T >
int mfem::ArraysByName< T >::Size ( ) const
inline

Return the number of named arrays in the container.

Definition at line 67 of file arrays_by_name.hpp.

◆ SortAll()

template<class T >
void mfem::ArraysByName< T >::SortAll ( )
inline

Sort each named array in the container.

Definition at line 227 of file arrays_by_name.hpp.

◆ UniqueAll()

template<class T >
void mfem::ArraysByName< T >::UniqueAll ( )
inline

Remove duplicates from each, previously sorted, named array.

Note
Identical entries may exist in multiple arrays but will only occur at most once in each array.

Definition at line 236 of file arrays_by_name.hpp.

Member Data Documentation

◆ data

template<class T >
container mfem::ArraysByName< T >::data
protected

Map containing the data sorted alphabetically by name.

Definition at line 53 of file arrays_by_name.hpp.


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