From: <qua...@us...> - 2010-02-08 09:22:28
|
Revision: 123 http://stdair.svn.sourceforge.net/stdair/?rev=123&view=rev Author: quannaus Date: 2010-02-08 09:22:21 +0000 (Mon, 08 Feb 2010) Log Message: ----------- [BOM] Delegated the creation of Inventory to the StdAir library. Modified Paths: -------------- trunk/stdair/stdair/command/sources.mk trunk/stdair/stdair/service/STDAIR_Service.cpp Added Paths: ----------- trunk/stdair/stdair/command/CmdBomManager.cpp trunk/stdair/stdair/command/CmdBomManager.hpp Added: trunk/stdair/stdair/command/CmdBomManager.cpp =================================================================== --- trunk/stdair/stdair/command/CmdBomManager.cpp (rev 0) +++ trunk/stdair/stdair/command/CmdBomManager.cpp 2010-02-08 09:22:21 UTC (rev 123) @@ -0,0 +1,106 @@ +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <cassert> +// StdAir +#include <stdair/bom/BomRoot.hpp> +#include <stdair/bom/AirlineFeatureSet.hpp> +#include <stdair/bom/AirlineFeature.hpp> +// Inventory: child of BomRoot, needed for creation of BomRoot +#include <stdair/bom/Inventory.hpp> +// Network: child of BomRoot, needed for creation of BomRoot +#include <stdair/bom/Network.hpp> +#include <stdair/bom/FlightDate.hpp> +#include <stdair/factory/FacSupervisor.hpp> +#include <stdair/factory/FacBomContent.hpp> +#include <stdair/command/CmdBomManager.hpp> +#include <stdair/service/Logger.hpp> + +namespace stdair { + + // ////////////////////////////////////////////////////////////////////// + void CmdBomManager::initAirlineFeatureSet (BomRoot& ioBomRoot) { + // Initialise the set of required airline features + AirlineFeatureSet& lAirlineFeatureSet = + FacBomContent::instance().create<AirlineFeatureSet>(); + + // Set the AirlineFeatureSet for the BomRoot. + ioBomRoot.setAirlineFeatureSet (&lAirlineFeatureSet); + } + + // ////////////////////////////////////////////////////////////////////// + void CmdBomManager:: + addAirlineFeature (BomRoot& ioBomRoot, + const AirlineCode_T& iAirlineCode) { + + // Initialise an AirlineFeature object + AirlineFeatureKey_T lAirlineFeatureKey (iAirlineCode); + AirlineFeature& lAirlineFeature = FacBomContent:: + instance().create<AirlineFeature> (lAirlineFeatureKey); + + // Retrieve the AirlineFeatureSet object + AirlineFeatureSet& lAirlineFeatureSet = ioBomRoot.getAirlineFeatureSet(); + + // Add the AirlineFeature object to its AirlineFeatureSet parent + FacBomContent::linkWithParent<AirlineFeature> (lAirlineFeature, + lAirlineFeatureSet); + } + + // ////////////////////////////////////////////////////////////////////// + Inventory& CmdBomManager:: + createInventoryInternal (BomRoot& ioBomRoot, + const AirlineCode_T& iAirlineCode) { + InventoryKey_T lInventoryKey (iAirlineCode); + + // Instantiate an Inventory object with the given airline code + Inventory& lInventory = + FacBomContent::instance().create<Inventory> (lInventoryKey); + + // Link the created inventory with the bom root. + FacBomContent::linkWithParent<Inventory> (lInventory, ioBomRoot); + + return lInventory; + } + + // ////////////////////////////////////////////////////////////////////// + Inventory& CmdBomManager:: + getOrCreateInventory (BomRoot& ioBomRoot, + const AirlineCode_T& iAirlineCode) { + Inventory* lInventory_ptr = ioBomRoot.getInventory (iAirlineCode); + + // If there is no Inventory object for that airline already, create one + if (lInventory_ptr == NULL) { + const InventoryKey_T lInventoryKey (iAirlineCode); + + + // Instantiate an Inventory object with the given airline code + lInventory_ptr = &createInventoryInternal (ioBomRoot, iAirlineCode); + assert (lInventory_ptr != NULL); + + // Set the AirlineFeature for the inventory. + addAirlineFeature (ioBomRoot, iAirlineCode); + + // TODO: find a more elegant way to link the AirlineFeature back to the + // Inventory object + + // Link the AirlineFeature with the Inventory object + const AirlineFeatureSet& lAirlineFeatureSet = + ioBomRoot.getAirlineFeatureSet (); + const AirlineFeature* lAirlineFeature_ptr = + lAirlineFeatureSet.getAirlineFeature (iAirlineCode); + + if (lAirlineFeature_ptr == NULL) { + STDAIR_LOG_ERROR (lAirlineFeatureSet.display() + << "Needed airline code: " << iAirlineCode); + assert (false); + } + + lInventory_ptr->setAirlineFeature (lAirlineFeature_ptr); + } + assert (lInventory_ptr != NULL); + + return *lInventory_ptr; + } + +} Added: trunk/stdair/stdair/command/CmdBomManager.hpp =================================================================== --- trunk/stdair/stdair/command/CmdBomManager.hpp (rev 0) +++ trunk/stdair/stdair/command/CmdBomManager.hpp 2010-02-08 09:22:21 UTC (rev 123) @@ -0,0 +1,56 @@ +#ifndef __STDAIR_CMD_CMDBOMMANAGER_HPP +#define __STDAIR_CMD_CMDBOMMANAGER_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// StdAir +#include <stdair/STDAIR_Types.hpp> +#include <stdair/command/CmdAbstract.hpp> + +namespace stdair { + + // Forward declarations + class BomRoot; + class Inventory; + + /** Class wrapping utility functions for handling the BOM tree objects. */ + class CmdBomManager : public CmdAbstract { + public: + + /** If needed, create the Inventory corresponding to the given airline code + (Inventory key), link it to the BomRoot object and to the + associated AirlineFeature object, itself retrieved from the + AirlineFeatureSet object. + Otherwise, just retrieve the reference on the existing Inventory object + corresponding to the given airline code. + <br>If not existing, a ObjectNotFoundException exception is thrown. + @param BomRoot& Root of the BOM tree. + @param const AirlineCode_T& Airline code for the inventory to be + created . */ + static Inventory& getOrCreateInventory (BomRoot&, const AirlineCode_T&); + + /** Initialise the AirlineFeatureSet object, and attach it to the + BomRoot. + @param BomRoot& Root of the BOM tree. */ + static void initAirlineFeatureSet (BomRoot&); + + /** Add the airline-specific AirlineFeature object to its AirlineFeatureSet + parent. + @param BomRoot& Root of the BOM tree. + @param const AirlineCode_T& Airline code for the inventory to be + created . */ + static void addAirlineFeature (BomRoot&, const AirlineCode_T& iAirlineCode); + + private: + // ///////////////////// Internal support methods //////////////////////// + /** Create the Inventory corresponding to the given airline code + (Inventory key). + @param BomRoot& Root of the BOM tree. + @param const AirlineCode_T& Airline code for the inventory to be + created . */ + static Inventory& createInventoryInternal (BomRoot&, const AirlineCode_T&); + }; + +} +#endif // ___STDAIR_CMD_CMDBOMMANAGER_HPP Modified: trunk/stdair/stdair/command/sources.mk =================================================================== --- trunk/stdair/stdair/command/sources.mk 2010-02-07 20:06:07 UTC (rev 122) +++ trunk/stdair/stdair/command/sources.mk 2010-02-08 09:22:21 UTC (rev 123) @@ -1,6 +1,8 @@ cmd_h_sources = \ $(top_srcdir)/stdair/command/CmdAbstract.hpp \ + $(top_srcdir)/stdair/command/CmdBomManager.hpp \ $(top_srcdir)/stdair/command/DBManagerForAirlines.hpp cmd_cc_sources = \ $(top_srcdir)/stdair/command/CmdAbstract.cpp \ + $(top_srcdir)/stdair/command/CmdBomManager.cpp \ $(top_srcdir)/stdair/command/DBManagerForAirlines.cpp Modified: trunk/stdair/stdair/service/STDAIR_Service.cpp =================================================================== --- trunk/stdair/stdair/service/STDAIR_Service.cpp 2010-02-07 20:06:07 UTC (rev 122) +++ trunk/stdair/stdair/service/STDAIR_Service.cpp 2010-02-08 09:22:21 UTC (rev 123) @@ -7,15 +7,11 @@ #include <stdair/basic/BasChronometer.hpp> #include <stdair/bom/BomManager.hpp> // for display() #include <stdair/bom/BomRoot.hpp> -#include <stdair/bom/AirlineFeatureSet.hpp> -#include <stdair/bom/AirlineFeature.hpp> -// Inventory: child of BomRoot, needed for creation of BomRoot -#include <stdair/bom/Inventory.hpp> -// Network: child of BomRoot, needed for creation of BomRoot #include <stdair/bom/Network.hpp> -#include <stdair/bom/FlightDate.hpp> +#include <stdair/bom/Inventory.hpp> #include <stdair/factory/FacSupervisor.hpp> #include <stdair/factory/FacBomContent.hpp> +#include <stdair/command/CmdBomManager.hpp> #include <stdair/service/Logger.hpp> #include <stdair/service/DBSessionManager.hpp> #include <stdair/STDAIR_Service.hpp> @@ -91,32 +87,16 @@ } // ////////////////////////////////////////////////////////////////////// - void STDAIR_Service::initAirlineFeatureSet () { - // Initialise the set of required airline features - stdair::AirlineFeatureSet& lAirlineFeatureSet = - stdair::FacBomContent::instance().create<stdair::AirlineFeatureSet>(); - - // Set the AirlineFeatureSet for the BomRoot. - _bomRoot.setAirlineFeatureSet (&lAirlineFeatureSet); + void STDAIR_Service::initAirlineFeatureSet () { + // Delegate to the dedicated command + CmdBomManager::initAirlineFeatureSet (_bomRoot); } // ////////////////////////////////////////////////////////////////////// void STDAIR_Service:: addAirlineFeature (const AirlineCode_T& iAirlineCode) const { - - // Initialise an AirlineFeature object - stdair::AirlineFeatureKey_T lAirlineFeatureKey (iAirlineCode); - stdair::AirlineFeature& lAirlineFeature = stdair::FacBomContent:: - instance().create<stdair::AirlineFeature> (lAirlineFeatureKey); - - // Retrieve the AirlineFeatureSet object - stdair::AirlineFeatureSet& lAirlineFeatureSet = - _bomRoot.getAirlineFeatureSet(); - - // Add the AirlineFeature object to its AirlineFeatureSet parent - stdair::FacBomContent:: - linkWithParent<stdair::AirlineFeature> (lAirlineFeature, - lAirlineFeatureSet); + // Delegate to the dedicated command + CmdBomManager::addAirlineFeature (_bomRoot, iAirlineCode); } // ////////////////////////////////////////////////////////////////////// @@ -139,42 +119,19 @@ return *lInventory_ptr; } + /** + Note that the AirlineFeature is linked both to the Inventory + and to the AirlineFeatureSet, which in turn is linked to the BomRoot. + There is therefore a duplication of the structure links. + */ + // ////////////////////////////////////////////////////////////////////// Inventory& STDAIR_Service:: createInventory (const AirlineCode_T& iAirlineCode) const { - Inventory* lInventory_ptr = _bomRoot.getInventory (iAirlineCode); - - // If there is no Inventory object for that airline already, create one - if (lInventory_ptr == NULL) { - const stdair::InventoryKey_T lInventoryKey (iAirlineCode); - - // Instantiate an Inventory object with the given airline code - lInventory_ptr = - &stdair::FacBomContent::instance(). - create<stdair::Inventory> (lInventoryKey); - assert (lInventory_ptr != NULL); - - // Link the created inventory with the bom root. - stdair::FacBomContent::linkWithParent<stdair::Inventory> (*lInventory_ptr, - _bomRoot); - - // Set the AirlineFeature for the inventory. - const stdair::AirlineFeatureSet& lAirlineFeatureSet = - _bomRoot.getAirlineFeatureSet (); - const stdair::AirlineFeature* lAirlineFeature_ptr = - lAirlineFeatureSet.getAirlineFeature (iAirlineCode); - - // TODO: throw an exception? - if (lAirlineFeature_ptr == NULL) { - STDAIR_LOG_ERROR (lAirlineFeatureSet.display() - << "Needed airline code: " << iAirlineCode); - } - - lInventory_ptr->setAirlineFeature (lAirlineFeature_ptr); - } - assert (lInventory_ptr != NULL); - - return *lInventory_ptr; + // Delegate to the dedicated command + Inventory& oInventory = + CmdBomManager::getOrCreateInventory (_bomRoot, iAirlineCode); + return oInventory; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |