CORSIKA  @c8_version@
The framework to simulate particle cascades for astroparticle physics
ParticleBase.hpp
1 /*
2  * (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu
3  *
4  * This software is distributed under the terms of the GNU General Public
5  * Licence version 3 (GPL Version 3). See file LICENSE for a full version of
6  * the license.
7  */
8 
9 #pragma once
10 
11 #include <type_traits>
12 #include <cstdlib> // for size_t
13 
14 namespace corsika {
15 
42  template <typename TStackIterator>
43  class ParticleBase {
44 
45  public:
46  typedef TStackIterator stack_iterator_type;
47 
48  ParticleBase() = default;
49 
50  // those copy constructors and assigments should never be implemented
51 
52  ParticleBase(ParticleBase&&) = delete;
53  ParticleBase(ParticleBase const&) = delete;
54 
55  ParticleBase operator=(ParticleBase&&) = delete;
56  ParticleBase operator=(ParticleBase const&) = delete;
57 
62  void erase() { this->getIterator().getStack().erase(this->getIterator()); }
63 
68  bool isErased() const {
69  return this->getIterator().getStack().isErased(this->getIterator());
70  }
71 
77  template <typename... TArgs>
78  stack_iterator_type addSecondary(const TArgs... args) {
79  return this->getStack().addSecondary(this->getIterator(), args...);
80  }
81 
82  // protected: // todo should [MAY]be proteced, but don't now how to 'friend Stack'
83  // Function to provide CRTP access to inheriting class (type)
87  stack_iterator_type& getIterator() {
88  return static_cast<stack_iterator_type&>(*this);
89  }
90 
91  const stack_iterator_type& getIterator() const {
92  return static_cast<const stack_iterator_type&>(*this);
93  }
94 
95  protected:
102  auto& getStackData() { return this->getIterator().getStackData(); }
103 
104  const auto& getStackData() const { return this->getIterator().getStackData(); }
105 
106  auto& getStack() { return this->getIterator().getStack(); }
107 
108  const auto& getStack() const { return this->getIterator().getStack(); }
109 
114  std::size_t getIndex() const { return this->getIterator().getIndexFromIterator(); }
116  };
117 
118 } // namespace corsika
void erase()
Delete this particle on the stack.
stack_iterator_type & getIterator()
return the corresponding TStackIterator for this particle
`, since they are used everywhere as integral part of the framework.
std::size_t getIndex() const
return the index number of the underlying iterator object
bool isErased() const
Method to retrieve the status of the Particle.
stack_iterator_type addSecondary(const TArgs... args)
Add a secondary particle based on *this on the stack.
The base class to define the readout of particle properties from a particle stack.