Coverage Report

Created: 2023-02-22 06:06

/src/wxwidgets/include/wx/init.h
Line
Count
Source (jump to first uncovered line)
1
///////////////////////////////////////////////////////////////////////////////
2
// Name:        wx/init.h
3
// Purpose:     wxWidgets initialization and finalization functions
4
// Author:      Vadim Zeitlin
5
// Modified by:
6
// Created:     29.06.2003
7
// Copyright:   (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
8
// Licence:     wxWindows licence
9
///////////////////////////////////////////////////////////////////////////////
10
11
#ifndef _WX_INIT_H_
12
#define _WX_INIT_H_
13
14
#include "wx/defs.h"
15
#include "wx/chartype.h"
16
17
// ----------------------------------------------------------------------------
18
// wxEntry helper functions which allow to have more fine grained control
19
// ----------------------------------------------------------------------------
20
21
// do common initialization, return true if ok (in this case wxEntryCleanup
22
// must be called later), otherwise the program can't use wxWidgets at all
23
//
24
// this function also creates wxTheApp as a side effect, if wxIMPLEMENT_APP
25
// hadn't been used a dummy default application object is created
26
//
27
// note that the parameters may be modified, this is why we pass them by
28
// reference!
29
extern bool WXDLLIMPEXP_BASE wxEntryStart(int& argc, wxChar **argv);
30
31
// free the resources allocated by the library in wxEntryStart() and shut it
32
// down (wxEntryStart() may be called again afterwards if necessary)
33
extern void WXDLLIMPEXP_BASE wxEntryCleanup();
34
35
36
// ----------------------------------------------------------------------------
37
// wxEntry: this function initializes the library, runs the main event loop
38
//          and cleans it up
39
// ----------------------------------------------------------------------------
40
41
// note that other, platform-specific, overloads of wxEntry may exist as well
42
// but this one always exists under all platforms
43
//
44
// returns the program exit code
45
extern int WXDLLIMPEXP_BASE wxEntry(int& argc, wxChar **argv);
46
47
// we overload wxEntry[Start]() to take "char **" pointers too
48
extern bool WXDLLIMPEXP_BASE wxEntryStart(int& argc, char **argv);
49
extern int WXDLLIMPEXP_BASE wxEntry(int& argc, char **argv);
50
51
// Under Windows we define additional wxEntry() overloads with signature
52
// compatible with WinMain() and not the traditional main().
53
#ifdef __WINDOWS__
54
    #include "wx/msw/init.h"
55
#endif
56
57
// ----------------------------------------------------------------------------
58
// Using the library without (explicit) application object: you may avoid using
59
// wxDECLARE_APP and wxIMPLEMENT_APP macros and call the functions below instead at
60
// the program startup and termination
61
// ----------------------------------------------------------------------------
62
63
// initialize the library (may be called as many times as needed, but each
64
// call to wxInitialize() must be matched by wxUninitialize())
65
extern bool WXDLLIMPEXP_BASE wxInitialize();
66
extern bool WXDLLIMPEXP_BASE wxInitialize(int& argc, wxChar **argv);
67
extern bool WXDLLIMPEXP_BASE wxInitialize(int& argc, char **argv);
68
69
// clean up -- the library can't be used any more after the last call to
70
// wxUninitialize()
71
extern void WXDLLIMPEXP_BASE wxUninitialize();
72
73
// create an object of this class on stack to initialize/cleanup the library
74
// automatically
75
class WXDLLIMPEXP_BASE wxInitializer
76
{
77
public:
78
    // initialize the library
79
    wxInitializer()
80
0
    {
81
0
        m_ok = wxInitialize();
82
0
    }
83
84
    wxInitializer(int& argc, wxChar **argv)
85
0
    {
86
0
        m_ok = wxInitialize(argc, argv);
87
0
    }
88
89
    wxInitializer(int& argc, char **argv)
90
0
    {
91
0
        m_ok = wxInitialize(argc, argv);
92
0
    }
93
94
    // has the initialization been successful? (explicit test)
95
0
    bool IsOk() const { return m_ok; }
96
97
    // has the initialization been successful? (implicit test)
98
0
    operator bool() const { return m_ok; }
99
100
    // dtor only does clean up if we initialized the library properly
101
0
    ~wxInitializer() { if ( m_ok ) wxUninitialize(); }
102
103
private:
104
    bool m_ok;
105
};
106
107
#endif // _WX_INIT_H_
108