CORSIKA  @c8_version@
The framework to simulate particle cascades for astroparticle physics
EngineCaller.hpp
1 /*
2  * (c) Copyright 2021 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 /*
10  * EngineCaller.hpp
11  *
12  * Created on: 23/02/2021
13  * Author: Antonio Augusto Alves Junior
14  */
15 
16 #pragma once
17 
18 #include <stdint.h>
19 
20 namespace random_iterator {
21 
22  namespace detail {
23 
24  template <typename DistibutionType, typename EngineType>
25  struct EngineCaller {
26  typedef EngineType engine_type;
27  typedef typename engine_type::state_type state_type;
28  typedef typename engine_type::seed_type seed_type;
29  typedef typename engine_type::advance_type advance_type;
30  typedef typename engine_type::init_type init_type;
31 
32  typedef DistibutionType distribution_type;
33  typedef typename distribution_type::result_type result_type;
34 
35  EngineCaller() = delete;
36 
37  EngineCaller(distribution_type const& dist, seed_type seed, uint32_t stream)
38  : distribution_(dist)
39  , seed_(seed)
40  , stream_(stream) {}
41 
43  : distribution_(other.distribution_)
44  , seed_(other.seed_)
45  , stream_(other.stream_) {}
46 
49 
50  if (this == &other) return *this;
51 
52  distribution_ = other.distribution_;
53  seed_ = other.seed_;
54  stream_ = other.stream_;
55 
56  return *this;
57  }
58 
59  inline result_type operator()(advance_type n) const {
60 
61  EngineType eng(seed_, stream_);
62  eng.discard(n);
63 
64  return static_cast<distribution_type>(distribution_)(eng);
65  }
66 
67  distribution_type distribution_;
68  seed_type seed_;
69  uint32_t stream_;
70  };
71 
72  } // namespace detail
73 
74 } // namespace random_iterator