Version: SMASH-3.1
smash::ParticleTypePtr Class Reference

#include <particletype.h>

A pointer-like interface to global references to ParticleType objects.

See also
ParticleType::operator&

Definition at line 676 of file particletype.h.

Public Member Functions

const ParticleTypeoperator* () const
 
const ParticleTypeoperator-> () const
 
 ParticleTypePtr ()=default
 Default construction initializes with an invalid index. More...
 
bool operator== (const ParticleTypePtr &rhs) const
 
bool operator!= (const ParticleTypePtr &rhs) const
 
bool operator< (const ParticleTypePtr &rhs) const
 "Less than" operator More...
 
 operator bool () const
 

Private Member Functions

 ParticleTypePtr (std::uint16_t i)
 Constructs a pointer to the ParticleType object at offset i. More...
 
const ParticleTypelookup () const
 Helper function that does the ParticleType lookup from the stored index. More...
 

Private Attributes

std::uint16_t index_ = 0xffff
 Stores the index of the references ParticleType object in the global vector. More...
 

Friends

ParticleTypePtr ParticleType::operator& () const
 ParticleType::operator& is a friend in order to call the constructor. More...
 

Constructor & Destructor Documentation

◆ ParticleTypePtr() [1/2]

smash::ParticleTypePtr::ParticleTypePtr ( )
default

Default construction initializes with an invalid index.

◆ ParticleTypePtr() [2/2]

smash::ParticleTypePtr::ParticleTypePtr ( std::uint16_t  i)
inlineexplicitprivate

Constructs a pointer to the ParticleType object at offset i.

Parameters
[in]ithe offset where to create.

Definition at line 731 of file particletype.h.

731 : index_(i) {}
std::uint16_t index_
Stores the index of the references ParticleType object in the global vector.
Definition: particletype.h:754

Member Function Documentation

◆ operator*()

const ParticleType& smash::ParticleTypePtr::operator* ( ) const
inline
Returns
Dereferences the pointer and returns the ParticleType object.

Definition at line 679 of file particletype.h.

679 { return lookup(); }
const ParticleType & lookup() const
Helper function that does the ParticleType lookup from the stored index.
Definition: particletype.h:744

◆ operator->()

const ParticleType* smash::ParticleTypePtr::operator-> ( ) const
inline
Returns
Dereferences the pointer and returns the ParticleType object.

Definition at line 682 of file particletype.h.

682  {
683  // this requires std::addressof because &lookup() would call
684  // ParticleType::operator& and return ParticleTypePtr again
685  return std::addressof(lookup());
686  }

◆ operator==()

bool smash::ParticleTypePtr::operator== ( const ParticleTypePtr rhs) const
inline
Parameters
[in]rhsthe ParticleTypePtr to compare to
Returns
whether the two objects reference the same ParticleType object.

Definition at line 695 of file particletype.h.

695  {
696  return index_ == rhs.index_;
697  }

◆ operator!=()

bool smash::ParticleTypePtr::operator!= ( const ParticleTypePtr rhs) const
inline
Parameters
[in]rhsthe ParticleTypePtr to compare to
Returns
whether the two objects reference different ParticleType objects.

Definition at line 703 of file particletype.h.

703  {
704  return index_ != rhs.index_;
705  }

◆ operator<()

bool smash::ParticleTypePtr::operator< ( const ParticleTypePtr rhs) const
inline

"Less than" operator

Parameters
[in]rhsthe ParticleTypePtr to compare to
Returns
whether the index is smaller than rhs' index.

Definition at line 712 of file particletype.h.

712  {
713  return index_ < rhs.index_;
714  }

◆ operator bool()

smash::ParticleTypePtr::operator bool ( ) const
inline
Returns
whether the objects stores a valid ParticleType reference.

Definition at line 717 of file particletype.h.

717 { return index_ != 0xffff; }

◆ lookup()

const ParticleType& smash::ParticleTypePtr::lookup ( ) const
inlineprivate

Helper function that does the ParticleType lookup from the stored index.

Implementation:
In debug builds this function asserts that the index is valid. It then asks for the vector of all ParticleType objects (ParticleType::list_all) and uses vector::operator[] to return an lvalue reference to the ParticleType object at the offset index_.
Returns
a reference to the ParticleType object at offset index_.

Definition at line 744 of file particletype.h.

744  {
745  assert(index_ != 0xffff);
746  return ParticleType::list_all()[index_];
747  }
static const ParticleTypeList & list_all()
Definition: particletype.cc:51

Friends And Related Function Documentation

◆ ParticleType::operator&

ParticleTypePtr ParticleType::operator& ( ) const
friend

ParticleType::operator& is a friend in order to call the constructor.

Returns
the pointer to a ParticleType

Member Data Documentation

◆ index_

std::uint16_t smash::ParticleTypePtr::index_ = 0xffff
private

Stores the index of the references ParticleType object in the global vector.

The value 0xffff is used to denote an invalid index (similar to a null pointer).

Definition at line 754 of file particletype.h.


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