LIBINT 2.7.2
singleton.h
1/*
2 * Copyright (C) 2004-2021 Edward F. Valeev
3 *
4 * This file is part of Libint.
5 *
6 * Libint is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Libint is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with Libint. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21#ifndef _libint2_include_libint2_util_singleton_h_
22#define _libint2_include_libint2_util_singleton_h_
23
24#include <memory>
25
26namespace libint2 {
27 namespace detail {
28
29 template <typename T> class managed_singleton {
30 public:
31 static T* instance() {
32 if (not instance_)
33 instance_ = std::unique_ptr<T>(new T);
34 return instance_.get();
35 }
36 static bool instance_exists() {
37 return instance_.get() != nullptr;
38 }
39 static void delete_instance() {
40 instance_.reset();
41 }
42 private:
43 managed_singleton() = delete;
44 static std::unique_ptr<T> instance_;
45 };
46 template <typename T> std::unique_ptr<T> managed_singleton<T>::instance_;
47
48 } // namespace libint2::detail
49} // namespace libint2
50
51#endif /* header guard */
Definition: singleton.h:29
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:24