Dune Core Modules (2.3.1)

singleton.hh
Go to the documentation of this file.
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 #ifndef DUNE_SINGLETON_HH
4 #define DUNE_SINGLETON_HH
5 
6 #include <memory>
7 
15 namespace Dune
16 {
52  template<class T>
53  class Singleton
54  {
56  static std::auto_ptr<T> instance_;
57  protected:
58  /* @brief Private constructor. */
59  Singleton(){}
61  Singleton(const Singleton&){}
64 
65  public:
70  static T& instance()
71  {
72  if(instance_.get() == 0)
73  instance_ = std::auto_ptr<T>(new T());
74  return *instance_;
75  }
76  };
77 
78  template<class T>
79  typename std::auto_ptr<T> Singleton<T>::instance_;
80 
81 } // namespace Dune
82 
83 #endif
An adapter to turn a class into a singleton.
Definition: singleton.hh:54
static T & instance()
Get the instance of the singleton.
Definition: singleton.hh:70
Singleton(const Singleton &)
Private copy constructor.
Definition: singleton.hh:61
Singleton & operator=(const Singleton &)
Private assignment operator.
Definition: singleton.hh:63
Dune namespace.
Definition: alignment.hh:14
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 16, 22:29, 2024)