Turi Create  4.0
startup_teardown.hpp
1 /* Copyright © 2017 Apple Inc. All rights reserved.
2  *
3  * Use of this source code is governed by a BSD-3-clause license that can
4  * be found in the LICENSE.txt file or at https://opensource.org/licenses/BSD-3-Clause
5  */
6 #ifndef TURI_STARTUP_TEARDOWN_HPP
7 #define TURI_STARTUP_TEARDOWN_HPP
8 #include <core/export.hpp>
9 #include <string>
10 
11 namespace turi {
12 
13 /**
14  * Configures the system global environment. This should be the first thing
15  * (or close to the first thing) called on program startup.
16  */
17 void EXPORT configure_global_environment(std::string argv0);
18 
19 /**
20  * This class centralizes all startup functions
21  */
22 class EXPORT global_startup {
23  public:
24  global_startup() = default;
25 
26  global_startup(const global_startup&) = delete;
27  global_startup(global_startup&&) = delete;
28  global_startup& operator=(global_startup&&) = delete;
29  global_startup& operator=(const global_startup&) = delete;
30 
31  /**
32  * Performs all the startup calls immediately. Further calls to this
33  * function does nothing.
34  */
35  void perform_startup();
36 
37  /**
38  * Performs the startup if startup has not yet been performed.
39  */
40  ~global_startup();
41 
42  static global_startup& get_instance();
43 
44  private:
45  bool startup_performed = false;
46 };
47 
48 /**
49  * This class centralizes all tear down functions allowing destruction
50  * to happen in a prescribed order.
51  *
52  * TODO This can be more intelligent as required. For now, it is kinda dumb.
53  */
54 class EXPORT global_teardown {
55  public:
56  global_teardown() = default;
57 
58  global_teardown(const global_teardown&) = delete;
59  global_teardown(global_teardown&&) = delete;
60  global_teardown& operator=(global_teardown&&) = delete;
61  global_teardown& operator=(const global_teardown&) = delete;
62 
63  /**
64  * Performs all the teardown calls immediately. Further calls to this
65  * function does nothing.
66  */
67  void perform_teardown();
68 
69  /**
70  * Performs the teardown if teardown has not yet been performed.
71  */
72  ~global_teardown();
73 
74  static global_teardown& get_instance();
75  private:
76  bool teardown_performed = false;
77 };
78 
79 namespace teardown_impl {
80 extern EXPORT global_teardown teardown_instance;
81 }
82 
83 } // turi
84 #endif
void EXPORT configure_global_environment(std::string argv0)