From: <den...@us...> - 2010-09-12 14:43:50
|
Revision: 319 http://stdair.svn.sourceforge.net/stdair/?rev=319&view=rev Author: denis_arnaud Date: 2010-09-12 14:43:43 +0000 (Sun, 12 Sep 2010) Log Message: ----------- [Test] Added a test sub-directory for Boost.Intrusive-based architecture. Modified Paths: -------------- trunk/stdair/test/archi_intru/archi.cpp trunk/stdair/test/archi_intru/sources.mk Added Paths: ----------- trunk/stdair/test/archi_intru/FacRelationShipRoot.hpp trunk/stdair/test/archi_intru/FacRelationShipRootAbstract.hpp trunk/stdair/test/archi_intru/FacSupervisor.cpp trunk/stdair/test/archi_intru/FacSupervisor.hpp trunk/stdair/test/archi_intru/RelationShipHolder.hpp Added: trunk/stdair/test/archi_intru/FacRelationShipRoot.hpp =================================================================== --- trunk/stdair/test/archi_intru/FacRelationShipRoot.hpp (rev 0) +++ trunk/stdair/test/archi_intru/FacRelationShipRoot.hpp 2010-09-12 14:43:43 UTC (rev 319) @@ -0,0 +1,75 @@ +#ifndef __INTRUSIVE_FAC_FACRELATIONSHIPHOLDER_HPP +#define __INTRUSIVE_FAC_FACRELATIONSHIPHOLDER_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// Boost.Intrusive +#include <boost/intrusive/list.hpp> +#include <boost/intrusive/set.hpp> +// Local +#include <test/archi_intru/FacSupervisor.hpp> +#include <test/archi_intru/RelationShipHolder.hpp> + +/** Alias for the boost::intrusive namespace. */ +namespace bi = boost::intrusive; + +namespace stdair { + + /** Class holding the list of all the relationship objects of a given type. */ + template <typename FIRST_BOM, typename SECOND_BOM> + class FacRelationShipRoot { + public: + // /////////////////////////////////////////// + /** Type definition for a list of relationship holder objects. */ + typedef bi::list<RelationShipHolder<FIRST_BOM, + SECOND_BOM> > RelationShipHolderList_T; + /** Type definition for a set of relationship holder objects. */ + typedef bi::set<RelationShipHolder<FIRST_BOM, + SECOND_BOM> > RelationShipHolderSet_T; + // /////////////////////////////////////////// + + public: + /** Provide the unique instance. + <br>The singleton is instantiated when first used. + @return FacRelationShipRoot& */ + static FacRelationShipRoot& instance () { + if (_instance == NULL) { + _instance = new FacRelationShipRoot (); + assert (_instance != NULL); + + FacSupervisor::instance().registerFacRelationShipRoot (_instance); + } + return *_instance; + } + + public: + /** Add a child/sibling to the dedicated list of the parent/sibling. */ + static void addToList (FIRST_BOM& ioFirstBom, SECOND_BOM& ioSecondBom) { + instance().addToListImpl (ioFirstBom, ioSecondBom); + } + + /** Add a child/sibling to the dedicated list of the parent/sibling. */ + void addToListImpl (FIRST_BOM& ioFirstBom, SECOND_BOM& ioSecondBom) { + _relationShipHolderList.push_back (ioFirstBom, ioSecondBom); + _relationShipHolderSet.insert (ioFirstBom, ioSecondBom); + } + + private: + /** List of relationship holder objects. */ + RelationShipHolderList_T _relationShipHolderList; + /** Set of relationship holder objects. */ + RelationShipHolderSet_T _relationShipHolderSet; + + private: + /** The unique instance. */ + static FacRelationShipRoot* _instance; + }; + + // //////////////////////////////////////////////////////////////////// + template <typename FIRST_BOM, typename SECOND_BOM> + FacRelationShipRoot<FIRST_BOM, SECOND_BOM>* + FacRelationShipRoot<FIRST_BOM, SECOND_BOM>::_instance = NULL; + +} +#endif // __INTRUSIVE_FAC_FACRELATIONSHIPHOLDER_HPP Added: trunk/stdair/test/archi_intru/FacRelationShipRootAbstract.hpp =================================================================== --- trunk/stdair/test/archi_intru/FacRelationShipRootAbstract.hpp (rev 0) +++ trunk/stdair/test/archi_intru/FacRelationShipRootAbstract.hpp 2010-09-12 14:43:43 UTC (rev 319) @@ -0,0 +1,29 @@ +#ifndef __INTRUSIVE_BOM_RELATIONSHIPABSTRACT_HPP +#define __INTRUSIVE_BOM_RELATIONSHIPABSTRACT_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <iosfwd> +#include <string> +// StdAir +#include <stdair/STDAIR_Types.hpp> + +namespace stdair { + + /** + * @brief Base class for the relation ship objects + */ + class FacRelationShipRootAbstract { + protected: + /** Protected Default Constructor to ensure this class is abtract. */ + FacRelationShipRootAbstract () {} + FacRelationShipRootAbstract (const FacRelationShipRootAbstract&) {} + public: + /** Destructor. */ + virtual ~FacRelationShipRootAbstract() {} + }; + +} +#endif // __INTRUSIVE_BOM_RELATIONSHIPABSTRACT_HPP Added: trunk/stdair/test/archi_intru/FacSupervisor.cpp =================================================================== --- trunk/stdair/test/archi_intru/FacSupervisor.cpp (rev 0) +++ trunk/stdair/test/archi_intru/FacSupervisor.cpp 2010-09-12 14:43:43 UTC (rev 319) @@ -0,0 +1,57 @@ +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <cassert> +// Local +#include <test/archi_intru/FacRelationShipRootAbstract.hpp> +#include <test/archi_intru/FacSupervisor.hpp> + +namespace stdair { + + FacSupervisor* FacSupervisor::_instance = NULL; + + // ////////////////////////////////////////////////////////////////////// + FacSupervisor& FacSupervisor::instance() { + if (_instance == NULL) { + _instance = new FacSupervisor(); + } + + return *_instance; + } + + // ////////////////////////////////////////////////////////////////////// + FacSupervisor::~FacSupervisor() { + cleanFacRelationShipRoots(); + } + + // ////////////////////////////////////////////////////////////////////// + void FacSupervisor:: + registerFacRelationShipRoot (FacRelationShipRootAbstract* ioFacRelationShipRoot_ptr) { + _facRelationShipRootPool.push_back (ioFacRelationShipRoot_ptr); + } + + // ////////////////////////////////////////////////////////////////////// + void FacSupervisor::cleanFacRelationShipRoots() { + for (FacRelationShipRootPool_T::const_iterator itRS = + _facRelationShipRootPool.begin(); + itRS != _facRelationShipRootPool.end(); ++itRS) { + const FacRelationShipRootAbstract* currentFacRelationShipRoot_ptr = *itRS; + assert (currentFacRelationShipRoot_ptr != NULL); + + delete currentFacRelationShipRoot_ptr; currentFacRelationShipRoot_ptr = NULL; + } + + // Empty the pool of relations ships + _facRelationShipRootPool.clear(); + } + + // ////////////////////////////////////////////////////////////////////// + void FacSupervisor::cleanAll () { + // Clean the static instance of the FacSupervisor. + // This in turn will invoke the destructor (~FacSupervisor() method) + // of the static instance. + delete _instance; _instance = NULL; + } + +} Added: trunk/stdair/test/archi_intru/FacSupervisor.hpp =================================================================== --- trunk/stdair/test/archi_intru/FacSupervisor.hpp (rev 0) +++ trunk/stdair/test/archi_intru/FacSupervisor.hpp 2010-09-12 14:43:43 UTC (rev 319) @@ -0,0 +1,57 @@ +#ifndef __INTRUSIVE_SVC_FACSUPERVISOR_HPP +#define __INTRUSIVE_SVC_FACSUPERVISOR_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <list> + +namespace stdair { + + // Forward declarations + class FacRelationShipRootAbstract; + + /** Singleton class to register and clean all Factories. */ + class FacSupervisor { + public: + /** Define the pool (list) of factories. */ + typedef std::list<FacRelationShipRootAbstract*> FacRelationShipRootPool_T; + + /** Provide the unique (static) instance of the FacSupervisor object. + <br>The singleton is instantiated when first used. + @return FacSupervisor& */ + static FacSupervisor& instance(); + + /** Register a newly instantiated concrete relation ship factory. */ + void registerFacRelationShipRoot (FacRelationShipRootAbstract*); + + /** Clean all registered relation ships. */ + void cleanFacRelationShipRoots(); + + /** Clean the static instance. + <br>As the static instance (singleton) is deleted, all the other + registered objects will be deleted in turn. */ + static void cleanAll (); + + /** Destructor. + <br>That destructors is applied on the static instance. It then + deletes in turn all the other registered objects. */ + ~FacSupervisor(); + + + protected: + /** Default Constructor. + <br>This constructor is protected + to ensure the singleton pattern. */ + FacSupervisor () {} + FacSupervisor (const FacSupervisor&) {} + + private: + /** The unique instance.*/ + static FacSupervisor* _instance; + /** List of instantiated relation ships. */ + FacRelationShipRootPool_T _facRelationShipRootPool; + }; +} +#endif // __INTRUSIVE_SVC_FACSUPERVISOR_HPP Added: trunk/stdair/test/archi_intru/RelationShipHolder.hpp =================================================================== --- trunk/stdair/test/archi_intru/RelationShipHolder.hpp (rev 0) +++ trunk/stdair/test/archi_intru/RelationShipHolder.hpp 2010-09-12 14:43:43 UTC (rev 319) @@ -0,0 +1,38 @@ +#ifndef __INTRUSIVE_BOM_RELATIONSHIPHOLDER_HPP +#define __INTRUSIVE_BOM_RELATIONSHIPHOLDER_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// Boost.Intrusive +#include <boost/intrusive/list.hpp> + +/** Alias for the boost::intrusive namespace. */ +namespace bi = boost::intrusive; + +namespace stdair { + + /** Class holding relationship objects between either a parent Bom and its + children or a Bom object and its siblings. */ + template <typename FIRST_BOM, typename SECOND_BOM> + class RelationShipHolder { + public: + // /////////////////////////////////////////// + /** Type definition for a list of either children or siblings. */ + typedef bi::list<SECOND_BOM> SecondBomList_T; + + /** Type definition for a relationship, holding a list of children + or siblings for a given parent/Bom object. + <br>The list has got only two elements. A list is used only because + the pair does not exist (yet?) within boost::intrusive. */ + typedef bi::list<FIRST_BOM, SecondBomList_T> RelationShip_T; + // /////////////////////////////////////////// + + private: + /** Relationship, holding a list of children or siblings for a + given parent/Bom object. */ + RelationShip_T _relationShip; + }; + +} +#endif // __INTRUSIVE_BOM_RELATIONSHIPHOLDER_HPP Modified: trunk/stdair/test/archi_intru/archi.cpp =================================================================== --- trunk/stdair/test/archi_intru/archi.cpp 2010-09-12 13:25:36 UTC (rev 318) +++ trunk/stdair/test/archi_intru/archi.cpp 2010-09-12 14:43:43 UTC (rev 319) @@ -8,6 +8,7 @@ #include <boost/intrusive/list.hpp> // Local #include <test/archi_intru/FlightDate.hpp> +//#include <test/archi_intru/FacRelationShipRoot.hpp> /** Alias for the boost::intrusive namespace. */ namespace bi = boost::intrusive; Modified: trunk/stdair/test/archi_intru/sources.mk =================================================================== --- trunk/stdair/test/archi_intru/sources.mk 2010-09-12 13:25:36 UTC (rev 318) +++ trunk/stdair/test/archi_intru/sources.mk 2010-09-12 14:43:43 UTC (rev 319) @@ -1,8 +1,13 @@ archi_intru_h_sources = \ + $(top_srcdir)/test/archi_intru/FacSupervisor.hpp \ + $(top_srcdir)/test/archi_intru/FacRelationShipRoot.hpp \ + $(top_srcdir)/test/archi_intru/FacRelationShipRootAbstract.hpp \ + $(top_srcdir)/test/archi_intru/RelationShipHolder.hpp \ $(top_srcdir)/test/archi_intru/BomAbstract.hpp \ $(top_srcdir)/test/archi_intru/BomRoot.hpp \ $(top_srcdir)/test/archi_intru/FlightDate.hpp \ $(top_srcdir)/test/archi_intru/LegDate.hpp \ $(top_srcdir)/test/archi_intru/SegmentDate.hpp archi_intru_cc_sources = \ + $(top_srcdir)/test/archi_intru/FacSupervisor.cpp \ $(top_srcdir)/test/archi_intru/archi.cpp This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |