Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ContextType.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ContextType.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2021 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
11 #include <any>
12 
13 namespace Acts {
14 
22 class ContextType {
23  public:
26  ContextType() = default;
27 
32  template <typename T>
33  explicit ContextType(T&& value) : m_data{std::move(value)} {}
34 
39  template <typename T>
40  explicit ContextType(const T& value) : m_data{value} {}
41 
47  template <typename T>
49  m_data = std::move(value);
50  return *this;
51  }
52 
58  template <typename T>
59  ContextType& operator=(const T& value) {
60  m_data = value;
61  return *this;
62  }
63 
68  template <typename T>
69  std::decay_t<T>& get() {
70  return std::any_cast<std::decay_t<T>&>(m_data);
71  }
72 
77  template <typename T>
78  const std::decay_t<T>& get() const {
79  return std::any_cast<const std::decay_t<T>&>(m_data);
80  }
81 
84  bool hasValue() const { return m_data.has_value(); }
85 
86  private:
87  std::any m_data;
88 };
89 
90 } // namespace Acts