Dune Core Modules (2.4.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 
9 
17 namespace Dune
18 {
54  template<class T>
55  class Singleton
56  {
57  protected:
58  /* @brief Private constructor. */
59  Singleton(){}
61  Singleton(const Singleton&){}
64 
65  public:
70  DUNE_EXPORT static T& instance()
71  {
72  /* Smartpointer to the instance. */
73  static std::unique_ptr<T> instance_;
74  if(instance_.get() == 0)
75  instance_ = std::unique_ptr<T>(new T());
76  return *instance_;
77  }
78  };
79 
80 } // namespace Dune
81 
82 #endif
An adapter to turn a class into a singleton.
Definition: singleton.hh:56
Singleton(const Singleton &)
Private copy constructor.
Definition: singleton.hh:61
Singleton & operator=(const Singleton &)
Private assignment operator.
Definition: singleton.hh:63
static DUNE_EXPORT T & instance()
Get the instance of the singleton.
Definition: singleton.hh:70
Dune namespace.
Definition: alignment.hh:10
Definition of macros controlling symbol visibility at the ABI level.
#define DUNE_EXPORT
Export a symbol as part of the public ABI.
Definition: visibility.hh:18
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 12, 22:29, 2024)