Skip to content

Commit

Permalink
#5343: Use a proxy object to cache the reference in the Global*() mod…
Browse files Browse the repository at this point in the history
…ule accessor wrappers.

When the MODULE_REFERENCES_SUPPORT_INVALIDATION preprocessor symbol is defined, it will check the cached reference for validity on every access.
  • Loading branch information
codereader committed Sep 27, 2020
1 parent e562400 commit 32bcde9
Show file tree
Hide file tree
Showing 62 changed files with 199 additions and 436 deletions.
8 changes: 2 additions & 6 deletions include/iaasfile.h
Expand Up @@ -153,10 +153,6 @@ const char* const MODULE_AASFILEMANAGER("ZAasFileManager");
// Application-wide Accessor to the global AAS file manager
inline map::IAasFileManager& GlobalAasFileManager()
{
// Cache the reference locally
static map::IAasFileManager& _manager(
*std::static_pointer_cast<map::IAasFileManager>(
module::GlobalModuleRegistry().getModule(MODULE_AASFILEMANAGER))
);
return _manager;
static module::InstanceReference<map::IAasFileManager> _reference(MODULE_AASFILEMANAGER);
return _reference;
}
9 changes: 2 additions & 7 deletions include/ibrush.h
Expand Up @@ -322,11 +322,6 @@ const char* const MODULE_BRUSHCREATOR("Doom3BrushCreator");

inline brush::BrushCreator& GlobalBrushCreator()
{
// Cache the reference locally
static brush::BrushCreator& _brushCreator(
*std::static_pointer_cast<brush::BrushCreator>(
module::GlobalModuleRegistry().getModule(MODULE_BRUSHCREATOR)
)
);
return _brushCreator;
static module::InstanceReference<brush::BrushCreator> _reference(MODULE_BRUSHCREATOR);
return _reference;
}
9 changes: 2 additions & 7 deletions include/icameraview.h
Expand Up @@ -101,11 +101,6 @@ const char* const MODULE_CAMERA_MANAGER("CameraManager");
// Module accessor
inline camera::ICameraViewManager& GlobalCameraManager()
{
// Cache the reference locally
static camera::ICameraViewManager& _instance(
*std::static_pointer_cast<camera::ICameraViewManager>(
module::GlobalModuleRegistry().getModule(MODULE_CAMERA_MANAGER)
)
);
return _instance;
static module::InstanceReference<camera::ICameraViewManager> _reference(MODULE_CAMERA_MANAGER);
return _reference;
}
9 changes: 2 additions & 7 deletions include/iclipboard.h
Expand Up @@ -33,11 +33,6 @@ const char* const MODULE_CLIPBOARD("Clipboard");

inline radiant::IClipboard& GlobalClipboard()
{
// Cache the reference locally
static radiant::IClipboard& _instance(
*std::static_pointer_cast<radiant::IClipboard>(
module::GlobalModuleRegistry().getModule(MODULE_CLIPBOARD)
)
);
return _instance;
static module::InstanceReference<radiant::IClipboard> _reference(MODULE_CLIPBOARD);
return _reference;
}
9 changes: 2 additions & 7 deletions include/iclipper.h
Expand Up @@ -73,11 +73,6 @@ class IClipper :
// The accessor for the clipper module
inline IClipper& GlobalClipper()
{
// Cache the reference locally
static IClipper& _clipper(
*std::static_pointer_cast<IClipper>(
module::GlobalModuleRegistry().getModule(MODULE_CLIPPER)
)
);
return _clipper;
static module::InstanceReference<IClipper> _reference(MODULE_CLIPPER);
return _reference;
}
9 changes: 2 additions & 7 deletions include/icolourscheme.h
Expand Up @@ -82,11 +82,6 @@ const char* const MODULE_COLOURSCHEME_MANAGER("ColourSchemeManager");

