Gromacs
2026.0-dev-20241204-d69d709
|
#include <gromacs/utility/enumerationhelpers.h>
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.
EnumType | The enum (class) type. |
DataType | Type of the data stored in the array. |
ArraySize | Size 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... | |
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.