ValueProxy_fwd.h
1 /*
2  * MoMEMta: a modular implementation of the Matrix Element Method
3  * Copyright (C) 2016 Universite catholique de Louvain (UCL), Belgium
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #pragma once
20 
21 #include <memory>
22 #include <type_traits>
23 #include <vector>
24 
25 class Pool;
26 struct InputTag;
27 
28 template <typename T>
29 class ValueProxy {
30 public:
31  virtual T& operator*() = 0;
32  virtual T* operator->() = 0;
33  virtual T* get() = 0;
34 
35  static std::shared_ptr<ValueProxy<T>> create(const Pool*, const InputTag&);
36 
37 protected:
38  template <typename U>
39  std::shared_ptr<const U> get_from_pool(const Pool*, const InputTag&);
40 };
41 
42 template <typename T>
43 class NonIndexedValueProxy: public ValueProxy<T> {
44 public:
45  using container_t = typename std::remove_const<T>::type;
46 
47  NonIndexedValueProxy(const Pool*, const InputTag& tag);
48  virtual T& operator*() override;
49  virtual T* operator->() override;
50  virtual T* get() override;
51 
52 private:
53  std::shared_ptr<const container_t> raw_value;
54 };
55 
56 template <typename T>
57 class IndexedValueProxy: public ValueProxy<T> {
58 public:
59  using container_t = std::vector<typename std::remove_const<T>::type>;
60 
61  IndexedValueProxy(const Pool*, const InputTag& tag);
62  virtual T& operator*() override;
63  virtual T* operator->() override;
64  virtual T* get() override;
65 
66 private:
67  size_t index;
68  std::shared_ptr<const container_t> raw_value;
69 };
An identifier of a module&#39;s output.
Definition: InputTag_fwd.h:37
Definition: Pool.h:40