From: <den...@us...> - 2010-09-12 21:58:01
|
Revision: 325 http://stdair.svn.sourceforge.net/stdair/?rev=325&view=rev Author: denis_arnaud Date: 2010-09-12 21:57:55 +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/FacRelationShipRoot.hpp trunk/stdair/test/archi_intru/RelationShipHolder.hpp trunk/stdair/test/archi_intru/TestBomUsage.cpp trunk/stdair/test/archi_intru/TestBomUsage.hpp trunk/stdair/test/archi_intru/TestIntrusive.cpp trunk/stdair/test/archi_intru/sources.mk Added Paths: ----------- trunk/stdair/test/archi_intru/RelationShipHolderSet.hpp Modified: trunk/stdair/test/archi_intru/FacRelationShipRoot.hpp =================================================================== --- trunk/stdair/test/archi_intru/FacRelationShipRoot.hpp 2010-09-12 19:11:43 UTC (rev 324) +++ trunk/stdair/test/archi_intru/FacRelationShipRoot.hpp 2010-09-12 21:57:55 UTC (rev 325) @@ -1,9 +1,11 @@ -#ifndef __INTRUSIVE_FAC_FACRELATIONSHIPHOLDER_HPP -#define __INTRUSIVE_FAC_FACRELATIONSHIPHOLDER_HPP +#ifndef __INTRUSIVE_FAC_FACRELATIONSHIPROOT_HPP +#define __INTRUSIVE_FAC_FACRELATIONSHIPROOT_HPP // ////////////////////////////////////////////////////////////////////// // Import section // ////////////////////////////////////////////////////////////////////// +// STL +#include <cassert> // Boost.Intrusive #include <boost/intrusive/list.hpp> #include <boost/intrusive/set.hpp> @@ -11,6 +13,7 @@ #include <test/archi_intru/FacSupervisor.hpp> #include <test/archi_intru/FacRelationShipRootAbstract.hpp> #include <test/archi_intru/RelationShipHolder.hpp> +#include <test/archi_intru/RelationShipHolderSet.hpp> /** Alias for the boost::intrusive namespace. */ namespace bi = boost::intrusive; @@ -22,23 +25,32 @@ class FacRelationShipRoot : public FacRelationShipRootAbstract { public: // /////////////////////////////////////////// - /** Type definition for the specific relationship. */ + /** Type definition for the specific relationship class. */ typedef RelationShipHolder<FIRST_BOM, SECOND_BOM> RelationShipHolder_T; - - /** Type definition for a list of relationship holder objects. */ + /** Type definition for a list of relationship objects. */ + /* typedef bi::member_hook <RelationShipHolder_T, bi::list_member_hook<>, - &RelationShipHolder_T::_childListHook> RSHolderListMemberOption; + &RelationShipHolder_T::_childListHook> RSHListMemberOption; typedef bi::list<RelationShipHolder_T, - RSHolderListMemberOption> RelationShipHolderList_T; - /** Type definition for a set of relationship holder objects. */ + RSHListMemberOption> RelationShipHolderList_T; + */ + /** Type definition for a set of relationship objects. */ + /* typedef bi::member_hook <RelationShipHolder_T, bi::set_member_hook<>, - &RelationShipHolder_T::_childSetHook> RSHolderSetMemberOption; + &RelationShipHolder_T::_childSetHook> RSHSetMemberOption; typedef bi::set<RelationShipHolder_T, - RSHolderSetMemberOption> RelationShipHolderSet_T; + RSHSetMemberOption> RelationShipHolderSet_T; + */ // /////////////////////////////////////////// + // /////////////////////////////////////////// + /** Type definition for the specific relationship holder (set) class. */ + typedef RelationShipHolderSet<FIRST_BOM, + SECOND_BOM> RelationShipHolderHolder_T; + // /////////////////////////////////////////// + public: /** Provide the unique instance. <br>The singleton is instantiated when first used. @@ -52,6 +64,11 @@ } return *_instance; } + + public: + /** Constructor. */ + FacRelationShipRoot() : _relationShipHolderSet () { + } public: /** Add a child/sibling to the dedicated list of the parent/sibling. */ @@ -63,15 +80,28 @@ void addToListImpl (FIRST_BOM& ioFirstBom, SECOND_BOM& ioSecondBom) { RelationShipHolder_T* lRS_ptr = new RelationShipHolder_T (ioFirstBom, ioSecondBom); - _relationShipHolderList.push_back (*lRS_ptr); - _relationShipHolderSet.insert (*lRS_ptr); + _relationShipHolderSet.addToList (*lRS_ptr); } + /** Add a child/sibling to the dedicated list of the parent/sibling. */ + static SECOND_BOM* find (const FIRST_BOM& iFirstBom, + const std::string& iSecondBomKey) { + SECOND_BOM* oSecondBom_ptr = + instance().findImpl (iFirstBom, iSecondBomKey); + return oSecondBom_ptr; + } + + /** Add a child/sibling to the dedicated list of the parent/sibling. */ + SECOND_BOM* findImpl (const FIRST_BOM& iFirstBom, + const std::string& iSecondBomKey) { + SECOND_BOM* oSecondBom_ptr = + _relationShipHolderSet.find (iFirstBom, iSecondBomKey); + return oSecondBom_ptr; + } + private: - /** List of relationship holder objects. */ - RelationShipHolderList_T _relationShipHolderList; /** Set of relationship holder objects. */ - RelationShipHolderSet_T _relationShipHolderSet; + RelationShipHolderHolder_T _relationShipHolderSet; private: /** The unique instance. */ @@ -84,4 +114,4 @@ FacRelationShipRoot<FIRST_BOM, SECOND_BOM>::_instance = NULL; } -#endif // __INTRUSIVE_FAC_FACRELATIONSHIPHOLDER_HPP +#endif // __INTRUSIVE_FAC_FACRELATIONSHIPROOT_HPP Modified: trunk/stdair/test/archi_intru/RelationShipHolder.hpp =================================================================== --- trunk/stdair/test/archi_intru/RelationShipHolder.hpp 2010-09-12 19:11:43 UTC (rev 324) +++ trunk/stdair/test/archi_intru/RelationShipHolder.hpp 2010-09-12 21:57:55 UTC (rev 325) @@ -6,8 +6,12 @@ // ////////////////////////////////////////////////////////////////////// // STL #include <string> +// Boost.Intrusive +#include <boost/intrusive/list.hpp> +#include <boost/intrusive/set.hpp> // Local #include <test/archi_intru/RelationShipHolderAbstract.hpp> +#include <test/archi_intru/IntrusiveHelper.hpp> /** Alias for the boost::intrusive namespace. */ namespace bi = boost::intrusive; @@ -22,19 +26,37 @@ // /////////////////////////////////////////// /** Type definition for a list of either children or siblings. */ typedef bi::member_hook <SECOND_BOM, - bi::list_member_hook<>, - &SECOND_BOM::_childListHook> SecondBomListMemberOption; - typedef bi::list<SECOND_BOM, SecondBomListMemberOption> SecondBomList_T; + bi::set_member_hook<>, + &SECOND_BOM::_childSetHook> SecondBomSetMemberOption; + typedef bi::set<SECOND_BOM, SecondBomSetMemberOption> SecondBomSet_T; // /////////////////////////////////////////// public: RelationShipHolder (FIRST_BOM& ioFirstBom, SECOND_BOM& ioSecondBom) - : _firstBom (ioFirstBom) { + : RelationShipHolderAbstract (ioFirstBom.getKey() + "," + + ioSecondBom.getKey()), + _firstBom (ioFirstBom) { } public: bi::list_member_hook<> _childListHook; bi::set_member_hook<> _childSetHook; + + public: + /** Search for a child/sibling from the dedicated list of the + parents/siblings. */ + SECOND_BOM* find (const std::string& iSecondBomKey) { + SECOND_BOM* oSecondBom_ptr = NULL; + + typename SecondBomSet_T::iterator itSecondBom = + _secondBomSet.find (iSecondBomKey, StrExpComp<SECOND_BOM>()); + if (itSecondBom == _secondBomSet.end()) { + return oSecondBom_ptr; + } + oSecondBom_ptr = &*itSecondBom; + + return oSecondBom_ptr; + } public: // /////////// Display support methods ///////// @@ -53,7 +75,7 @@ /** Relationship, holding a list of children or siblings for a given parent/Bom object. */ FIRST_BOM& _firstBom; - SecondBomList_T _secondBomList; + SecondBomSet_T _secondBomSet; }; } Added: trunk/stdair/test/archi_intru/RelationShipHolderSet.hpp =================================================================== --- trunk/stdair/test/archi_intru/RelationShipHolderSet.hpp (rev 0) +++ trunk/stdair/test/archi_intru/RelationShipHolderSet.hpp 2010-09-12 21:57:55 UTC (rev 325) @@ -0,0 +1,103 @@ +#ifndef __INTRUSIVE_BOM_RELATIONSHIPHOLDERSET_HPP +#define __INTRUSIVE_BOM_RELATIONSHIPHOLDERSET_HPP + +// ////////////////////////////////////////////////////////////////////// +// Import section +// ////////////////////////////////////////////////////////////////////// +// STL +#include <string> +// Boost.Intrusive +#include <boost/intrusive/list.hpp> +#include <boost/intrusive/set.hpp> +// Local +#include <test/archi_intru/RelationShipHolderAbstract.hpp> +#include <test/archi_intru/RelationShipHolder.hpp> +#include <test/archi_intru/IntrusiveHelper.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 RelationShipHolderSet : public RelationShipHolderAbstract { + public: + // /////////////////////////////////////////// + /** Type definition for the specific relationship class. */ + typedef RelationShipHolder<FIRST_BOM, SECOND_BOM> RelationShipHolder_T; + + /** Type definition for a list of relationship objects. */ + typedef bi::member_hook <RelationShipHolder_T, + bi::list_member_hook<>, + &RelationShipHolder_T::_childListHook> RSHListMemberOption; + typedef bi::list<RelationShipHolder_T, + RSHListMemberOption> RelationShipHolderList_T; + + /** Type definition for a set of relationship objects. */ + typedef bi::member_hook <RelationShipHolder_T, + bi::set_member_hook<>, + &RelationShipHolder_T::_childSetHook> RSHSetMemberOption; + typedef bi::set<RelationShipHolder_T, + RSHSetMemberOption> RelationShipHolderSet_T; + // /////////////////////////////////////////// + + public: + /** Constructor. */ + RelationShipHolderSet () + : RelationShipHolderAbstract ("RelationShipHolderSet") { + } + + public: + bi::list_member_hook<> _childListHook; + bi::set_member_hook<> _childSetHook; + + public: + /** Add a child/sibling to the dedicated list of the parent/sibling. */ + void addToList (RelationShipHolder_T& ioRelationShipHolder) { + _relationShipHolderList.push_back (ioRelationShipHolder); + _relationShipHolderSet.insert (ioRelationShipHolder); + } + + /** Search for a child/sibling from the dedicated list of the + parents/siblings. */ + SECOND_BOM* find (const FIRST_BOM& iFirstBom, + const std::string& iSecondBomKey) { + SECOND_BOM* oSecondBom_ptr = NULL; + RelationShipHolder_T* oRSH_ptr = NULL; + + typename RelationShipHolderSet_T::iterator itRSH = + _relationShipHolderSet.find (iSecondBomKey, StrExpComp<RelationShipHolder_T>()); + if (itRSH == _relationShipHolderSet.end()) { + return oSecondBom_ptr; + } + oRSH_ptr = &*itRSH; + + oSecondBom_ptr = oRSH_ptr->find (iSecondBomKey); + + return oSecondBom_ptr; + } + + public: + // /////////// Display support methods ///////// + /** Dump a Business Object into an output stream. + @param ostream& the output stream. */ + void toStream (std::ostream& ioOut) const { toString(); } + + /** Read a Business Object from an input stream. + @param istream& the input stream. */ + void fromStream (std::istream& ioIn) {} + + /** Get the serialised version of the Business Object. */ + std::string toString() const { return _key; }; + + private: + /** Relationship, holding a list of children or siblings for a + given parent/Bom object. */ + RelationShipHolderList_T _relationShipHolderList; + RelationShipHolderSet_T _relationShipHolderSet; + }; + +} +#endif // __INTRUSIVE_BOM_RELATIONSHIPHOLDERSET_HPP Modified: trunk/stdair/test/archi_intru/TestBomUsage.cpp =================================================================== --- trunk/stdair/test/archi_intru/TestBomUsage.cpp 2010-09-12 19:11:43 UTC (rev 324) +++ trunk/stdair/test/archi_intru/TestBomUsage.cpp 2010-09-12 21:57:55 UTC (rev 325) @@ -20,12 +20,18 @@ namespace bi = boost::intrusive; // ////////////////////////////////////////////////////////////////////// +TestBomUsage::TestBomUsage() : _bomRoot (NULL) { + init(); +} + +// ////////////////////////////////////////////////////////////////////// TestBomUsage::~TestBomUsage() { clean(); } // ////////////////////////////////////////////////////////////////////// void TestBomUsage::init() { + _bomRoot = &stdair::FacBom<stdair::BomRoot>::instance().create ("BR"); } // ////////////////////////////////////////////////////////////////////// @@ -36,24 +42,64 @@ bool TestBomUsage::testBomBuilding() { bool oTestSuccessfull = true; - const std::string br0 ("BR"); - stdair::BomRoot& lBomRoot = - stdair::FacBom<stdair::BomRoot>::instance().create (br0); - + // 0. Sanity check + assert (_bomRoot != NULL); + + // 1. FlightDate level + // 1.1. BA177 const std::string fdba117 ("BA117"); stdair::FlightDate& lFDBA117 = stdair::FacBom<stdair::FlightDate>::instance().create (fdba117); stdair::FacRelationShipRoot<stdair::BomRoot, - stdair::FlightDate>::addToList(lBomRoot,lFDBA117); + stdair::FlightDate>::addToList (*_bomRoot, + lFDBA117); + // 1.2. LH434 + const std::string fdlh434 ("LH434"); + stdair::FlightDate& lFDLH434 = + stdair::FacBom<stdair::FlightDate>::instance().create (fdlh434); + + stdair::FacRelationShipRoot<stdair::BomRoot, + stdair::FlightDate>::addToList (*_bomRoot, + lFDLH434); + return oTestSuccessfull; } // ////////////////////////////////////////////////////////////////////// +bool TestBomUsage::testBomSearching() { + bool oTestSuccessfull = true; + + stdair::FlightDate* lFlightDate_ptr = + stdair::FacRelationShipRoot<stdair::BomRoot, + stdair::FlightDate>::find (*_bomRoot, "BA117"); + + // DEBUG + const std::string isFDNullStr = (lFlightDate_ptr == NULL)?"Yes":"No"; + std::cout << "Is FlightDate NULL? " << isFDNullStr << std::endl; + + return oTestSuccessfull; +} + +// ////////////////////////////////////////////////////////////////////// bool TestBomUsage::test() { bool oTestSuccessfull = true; + // + TestBomUsage lTestBomUsage; + + // Test the building of the BOM tree + oTestSuccessfull = lTestBomUsage.testBomBuilding(); + if (oTestSuccessfull == false) { + return oTestSuccessfull; + } + // Test searching within the BOM tree + oTestSuccessfull = lTestBomUsage.testBomSearching(); + if (oTestSuccessfull == false) { + return oTestSuccessfull; + } + return oTestSuccessfull; } Modified: trunk/stdair/test/archi_intru/TestBomUsage.hpp =================================================================== --- trunk/stdair/test/archi_intru/TestBomUsage.hpp 2010-09-12 19:11:43 UTC (rev 324) +++ trunk/stdair/test/archi_intru/TestBomUsage.hpp 2010-09-12 21:57:55 UTC (rev 325) @@ -9,9 +9,16 @@ // Local #include <test/archi_intru/FlightDate.hpp> +// Forward declarations +namespace stdair { + class BomRoot; +} + /** Class wrapping test functions. */ class TestBomUsage { public: + /** Constructor. */ + TestBomUsage(); /** Destructor. */ ~TestBomUsage(); @@ -23,6 +30,9 @@ /** Test the building of the BOM tree. */ bool testBomBuilding(); + /** Test the search within the BOM tree. */ + bool testBomSearching(); + private: /** Initialise. */ void init(); @@ -31,6 +41,7 @@ void clean(); private: + stdair::BomRoot* _bomRoot; }; #endif // __INTRUSIVE_TST_TESTBOMUSAGE_HPP Modified: trunk/stdair/test/archi_intru/TestIntrusive.cpp =================================================================== --- trunk/stdair/test/archi_intru/TestIntrusive.cpp 2010-09-12 19:11:43 UTC (rev 324) +++ trunk/stdair/test/archi_intru/TestIntrusive.cpp 2010-09-12 21:57:55 UTC (rev 325) @@ -7,7 +7,7 @@ #include <sstream> #include <string> #include <vector> -// Boost +// Boost.Intrusive #include <boost/intrusive/list.hpp> // Local #include <test/archi_intru/FacBom.hpp> @@ -165,13 +165,22 @@ lTestIntrusive.init(); // Now test lists - lTestIntrusive.testIntrusiveList(); + oTestSuccessfull = lTestIntrusive.testIntrusiveList(); + if (oTestSuccessfull == false) { + return oTestSuccessfull; + } // Now, test iterator_to() - lTestIntrusive.testIntrusiveIteratorTo(); + oTestSuccessfull = lTestIntrusive.testIntrusiveIteratorTo(); + if (oTestSuccessfull == false) { + return oTestSuccessfull; + } // Now, test sets - lTestIntrusive.testIntrusiveSets(); + oTestSuccessfull = lTestIntrusive.testIntrusiveSets(); + if (oTestSuccessfull == false) { + return oTestSuccessfull; + } return oTestSuccessfull; } Modified: trunk/stdair/test/archi_intru/sources.mk =================================================================== --- trunk/stdair/test/archi_intru/sources.mk 2010-09-12 19:11:43 UTC (rev 324) +++ trunk/stdair/test/archi_intru/sources.mk 2010-09-12 21:57:55 UTC (rev 325) @@ -7,6 +7,7 @@ $(top_srcdir)/test/archi_intru/IntrusiveHelper.hpp \ $(top_srcdir)/test/archi_intru/RelationShipHolderAbstract.hpp \ $(top_srcdir)/test/archi_intru/RelationShipHolder.hpp \ + $(top_srcdir)/test/archi_intru/RelationShipHolderSet.hpp \ $(top_srcdir)/test/archi_intru/BomAbstract.hpp \ $(top_srcdir)/test/archi_intru/BomRoot.hpp \ $(top_srcdir)/test/archi_intru/FlightDate.hpp \ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |