Gromacs  2024.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes
gmx::EnumerationArray< EnumType, DataType, ArraySize > Struct Template Reference

#include <gromacs/utility/enumerationhelpers.h>

Description

template<typename EnumType, typename DataType, EnumType ArraySize>
struct gmx::EnumerationArray< EnumType, DataType, ArraySize >

Wrapper for a C-style array with size and indexing defined by an enum. Useful for declaring arrays of enum names for debug or other printing. An ArrayRef<DataType> may be constructed from an object of this type.

See file documentation for usage example.

Note that if clang-tidy gives strange errors referring to the line number of the struct declaration, these likely refer to the compiler-generated constructors. Simplification of the calling code might eliminate that call and thus the clang-tidy error.

Template Parameters
EnumTypeThe enum (class) type.
DataTypeType of the data stored in the array.
ArraySizeSize in entries of the array.

Public Types

using EnumerationWrapperType = EnumerationWrapper< EnumType, ArraySize >
 Convenience alias.
 
using value_type = DataType
 Convenience alias.
 
using iterator = DataType *
 Range iterators (unchecked)
 
using const_iterator = const DataType *
 
using reverse_iterator = std::reverse_iterator< iterator >
 
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 
using pointer = DataType *
 Pointers (unchecked)
 
using const_pointer = const DataType *
 

Public Member Functions

constexpr std::size_t size () const
 Returns the size of the enumeration.
 
const_pointer data () const
 Returns a const raw pointer to the contents of the array.
 
pointer data ()
 Returns a raw pointer to the contents of the array.
 
DataType & operator[] (const std::size_t arrayIndex)
 Array access with asserts:
 
const DataType & operator[] (const std::size_t arrayIndex) const
 
DataType & operator[] (const EnumType enumIndex)
 
const DataType & operator[] (const EnumType enumIndex) const
 
iterator begin ()
 Getters for forward iterators for ranges.
 
iterator end ()
 
constexpr const_iterator begin () const
 
constexpr const_iterator end () const
 
reverse_iterator rbegin ()
 Getters for reverse iterators for ranges.
 
reverse_iterator rend ()
 
constexpr const_reverse_iterator rbegin () const
 
constexpr const_reverse_iterator rend () const
 

Static Public Member Functions

static constexpr
EnumerationWrapperType 
keys ()
 Returns an object that provides iterators over the keys.
 

Public Attributes

DataType m_elements [std::size_t(ArraySize)]
 Data for names. More...
 

Member Data Documentation

template<typename EnumType, typename DataType, EnumType ArraySize>
DataType gmx::EnumerationArray< EnumType, DataType, ArraySize >::m_elements[std::size_t(ArraySize)]

Data for names.

Data is kept public so we can use direct aggregate initialization just like in a plain C-style array.


The documentation for this struct was generated from the following files: