ALPSCore reference
wrapper_set.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1998-2018 ALPS Collaboration. See COPYRIGHT.TXT
3  * All rights reserved. Use is subject to license terms. See LICENSE.TXT
4  * For use in publications, see ACKNOWLEDGE.TXT
5  */
6 
8 #include <alps/accumulators.hpp>
9 
10 namespace alps {
11  namespace accumulators {
12 
13  namespace detail {
14  void register_predefined_serializable_types();
15  }
16 
17  namespace impl {
18 
19  template<typename T>
21  std::lock_guard<std::mutex> guard(m_types_mutex);
22  if (m_types.empty()) {
23  detail::register_predefined_serializable_types();
24  }
25  }
26 
27  template<typename T>
28  T & wrapper_set<T>::operator[](std::string const & name) {
29  if (!has(name))
30  m_storage.insert(make_pair(name, std::shared_ptr<T>(new T())));
31  return *(m_storage.find(name)->second);
32  }
33 
34  template<typename T>
35  T const & wrapper_set<T>::operator[](std::string const & name) const {
36  if (!has(name))
37  throw std::out_of_range("No observable found with the name: " + name + ALPS_STACKTRACE);
38  return *(m_storage.find(name)->second);
39  }
40 
41  template<typename T>
42  bool wrapper_set<T>::has(std::string const & name) const{
43  return m_storage.find(name) != m_storage.end();
44  }
45 
46  template<typename T>
47  void wrapper_set<T>::insert(std::string const & name, std::shared_ptr<T> ptr){
48  if (has(name))
49  throw std::out_of_range("There already exists an accumulator with the name: " + name + ALPS_STACKTRACE);
50  m_storage.insert(make_pair(name, ptr));
51  }
52 
53  template<typename T>
54  void wrapper_set<T>::print(std::ostream & os) const {
55  for(const_iterator it = begin(); it != end(); ++it)
56  os << it->first << ": " << *(it->second) << std::endl;
57  }
58 
59  // Explicit instantiations
60  template class wrapper_set<accumulator_wrapper>;
61  template class wrapper_set<result_wrapper>;
62  }
63  }
64 }
void insert(std::string const &name, std::shared_ptr< T > ptr)
Definition: wrapper_set.cpp:47
std::ostream & print(std::ostream &s, const dict_value &dv, bool terse)
Definition: dict_value.cpp:186
#define ALPS_STACKTRACE
Definition: stacktrace.hpp:37
std::map< std::string, std::shared_ptr< T > >::const_iterator const_iterator
Definition: wrapper_set.hpp:33