Dune Core Modules (unstable)

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 // SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4 // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5 #ifndef DUNE_SINGLETON_HH
6 #define DUNE_SINGLETON_HH
7 
9 
17 namespace Dune
18 {
54  template<class T>
55  class Singleton
56  {
57  protected:
58  /* @brief Protected constructor. */
59  Singleton() = default;
60 
61  public:
62 
63  Singleton(const Singleton&) = delete;
64  void operator=(const Singleton&) = delete;
65 
70  DUNE_EXPORT static T& instance()
71  {
72  static T instance_;
73  return instance_;
74  }
75  };
76 
77 } // namespace Dune
78 
79 #endif
An adapter to turn a class into a singleton.
Definition: singleton.hh:56
static DUNE_EXPORT T & instance()
Get the instance of the singleton.
Definition: singleton.hh:70
Dune namespace.
Definition: alignedallocator.hh:13
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:20
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (Apr 27, 22:29, 2024)