Coverage Report

Created: 2025-07-23 07:02

/src/wxwidgets/include/wx/module.h
Line
Count
Source (jump to first uncovered line)
1
/////////////////////////////////////////////////////////////////////////////
2
// Name:        wx/module.h
3
// Purpose:     Modules handling
4
// Author:      Wolfram Gloger/adapted by Guilhem Lavaux
5
// Created:     04/11/98
6
// Copyright:   (c) Wolfram Gloger and Guilhem Lavaux
7
// Licence:     wxWindows licence
8
/////////////////////////////////////////////////////////////////////////////
9
10
#ifndef _WX_MODULE_H_
11
#define _WX_MODULE_H_
12
13
#include "wx/object.h"
14
#include "wx/string.h"
15
#include "wx/vector.h"
16
17
class wxModule;
18
19
typedef wxVector<wxModule*> wxModuleList;
20
21
// declaring a class derived from wxModule will automatically create an
22
// instance of this class on program startup, call its OnInit() method and call
23
// OnExit() on program termination (but only if OnInit() succeeded)
24
class WXDLLIMPEXP_BASE wxModule : public wxObject
25
{
26
public:
27
0
    wxModule() = default;
28
0
    virtual ~wxModule() = default;
29
30
    // if module init routine returns false the application
31
    // will fail to startup
32
33
0
    bool Init() { return OnInit(); }
34
0
    void Exit() { OnExit(); }
35
36
    // Override both of these
37
38
        // called on program startup
39
40
    virtual bool OnInit() = 0;
41
42
        // called just before program termination, but only if OnInit()
43
        // succeeded
44
45
    virtual void OnExit() = 0;
46
47
    static void RegisterModule(wxModule *module);
48
    static void RegisterModules();
49
    static bool InitializeModules();
50
    static void CleanUpModules();
51
0
    static bool AreInitialized() { return ms_areInitialized; }
52
53
    // used by wxObjectLoader when unloading shared libs's
54
55
    static void UnregisterModule(wxModule *module);
56
57
protected:
58
    static wxModuleList ms_modules;
59
60
    static bool ms_areInitialized;
61
62
    // the function to call from constructor of a deriving class add module
63
    // dependency which will be initialized before the module and unloaded
64
    // after that
65
    void AddDependency(wxClassInfo *dep)
66
0
    {
67
0
        wxCHECK_RET( dep, wxT("null module dependency") );
68
0
69
0
        m_dependencies.push_back(dep);
70
0
    }
71
72
    // same as the version above except it will look up wxClassInfo by name on
73
    // its own. Note that className must be ASCII
74
    void AddDependency(const char *className)
75
0
    {
76
0
        m_namedDependencies.push_back(wxASCII_STR(className));
77
0
    }
78
79
80
private:
81
    // initialize module and Append it to initializedModules list recursively
82
    // calling itself to satisfy module dependencies if needed
83
    static bool
84
    DoInitializeModule(wxModule *module, wxModuleList &initializedModules);
85
86
    // cleanup the modules in the specified list (which may not contain all
87
    // modules if we're called during initialization because not all modules
88
    // could be initialized) and also empty ms_modules itself
89
    static void DoCleanUpModules(const wxModuleList& modules);
90
91
    // resolve all named dependencies and add them to the normal m_dependencies
92
    bool ResolveNamedDependencies();
93
94
95
    // module dependencies: contains wxClassInfo pointers for all modules which
96
    // must be initialized before this one
97
    typedef wxVector<wxClassInfo*> wxArrayClassInfo;
98
    wxArrayClassInfo m_dependencies;
99
100
    // and the named dependencies: those will be resolved during run-time and
101
    // added to m_dependencies
102
    wxVector<wxString> m_namedDependencies;
103
104
    // used internally while initializing/cleaning up modules
105
    enum
106
    {
107
        State_Registered,   // module registered but not initialized yet
108
        State_Initializing, // we're initializing this module but not done yet
109
        State_Initialized   // module initialized successfully
110
    } m_state;
111
112
113
    wxDECLARE_CLASS(wxModule);
114
};
115
116
#endif // _WX_MODULE_H_