RMOL Logo Get Revenue Management Optimisation Library at SourceForge.net. Fast, secure and Free Open Source software downloads
FacSupervisor.cpp
Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // C
00005 #include <assert.h>
00006 // RMOL
00007 #include <rmol/factory/FacBomAbstract.hpp>
00008 #include <rmol/factory/FacServiceAbstract.hpp>
00009 #include <rmol/factory/FacSupervisor.hpp>
00010 #include <rmol/service/Logger.hpp>
00011 
00012 namespace RMOL {
00013 
00014   FacSupervisor* FacSupervisor::_instance = NULL;
00015 
00016   // //////////////////////////////////////////////////////////////////////
00017   FacSupervisor& FacSupervisor::instance() {
00018     if (_instance == NULL) {
00019       _instance = new FacSupervisor();
00020     }
00021 
00022     return *_instance;
00023   }
00024 
00025   // //////////////////////////////////////////////////////////////////////
00026   void FacSupervisor::registerBomFactory (FacBomAbstract* ioFacAbstract_ptr) {
00027     _bomPool.push_back (ioFacAbstract_ptr);
00028   }
00029 
00030   // //////////////////////////////////////////////////////////////////////
00031   void FacSupervisor::
00032   registerServiceFactory (FacServiceAbstract* ioFacServiceAbstract_ptr) {
00033     _svcPool.push_back (ioFacServiceAbstract_ptr);
00034   }
00035 
00036   // //////////////////////////////////////////////////////////////////////
00037   void FacSupervisor::registerLoggerService (Logger* ioLogger_ptr) {
00038     _logger = ioLogger_ptr;
00039   }
00040 
00041   // //////////////////////////////////////////////////////////////////////
00042   FacSupervisor::~FacSupervisor() {
00043     cleanBomLayer();
00044     cleanServiceLayer();
00045     cleanLoggerService();
00046  }
00047 
00048   // //////////////////////////////////////////////////////////////////////
00049   void FacSupervisor::cleanBomLayer() {
00050     for (BomFactoryPool_T::const_iterator itFactory = _bomPool.begin();
00051          itFactory != _bomPool.end(); itFactory++) {
00052       const FacBomAbstract* currentFactory_ptr = *itFactory;
00053       assert (currentFactory_ptr != NULL);
00054 
00055       delete (currentFactory_ptr); currentFactory_ptr = NULL;
00056     }
00057 
00058     // Empty the pool of Bom Factories
00059     _bomPool.clear();
00060   }
00061 
00062   // //////////////////////////////////////////////////////////////////////
00063   void FacSupervisor::cleanServiceLayer() {
00064     for (ServiceFactoryPool_T::const_iterator itFactory = _svcPool.begin();
00065          itFactory != _svcPool.end(); itFactory++) {
00066       const FacServiceAbstract* currentFactory_ptr = *itFactory;
00067       assert (currentFactory_ptr != NULL);
00068 
00069       delete (currentFactory_ptr); currentFactory_ptr = NULL;
00070     }
00071 
00072     // Empty the pool of Service Factories
00073     _svcPool.clear();
00074   }
00075 
00076   // //////////////////////////////////////////////////////////////////////
00077   void FacSupervisor::cleanLoggerService() {
00078     delete _logger; _logger = NULL;
00079   }
00080   
00081   // //////////////////////////////////////////////////////////////////////
00082   void FacSupervisor::cleanFactory () {
00083         if (_instance != NULL) {
00084                 _instance->cleanBomLayer();
00085                 _instance->cleanServiceLayer();
00086         _instance->cleanLoggerService();
00087         }
00088     delete (_instance); _instance = NULL;
00089   }
00090 
00091 }