AirInv Logo  0.1.2
C++ Simulated Airline Inventory Management System library
FacSupervisor.cpp
Go to the documentation of this file.
00001 // //////////////////////////////////////////////////////////////////////
00002 // Import section
00003 // //////////////////////////////////////////////////////////////////////
00004 // STL
00005 #include <cassert>
00006 // AIRINV
00007 #include <airinv/factory/FacBomAbstract.hpp>
00008 #include <airinv/factory/FacServiceAbstract.hpp>
00009 #include <airinv/factory/FacSupervisor.hpp>
00010 
00011 namespace AIRINV {
00012 
00013   FacSupervisor* FacSupervisor::_instance = NULL;
00014 
00015   // //////////////////////////////////////////////////////////////////////
00016   FacSupervisor::FacSupervisor () {
00017   }
00018     
00019   // //////////////////////////////////////////////////////////////////////
00020   FacSupervisor& FacSupervisor::instance() {
00021     if (_instance == NULL) {
00022       _instance = new FacSupervisor();
00023     }
00024 
00025     return *_instance;
00026   }
00027 
00028   // //////////////////////////////////////////////////////////////////////
00029   void FacSupervisor::
00030   registerBomFactory (FacBomAbstract* ioFacBomAbstract_ptr) {
00031     _bomPool.push_back (ioFacBomAbstract_ptr);
00032   }
00033 
00034   // //////////////////////////////////////////////////////////////////////
00035   void FacSupervisor::
00036   registerServiceFactory (FacServiceAbstract* ioFacServiceAbstract_ptr) {
00037     _svcPool.push_back (ioFacServiceAbstract_ptr);
00038   }
00039 
00040   // //////////////////////////////////////////////////////////////////////
00041   FacSupervisor::~FacSupervisor() {
00042     cleanBomLayer();
00043     cleanServiceLayer();
00044   }
00045 
00046   // //////////////////////////////////////////////////////////////////////
00047   void FacSupervisor::cleanBomLayer() {
00048     for (BomFactoryPool_T::const_iterator itFactory = _bomPool.begin();
00049          itFactory != _bomPool.end(); itFactory++) {
00050       const FacBomAbstract* currentFactory_ptr = *itFactory;
00051       assert (currentFactory_ptr != NULL);
00052 
00053       delete (currentFactory_ptr); currentFactory_ptr = NULL;
00054     }
00055 
00056     // Empty the pool of Bom Factories
00057     _bomPool.clear();
00058   }
00059 
00060   // //////////////////////////////////////////////////////////////////////
00061   void FacSupervisor::cleanServiceLayer() {
00062     for (ServiceFactoryPool_T::const_iterator itFactory = _svcPool.begin();
00063          itFactory != _svcPool.end(); itFactory++) {
00064       const FacServiceAbstract* currentFactory_ptr = *itFactory;
00065       assert (currentFactory_ptr != NULL);
00066       
00067       delete (currentFactory_ptr); currentFactory_ptr = NULL;
00068     }
00069     
00070     // Empty the pool of Service Factories
00071     _svcPool.clear();
00072   }
00073   
00074   // //////////////////////////////////////////////////////////////////////
00075   void FacSupervisor::cleanFactory () {
00076         if (_instance != NULL) {
00077                 _instance->cleanBomLayer();
00078                 _instance->cleanServiceLayer();
00079         }
00080     delete (_instance); _instance = NULL;
00081   }
00082 
00083 }