Version: SMASH-1.5
smash::ParticleTypePtr Class Reference

#include <particletype.h>

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

See also
ParticleType::operator&

Definition at line 660 of file particletype.h.

Collaboration diagram for smash::ParticleTypePtr:
[legend]

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 715 of file particletype.h.

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

Member Function Documentation

◆ operator*()

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

Definition at line 663 of file particletype.h.

663 { return lookup(); }
const ParticleType & lookup() const
Helper function that does the ParticleType lookup from the stored index.
Definition: particletype.h:728
Here is the call graph for this function:

◆ operator->()

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

Definition at line 666 of file particletype.h.

666  {
667  // this requires std::addressof because &lookup() would call
668  // ParticleType::operator& and return ParticleTypePtr again
669  return std::addressof(lookup());
670  }
const ParticleType & lookup() const
Helper function that does the ParticleType lookup from the stored index.
Definition: particletype.h:728
Here is the call graph for this function:

◆ 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 679 of file particletype.h.

679  {
680  return index_ == rhs.index_;
681  }
std::uint16_t index_
Stores the index of the references ParticleType object in the global vector.
Definition: particletype.h:738

◆ 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 687 of file particletype.h.

687  {
688  return index_ != rhs.index_;
689  }
std::uint16_t index_
Stores the index of the references ParticleType object in the global vector.
Definition: particletype.h:738

◆ 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 696 of file particletype.h.

696  {
697  return index_ < rhs.index_;
698  }
std::uint16_t index_
Stores the index of the references ParticleType object in the global vector.
Definition: particletype.h:738

◆ operator bool()

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

Definition at line 701 of file particletype.h.

701 { return index_ != 0xffff; }
std::uint16_t index_
Stores the index of the references ParticleType object in the global vector.
Definition: particletype.h:738

◆ 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 728 of file particletype.h.

728  {
729  assert(index_ != 0xffff);
730  return ParticleType::list_all()[index_];
731  }
static const ParticleTypeList & list_all()
Definition: particletype.cc:55
std::uint16_t index_
Stores the index of the references ParticleType object in the global vector.
Definition: particletype.h:738
Here is the call graph for this function:
Here is the caller graph for this function:

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 738 of file particletype.h.


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