Version: 3.2.5

#include <wx/module.h>

+ Inheritance diagram for wxModule:

Detailed Description

The module system is a very simple mechanism to allow applications (and parts of wxWidgets itself) to define initialization and cleanup functions that are automatically called on wxWidgets startup and exit.

To define a new kind of module, derive a class from wxModule, override the wxModule::OnInit and wxModule::OnExit functions, and add the wxDECLARE_DYNAMIC_CLASS and wxIMPLEMENT_DYNAMIC_CLASS to header and implementation files (which can be the same file). On initialization, wxWidgets will find all classes derived from wxModule, create an instance of each, and call each wxModule::OnInit function. On exit, wxWidgets will call the wxModule::OnExit function for each module instance.

Note that your module class does not have to be in a header file.

For example:

// A module to allow DDE initialization/cleanup
// without calling these functions from app.cpp or from
// the user's application.
class wxDDEModule: public wxModule
{
public:
wxDDEModule() { }
virtual bool OnInit() { wxDDEInitialize(); return true; };
virtual void OnExit() { wxDDECleanUp(); };
private:
};
// Another module which uses DDE in its OnInit()
class MyModule: public wxModule
{
public:
MyModule() { AddDependency(wxCLASSINFO(wxDDEModule)); }
virtual bool OnInit() { ... code using DDE ... }
virtual void OnExit() { ... }
private:
};
// Another module which uses DDE in its OnInit()
// but uses a named dependency
class MyModule2: public wxModule
{
public:
MyModule2() { AddDependency("wxDDEModule"); }
virtual bool OnInit() { ... code using DDE ... }
virtual void OnExit() { ... }
private:
};
The module system is a very simple mechanism to allow applications (and parts of wxWidgets itself) to...
Definition: module.h:78
virtual bool OnInit()=0
Provide this function with appropriate initialization for your module.
void AddDependency(wxClassInfo *dep)
Call this function from the constructor of the derived class.
virtual void OnExit()=0
Provide this function with appropriate cleanup for your module.
void wxDDEInitialize()
Initializes the DDE system.
void wxDDECleanUp()
Called when wxWidgets exits, to clean up the DDE system.
#define wxIMPLEMENT_DYNAMIC_CLASS(className, baseClassName)
Used in a C++ implementation file to complete the declaration of a class that has run-time type infor...
Definition: object.h:788
#define wxDECLARE_DYNAMIC_CLASS(className)
Used inside a class declaration to make the class known to wxWidgets RTTI system and also declare tha...
Definition: object.h:730
#define wxCLASSINFO(className)
Returns a pointer to the wxClassInfo object associated with this class.
Definition: object.h:682

Library:  wxBase
Category:  Application and Process Management

Public Member Functions

 wxModule ()
 Constructs a wxModule object. More...
 
virtual ~wxModule ()
 Destructor. More...
 
virtual void OnExit ()=0
 Provide this function with appropriate cleanup for your module. More...
 
virtual bool OnInit ()=0
 Provide this function with appropriate initialization for your module. More...
 
- Public Member Functions inherited from wxObject
 wxObject ()
 Default ctor; initializes to NULL the internal reference data. More...
 
 wxObject (const wxObject &other)
 Copy ctor. More...
 
virtual ~wxObject ()
 Destructor. More...
 
virtual wxClassInfoGetClassInfo () const
 This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar). More...
 
wxObjectRefDataGetRefData () const
 Returns the wxObject::m_refData pointer, i.e. the data referenced by this object. More...
 
bool IsKindOf (const wxClassInfo *info) const
 Determines whether this class is a subclass of (or the same class as) the given class. More...
 
bool IsSameAs (const wxObject &obj) const
 Returns true if this object has the same data pointer as obj. More...
 
void Ref (const wxObject &clone)
 Makes this object refer to the data in clone. More...
 
void SetRefData (wxObjectRefData *data)
 Sets the wxObject::m_refData pointer. More...
 
void UnRef ()
 Decrements the reference count in the associated data, and if it is zero, deletes the data. More...
 
void UnShare ()
 This is the same of AllocExclusive() but this method is public. More...
 
void operator delete (void *buf)
 The delete operator is defined for debugging versions of the library only, when the identifier __WXDEBUG__ is defined. More...
 
void * operator new (size_t size, const wxString &filename=NULL, int lineNum=0)
 The new operator is defined for debugging versions of the library only, when the identifier __WXDEBUG__ is defined. More...
 

Protected Member Functions

void AddDependency (wxClassInfo *dep)
 Call this function from the constructor of the derived class. More...
 
void AddDependency (const char *classname)
 Call this function from the constructor of the derived class. More...
 
- Protected Member Functions inherited from wxObject
void AllocExclusive ()
 Ensure that this object's data is not shared with any other object. More...
 
virtual wxObjectRefDataCreateRefData () const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it. More...
 
virtual wxObjectRefDataCloneRefData (const wxObjectRefData *data) const
 Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data. More...
 

Additional Inherited Members

- Protected Attributes inherited from wxObject
wxObjectRefDatam_refData
 Pointer to an object which is the object's reference-counted data. More...
 

Constructor & Destructor Documentation

◆ wxModule()

wxModule::wxModule ( )

Constructs a wxModule object.

◆ ~wxModule()

virtual wxModule::~wxModule ( )
virtual

Destructor.

Member Function Documentation

◆ AddDependency() [1/2]

void wxModule::AddDependency ( const char *  classname)
protected

Call this function from the constructor of the derived class.

This overload allows a dependency to be added by name without access to the class info.

This is useful when a module is declared entirely in a source file and there is no header for the declaration of the module needed by wxCLASSINFO(), however errors are not detected until run-time, instead of compile-time, then. Note that circular dependencies are detected and result in a fatal error.

Parameters
classnameThe class name of the dependent module.

◆ AddDependency() [2/2]

void wxModule::AddDependency ( wxClassInfo dep)
protected

Call this function from the constructor of the derived class.

dep must be the wxCLASSINFO() of a wxModule-derived class and the corresponding module will be loaded before and unloaded after this module.

Parameters
depThe class information object for the dependent module.

◆ OnExit()

virtual void wxModule::OnExit ( )
pure virtual

Provide this function with appropriate cleanup for your module.

◆ OnInit()

virtual bool wxModule::OnInit ( )
pure virtual

Provide this function with appropriate initialization for your module.

If the function returns false, wxWidgets will exit immediately.