/* * (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu * * See file AUTHORS for a list of contributors. * * This software is distributed under the terms of the GNU General Public * Licence version 3 (GPL Version 3). See file LICENSE for a full version of * the license. */ #ifndef _include_particleBase_h_ #define _include_particleBase_h_ class StackData; // forward decl namespace corsika::stack { /** @class ParticleBase The base class to define the readout of particle properties from a particle stack. Every stack must implement this readout via the ParticleBase class. */ template <typename StackIterator> class ParticleBase { public: ParticleBase() = default; private: // those copy constructors and assigments should never be implemented ParticleBase(ParticleBase&) = delete; ParticleBase operator=(ParticleBase&) = delete; ParticleBase(ParticleBase&&) = delete; ParticleBase operator=(ParticleBase&&) = delete; ParticleBase(const ParticleBase&) = delete; ParticleBase operator=(const ParticleBase&) = delete; public: /** delete this particle on the stack. The corresponding iterator * will be invalidated by this operation */ void Delete() { GetIterator().GetStack().Delete(GetIterator()); } /** * Add a secondary particle based on *this on the stack @param * args is a variadic list of input data that has to match the * function description in the user defined ParticleInterface::AddSecondary(...) */ template <typename... Args> StackIterator AddSecondary(const Args... args) { return GetStack().AddSecondary(GetIterator(), args...); } // protected: // todo should [MAY]be proteced, but don't now how to 'friend Stack' // Function to provide CRTP access to inheriting class (type) /** * return the corresponding StackIterator for this particle */ StackIterator& GetIterator() { return static_cast<StackIterator&>(*this); } const StackIterator& GetIterator() const { return static_cast<const StackIterator&>(*this); } protected: /** @name Access to underlying stack data @{ */ auto& GetStackData() { return GetIterator().GetStackData(); } const auto& GetStackData() const { return GetIterator().GetStackData(); } auto& GetStack() { return GetIterator().GetStack(); } const auto& GetStack() const { return GetIterator().GetStack(); } ///@} /** * return the index number of the underlying iterator object */ int GetIndex() const { return GetIterator().GetIndex(); } }; } // namespace corsika::stack #endif