inline colours::IColourSchemeManager& GlobalColourSchemeManager()
{
// Cache the reference locally
static colours::IColourSchemeManager& _instance(
*std::static_pointer_cast<colours::IColourSchemeManager>(
module::GlobalModuleRegistry().getModule(MODULE_COLOURSCHEME_MANAGER)
)
);
return _instance;
static module::InstanceReference<colours::IColourSchemeManager> _reference(MODULE_COLOURSCHEME_MANAGER);
return _reference;
}
9 changes: 2 additions & 7 deletions include/icommandsystem.h
Expand Up @@ -319,11 +319,6 @@ const char* const MODULE_COMMANDSYSTEM("CommandSystem");
// This is the accessor for the commandsystem
inline cmd::ICommandSystem& GlobalCommandSystem()
{
// Cache the reference locally
static cmd::ICommandSystem& _cmdSystem(
*std::static_pointer_cast<cmd::ICommandSystem>(
module::GlobalModuleRegistry().getModule(MODULE_COMMANDSYSTEM)
)
);
return _cmdSystem;
static module::InstanceReference<cmd::ICommandSystem> _reference(MODULE_COMMANDSYSTEM);
return _reference;
}
9 changes: 2 additions & 7 deletions include/icounter.h
Expand Up @@ -44,11 +44,6 @@ class ICounterManager :

inline ICounterManager& GlobalCounters()
{
// Cache the reference locally
static ICounterManager& _counters(
*std::static_pointer_cast<ICounterManager>(
module::GlobalModuleRegistry().getModule(MODULE_COUNTER)
)
);
return _counters;
static module::InstanceReference<ICounterManager> _reference(MODULE_COUNTER);
return _reference;
}
12 changes: 4 additions & 8 deletions include/ieclass.h
Expand Up @@ -446,12 +446,8 @@ class IEntityClassManager :
*
* \ingroup eclass
*/
inline IEntityClassManager& GlobalEntityClassManager() {
// Cache the reference locally
static IEntityClassManager& _eclassMgr(
*std::static_pointer_cast<IEntityClassManager>(
module::GlobalModuleRegistry().getModule(MODULE_ECLASSMANAGER)
)
);
return _eclassMgr;
inline IEntityClassManager& GlobalEntityClassManager()
{
static module::InstanceReference<IEntityClassManager> _reference(MODULE_ECLASSMANAGER);
return _reference;
}
9 changes: 2 additions & 7 deletions include/ieditstopwatch.h
Expand Up @@ -48,11 +48,6 @@ const char* const MODULE_EDITING_STOPWATCH("EditingStopwatch");

inline map::IMapEditStopwatch& GlobalMapEditStopwatch()
{
// Cache the reference locally
static map::IMapEditStopwatch& _instance(
*std::static_pointer_cast<map::IMapEditStopwatch>(
module::GlobalModuleRegistry().getModule(MODULE_EDITING_STOPWATCH)
)
);
return _instance;
static module::InstanceReference<map::IMapEditStopwatch> _reference(MODULE_EDITING_STOPWATCH);
return _reference;
}
9 changes: 2 additions & 7 deletions include/ientity.h
Expand Up @@ -403,11 +403,6 @@ class IEntityModule :

inline IEntityModule& GlobalEntityModule()
{
// Cache the reference locally
static IEntityModule& _entityCreator(
*std::static_pointer_cast<IEntityModule>(
module::GlobalModuleRegistry().getModule(MODULE_ENTITY)
)
);
return _entityCreator;
static module::InstanceReference<IEntityModule> _reference(MODULE_ENTITY);
return _reference;
}
11 changes: 3 additions & 8 deletions include/ientityinspector.h
Expand Up @@ -110,15 +110,10 @@ class IEntityInspector :

} // namespace ui

const std::string MODULE_ENTITYINSPECTOR("EntityInspector");
const char* const MODULE_ENTITYINSPECTOR("EntityInspector");

inline ui::IEntityInspector& GlobalEntityInspector()
{
// Cache the reference locally
static ui::IEntityInspector& _inspector(
*std::static_pointer_cast<ui::IEntityInspector>(
module::GlobalModuleRegistry().getModule(MODULE_ENTITYINSPECTOR)
)
);
return _inspector;
static module::InstanceReference<ui::IEntityInspector> _reference(MODULE_ENTITYINSPECTOR);
return _reference;
}
12 changes: 4 additions & 8 deletions include/ieventmanager.h
Expand Up @@ -179,12 +179,8 @@ class IEventManager :
typedef std::shared_ptr<IEventManager> IEventManagerPtr;

