1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#pragma once
#include "Audio/IAudioDevice.h"
#include "Threading/IThreadPool.h"
#include "Graphics/IGfxCapabilities.h"
namespace nCine
{
/** @brief Provides base services to requesting classes */
class ServiceLocator
{
public:
/** @brief Returns reference to the current audio device instance */
IAudioDevice& GetAudioDevice() {
return *audioDevice_;
}
/** @brief Registers an audio device provider */
void RegisterAudioDevice(std::unique_ptr<IAudioDevice> service);
/** @brief Unregisters the audio device provider and reinstates the null one */
void UnregisterAudioDevice();
/** @brief Returns reference to the current thread pool instance */
IThreadPool& GetThreadPool() {
return *threadPool_;
}
/** @brief Registers a thread pool provider */
void RegisterThreadPool(std::unique_ptr<IThreadPool> service);
/** @brief Unregisters the thread pool provider and reinstates the null one */
void UnregisterThreadPool();
/** @brief Returns reference to the current graphics capabilities instance */
const IGfxCapabilities& GetGfxCapabilities() {
return *gfxCapabilities_;
}
/** @brief Registers a graphics capabilities provider */
void RegisterGfxCapabilities(std::unique_ptr<IGfxCapabilities> service);
/** @brief Unregisters the graphics capabilitiesprovider and reinstates the null one */
void UnregisterGfxCapabilities();
/** @brief Unregisters every registered service and reinstates null ones */
void UnregisterAll();
private:
IAudioDevice* audioDevice_;
std::unique_ptr<IAudioDevice> registeredAudioDevice_;
NullAudioDevice nullAudioDevice_;
IThreadPool* threadPool_;
std::unique_ptr<IThreadPool> registeredThreadPool_;
NullThreadPool nullThreadPool_;
IGfxCapabilities* gfxCapabilities_;
std::unique_ptr<IGfxCapabilities> registeredGfxCapabilities_;
NullGfxCapabilities nullGfxCapabilities_;
ServiceLocator();
ServiceLocator(const ServiceLocator&) = delete;
ServiceLocator& operator=(const ServiceLocator&) = delete;
friend ServiceLocator& theServiceLocator();
};
ServiceLocator& theServiceLocator();
}
|