Gromacs
2018.8
|
#include <gromacs/math/vectypes.h>
C++ class for 3D vectors.
ValueType | Type |
This class provides a C++ version of rvec/dvec/ivec that can be put into STL containers etc. It is more or less a drop-in replacement for rvec
and friends: it can be used in most contexts that accept the equivalent C type. However, there are two cases where explicit conversion is necessary:
const rvec &
parameter to a function needs an explicit call to as_vec(). The implicit conversion should work for this as well, but cppcheck parses the necessary implicit conversion operator incorrectly and MSVC fails to compile code that relies on the implicit conversion, so the explicit method is necessary.For the array conversion to work, the compiler should not add any extra alignment/padding in the layout of this class; that this actually works as intended is tested in the unit tests.
Public Types | |
typedef ValueType | RawArray [3] |
Underlying raw C array type (rvec/dvec/ivec). | |
Public Member Functions | |
BasicVector () | |
Constructs default (uninitialized) vector. | |
BasicVector (ValueType x, ValueType y, ValueType z) | |
Constructs a vector from given values. | |
BasicVector (const RawArray x) | |
Constructs a vector from given values. More... | |
ValueType & | operator[] (int i) |
Indexing operator to make the class work as the raw array. | |
ValueType | operator[] (int i) const |
Indexing operator to make the class work as the raw array. | |
operator ValueType * () | |
Makes BasicVector usable in contexts where a raw C array is expected. | |
operator const ValueType * () const | |
Makes BasicVector usable in contexts where a raw C array is expected. | |
RawArray & | as_vec () |
Converts to a raw C array where implicit conversion does not work. | |
const RawArray & | as_vec () const |
Converts to a raw C array where implicit conversion does not work. | |
|
inline |
Constructs a vector from given values.
This constructor is not explicit to support implicit conversions that allow, e.g., calling std::vector<RVec>:
:push_back()
directly with an rvec
parameter.