// This is the accessor for the event manager
inline IEventManager& GlobalEventManager() {
// Cache the reference locally
static IEventManager& _eventManager(
*std::static_pointer_cast<IEventManager>(
module::GlobalModuleRegistry().getModule(MODULE_EVENTMANAGER)
)
);
return _eventManager;
inline IEventManager& GlobalEventManager()
{
static module::InstanceReference<IEventManager> _reference(MODULE_EVENTMANAGER);
return _reference;
}
9 changes: 2 additions & 7 deletions include/ifilesystem.h
Expand Up @@ -200,11 +200,6 @@ const char* const MODULE_VIRTUALFILESYSTEM("VirtualFileSystem");

inline vfs::VirtualFileSystem& GlobalFileSystem()
{
// Cache the reference locally
static vfs::VirtualFileSystem& _vfs(
*std::static_pointer_cast<vfs::VirtualFileSystem>(
module::GlobalModuleRegistry().getModule(MODULE_VIRTUALFILESYSTEM)
)
);
return _vfs;
static module::InstanceReference<vfs::VirtualFileSystem> _reference(MODULE_VIRTUALFILESYSTEM);
return _reference;
}
9 changes: 2 additions & 7 deletions include/ifiletypes.h
Expand Up @@ -84,11 +84,6 @@ const char* const TYPE_MODEL_EXPORT = "modelexport";

inline IFileTypeRegistry& GlobalFiletypes()
{
// Cache the reference locally
static IFileTypeRegistry& _fileTypes(
*std::static_pointer_cast<IFileTypeRegistry>(
module::GlobalModuleRegistry().getModule(MODULE_FILETYPES)
)
);
return _fileTypes;
static module::InstanceReference<IFileTypeRegistry> _reference(MODULE_FILETYPES);
return _reference;
}
9 changes: 2 additions & 7 deletions include/ifilter.h
Expand Up @@ -220,11 +220,6 @@ class IFilterSystem :

inline filters::IFilterSystem& GlobalFilterSystem()
{
// Cache the reference locally
static filters::IFilterSystem& _filterSystem(
*std::static_pointer_cast<filters::IFilterSystem>(
module::GlobalModuleRegistry().getModule(MODULE_FILTERSYSTEM)
)
);
return _filterSystem;
static module::InstanceReference<filters::IFilterSystem> _reference(MODULE_FILTERSYSTEM);
return _reference;
}
11 changes: 3 additions & 8 deletions include/ifonts.h
Expand Up @@ -136,15 +136,10 @@ class IFontManager :

}

const std::string MODULE_FONTMANAGER("FontManager");
const char* const MODULE_FONTMANAGER("FontManager");

inline fonts::IFontManager& GlobalFontManager()
{
// Cache the reference locally
static fonts::IFontManager& _fontManager(
*std::static_pointer_cast<fonts::IFontManager>(
module::GlobalModuleRegistry().getModule(MODULE_FONTMANAGER)
)
);
return _fontManager;
static module::InstanceReference<fonts::IFontManager> _reference(MODULE_FONTMANAGER);
return _reference;
}
9 changes: 2 additions & 7 deletions include/igame.h
Expand Up @@ -133,11 +133,6 @@ typedef std::shared_ptr<IGameManager> IGameManagerPtr;
// This is the accessor for the game manager
inline game::IGameManager& GlobalGameManager()
{
// Cache the reference locally
static game::IGameManager& _gameManager(
*std::static_pointer_cast<game::IGameManager>(
module::GlobalModuleRegistry().getModule(MODULE_GAMEMANAGER)
)
);
return _gameManager;
static module::InstanceReference<game::IGameManager> _reference(MODULE_GAMEMANAGER);
return _reference;
}
18 changes: 4 additions & 14 deletions include/igl.h
Expand Up @@ -49,13 +49,8 @@ const char* const MODULE_SHARED_GL_CONTEXT("SharedGLContextHolder");

