IAP GITLAB

Skip to content
Snippets Groups Projects
ParticleBase.h 2.61 KiB
Newer Older
 * (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 {

  /**
ralfulrich's avatar
ralfulrich committed
   @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;
ralfulrich's avatar
ralfulrich committed
    // 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;
ralfulrich's avatar
ralfulrich committed
    /** delete this particle on the stack. The corresponding iterator
     *  will be invalidated by this operation
     */
    void Delete() { GetIterator().GetStack().Delete(GetIterator()); }

ralfulrich's avatar
ralfulrich committed
    /**
     * 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(...)
     */
ralfulrich's avatar
ralfulrich committed
    template <typename... Args>
ralfulrich's avatar
ralfulrich committed
    StackIterator AddSecondary(const Args... args) {
      return GetStack().AddSecondary(GetIterator(), args...);
ralfulrich's avatar
ralfulrich committed
    //  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:
ralfulrich's avatar
ralfulrich committed
    /** @name Access to underlying stack data
Felix Riehn's avatar
Felix Riehn committed
        @{
ralfulrich's avatar
ralfulrich committed
    */
    auto& GetStackData() { return GetIterator().GetStackData(); }
    const auto& GetStackData() const { return GetIterator().GetStackData(); }
    auto& GetStack() { return GetIterator().GetStack(); }
    const auto& GetStack() const { return GetIterator().GetStack(); }
ralfulrich's avatar
ralfulrich committed
    ///@}
Felix Riehn's avatar
Felix Riehn committed
    /**
ralfulrich's avatar
ralfulrich committed
     * return the index number of the underlying iterator object
     */
    int GetIndex() const { return GetIterator().GetIndex(); }
  };

} // namespace corsika::stack