LIBINT  2.6.0
initialize.h
1 /*
2  * Copyright (C) 2004-2019 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_src_lib_libint_initialize_h_
22 #define _libint2_src_lib_libint_initialize_h_
23 
24 #include <libint2/util/cxxstd.h>
25 #if LIBINT2_CPLUSPLUS_STD < 2011
26 # error "Libint2 C++ API requires C++11 support"
27 #endif
28 
29 #include <atomic>
30 #include <cassert>
31 #include <iostream>
32 
33 #include <libint2.h>
34 #include <libint2/util/deprecated.h>
35 #include <libint2/util/singleton.h>
36 
37 namespace libint2 {
38 
39  namespace detail {
40  struct __initializer {
41  __initializer() {
42  libint2_static_init();
43  }
44  ~__initializer() {
45  libint2_static_cleanup();
46  }
47  };
48 
49  inline std::atomic<bool>& verbose_accessor() {
50  static std::atomic<bool> value{false};
51  return value;
52  }
53  inline std::ostream*& verbose_stream_accessor() {
54  static std::ostream* value = &std::clog;
55  return value;
56  }
57  } // namespace libint2::detail
58 
61  inline bool initialized() {
62  using namespace detail;
63  return managed_singleton<__initializer>::instance_exists();
64  }
68  inline void initialize(bool verbose = false) {
69  if (!initialized()) {
70  using namespace detail;
71  __initializer *x = managed_singleton<__initializer>::instance();
72  (void) x; // to suppress unused variable warning (not guaranteed to work) TODO revise when upgrade to C++17
73  assert(x != nullptr);
74  verbose_accessor() = verbose;
75  }
76  }
77 
80  inline void initialize(std::ostream& os) {
81  if (!initialized()) {
82  initialize(true);
83  using namespace detail;
84  verbose_stream_accessor() = &os;
85  }
86  }
88  inline void finalize() {
89  if (initialized()) {
90  using namespace detail;
91  managed_singleton<__initializer>::delete_instance();
92  verbose_accessor() = true;
93  verbose_stream_accessor() = &std::clog;
94  }
95  }
98  inline std::ostream& verbose_stream() {
99  return *detail::verbose_stream_accessor();
100  }
104  inline bool verbose() {
105  if (initialized()) {
106  return detail::verbose_accessor();
107  } else {
108  return false;
109  }
110  }
111 }
112 
113 #endif /* _libint2_src_lib_libint_initialize_h_ */
114 
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:24
std::ostream & verbose_stream()
Accessor for the disgnostics stream.
Definition: initialize.h:98
bool verbose()
Accessor for the verbose flag.
Definition: initialize.h:104
bool initialized()
checks if the libint has been initialized.
Definition: initialize.h:61
Definition: initialize.h:40
void initialize(bool verbose=false)
initializes the libint library if not currently initialized, no-op otherwise
Definition: initialize.h:68
void finalize()
finalizes the libint library.
Definition: initialize.h:88