inline gl::ISharedGLContextHolder& GlobalOpenGLContext()
{
// Cache the reference locally
static gl::ISharedGLContextHolder& _instance(
*std::static_pointer_cast<gl::ISharedGLContextHolder>(
module::GlobalModuleRegistry().getModule(MODULE_SHARED_GL_CONTEXT)
)
);
return _instance;
static module::InstanceReference<gl::ISharedGLContextHolder> _reference(MODULE_SHARED_GL_CONTEXT);
return _reference;
}

const char* const MODULE_OPENGL("OpenGL");
Expand All @@ -80,11 +75,6 @@ class OpenGLBinding :

inline OpenGLBinding& GlobalOpenGL()
{
// Cache the reference locally
static OpenGLBinding& _openGL(
*std::static_pointer_cast<OpenGLBinding>(
module::GlobalModuleRegistry().getModule(MODULE_OPENGL)
)
);
return _openGL;
static module::InstanceReference<OpenGLBinding> _reference(MODULE_OPENGL);
return _reference;
}
9 changes: 2 additions & 7 deletions include/igrid.h
Expand Up @@ -89,11 +89,6 @@ class IGridManager :
// This is the accessor for the grid module
inline IGridManager& GlobalGrid()
{
// Cache the reference locally
static IGridManager& _grid(
*std::static_pointer_cast<IGridManager>(
module::GlobalModuleRegistry().getModule(MODULE_GRID)
)
);
return _grid;
static module::InstanceReference<IGridManager> _reference(MODULE_GRID);
return _reference;
}
8 changes: 2 additions & 6 deletions include/igui.h
Expand Up @@ -389,10 +389,6 @@ const char* const MODULE_GUIMANAGER("GuiManager");
// Application-wide Accessor to the global GUI manager
inline gui::IGuiManager& GlobalGuiManager()
{
// Cache the reference locally
static gui::IGuiManager& _manager(
*std::static_pointer_cast<gui::IGuiManager>(
module::GlobalModuleRegistry().getModule(MODULE_GUIMANAGER))
);
return _manager;
static module::InstanceReference<gui::IGuiManager> _reference(MODULE_GUIMANAGER);
return _reference;
}
9 changes: 2 additions & 7 deletions include/iimage.h
Expand Up @@ -89,11 +89,6 @@ const char* const MODULE_IMAGELOADER("ImageLoader");

inline const IImageLoader& GlobalImageLoader()
{
static IImageLoader& _imageLoader(
*std::static_pointer_cast<IImageLoader>(
module::GlobalModuleRegistry().getModule(MODULE_IMAGELOADER)
)
);

return _imageLoader;
static module::InstanceReference<IImageLoader> _reference(MODULE_IMAGELOADER);
return _reference;
}
9 changes: 2 additions & 7 deletions include/ilayer.h
Expand Up @@ -219,11 +219,6 @@ const char* const MODULE_LAYERS("LayerModule");

inline scene::ILayerModule& GlobalLayerModule()
{
// Cache the reference locally
static scene::ILayerModule& _layerModule(
*std::static_pointer_cast<scene::ILayerModule>(
module::GlobalModuleRegistry().getModule(MODULE_LAYERS)
)
);
return _layerModule;
static module::InstanceReference<scene::ILayerModule> _reference(MODULE_LAYERS);
return _reference;
}
9 changes: 2 additions & 7 deletions include/imainframe.h
Expand Up @@ -139,11 +139,6 @@ class IMainFrame :
// This is the accessor for the mainframe module
inline IMainFrame& GlobalMainFrame()
{
// Cache the reference locally
static IMainFrame& _mainFrame(
*std::static_pointer_cast<IMainFrame>(
module::GlobalModuleRegistry().getModule(MODULE_MAINFRAME)
)
);
return _mainFrame;
static module::InstanceReference<IMainFrame> _reference(MODULE_MAINFRAME);
return _reference;
}

0 comments on commit 32bcde9

Please sign in to comment.