From: <den...@us...> - 2009-06-16 22:44:57
|
Revision: 7 http://air-sched.svn.sourceforge.net/air-sched/?rev=7&view=rev Author: denis_arnaud Date: 2009-06-16 22:44:46 +0000 (Tue, 16 Jun 2009) Log Message: ----------- Improved the code: the SegmentDate and FlightDate are now linked. But the search part of pointers still does not work. Modified Paths: -------------- trunk/airsched/airsched/bom/FlightDate.cpp trunk/airsched/airsched/bom/SegmentDate.cpp trunk/airsched/airsched/factory/FacFlightDate.cpp trunk/airsched/airsched/factory/FacSegmentDate.cpp trunk/airsched/stdair/bom/FlightDate.cpp trunk/airsched/stdair/bom/FlightDateKey.cpp trunk/airsched/stdair/bom/FlightDateKey.hpp trunk/airsched/stdair/bom/SegmentDate.cpp trunk/airsched/stdair/bom/SegmentDate.hpp trunk/airsched/stdair/bom/SegmentDateKey.cpp trunk/airsched/stdair/bom/SegmentDateKey.hpp trunk/airsched/stdair/factory/FacFlightDate.cpp trunk/airsched/stdair/factory/FacFlightDate.hpp Modified: trunk/airsched/airsched/bom/FlightDate.cpp =================================================================== --- trunk/airsched/airsched/bom/FlightDate.cpp 2009-06-16 17:42:51 UTC (rev 6) +++ trunk/airsched/airsched/bom/FlightDate.cpp 2009-06-16 22:44:46 UTC (rev 7) @@ -9,6 +9,7 @@ // AIRSCHED #include <airsched/bom/FlightDate.hpp> #include <airsched/bom/SegmentDate.hpp> +#include <airsched/service/Logger.hpp> namespace AIRSCHED { @@ -23,6 +24,7 @@ // ////////////////////////////////////////////////////////////////////// void FlightDate::toStream (std::ostream& ioOut) const { + ioOut << toString() << std::endl; } // ////////////////////////////////////////////////////////////////////// @@ -31,16 +33,20 @@ // ////////////////////////////////////////////////////////////////////// std::string FlightDate::toString() const { - std::string oString; + std::ostringstream oStr; + // First, put the key of that level + oStr << describeShortKey() << std::endl; + // Retrieve the list of flight-date holders const STDAIR::SegmentDateList_T& lSegmentList = _flightStructure.getSegmentList(); // Browse the tree structure, i.e., the segment-dates + unsigned short idx = 0; for (STDAIR::SegmentDateList_T::const_iterator itSegment = lSegmentList.begin(); - itSegment != lSegmentList.end(); ++itSegment) { + itSegment != lSegmentList.end(); ++itSegment, ++idx) { const STDAIR::SegmentDate* lSegmentStructure_ptr = itSegment->second; assert (lSegmentStructure_ptr != NULL); @@ -48,24 +54,20 @@ const SegmentDate& lSegmentDate = lSegmentStructure_ptr->getContent<SegmentDate>(); - oString += lSegmentDate.toString(); + oStr << "[" << idx << "]: " << lSegmentDate.toString() << std::endl; } - return oString; + return oStr.str(); } // ////////////////////////////////////////////////////////////////////// const std::string FlightDate::describeKey() const { - std::string oKey; - - return oKey; + return _flightStructure.describeKey(); } // ////////////////////////////////////////////////////////////////////// const std::string FlightDate::describeShortKey() const { - std::string oKey; - - return oKey; + return _flightStructure.describeShortKey(); } } Modified: trunk/airsched/airsched/bom/SegmentDate.cpp =================================================================== --- trunk/airsched/airsched/bom/SegmentDate.cpp 2009-06-16 17:42:51 UTC (rev 6) +++ trunk/airsched/airsched/bom/SegmentDate.cpp 2009-06-16 22:44:46 UTC (rev 7) @@ -3,6 +3,8 @@ // ////////////////////////////////////////////////////////////////////// // C #include <assert.h> +// STDAIR +#include <stdair/bom/SegmentDate.hpp> // AIRSCHED #include <airsched/bom/SegmentDate.hpp> @@ -19,6 +21,7 @@ // ////////////////////////////////////////////////////////////////////// void SegmentDate::toStream (std::ostream& ioOut) const { + ioOut << toString() << std::endl; } // ////////////////////////////////////////////////////////////////////// @@ -27,23 +30,25 @@ // ////////////////////////////////////////////////////////////////////// std::string SegmentDate::toString() const { - std::string oString; + std::ostringstream oStr; - return oString; + // First, put the key of that level + oStr << describeShortKey() << std::endl; + + // Then, browse the children + // [...] (no child for now) + + return oStr.str(); } // ////////////////////////////////////////////////////////////////////// const std::string SegmentDate::describeKey() const { - std::string oKey; - - return oKey; + return _segmentStructure.describeKey(); } // ////////////////////////////////////////////////////////////////////// const std::string SegmentDate::describeShortKey() const { - std::string oKey; - - return oKey; + return _segmentStructure.describeShortKey(); } } Modified: trunk/airsched/airsched/factory/FacFlightDate.cpp =================================================================== --- trunk/airsched/airsched/factory/FacFlightDate.cpp 2009-06-16 17:42:51 UTC (rev 6) +++ trunk/airsched/airsched/factory/FacFlightDate.cpp 2009-06-16 22:44:46 UTC (rev 7) @@ -36,6 +36,7 @@ // //////////////////////////////////////////////////////////////////// FlightDate& FacFlightDate::create (const STDAIR::FlightDateKey& iKey) { + // Create the flight-date structure/holder STDAIR::FlightDate& lFlightDateStructure = STDAIR::FacFlightDate::instance().create (iKey); Modified: trunk/airsched/airsched/factory/FacSegmentDate.cpp =================================================================== --- trunk/airsched/airsched/factory/FacSegmentDate.cpp 2009-06-16 17:42:51 UTC (rev 6) +++ trunk/airsched/airsched/factory/FacSegmentDate.cpp 2009-06-16 22:44:46 UTC (rev 7) @@ -8,6 +8,7 @@ #include <stdair/bom/SegmentDateKey.hpp> #include <stdair/bom/SegmentDate.hpp> #include <stdair/factory/FacSupervisor.hpp> +#include <stdair/factory/FacFlightDate.hpp> #include <stdair/factory/FacSegmentDate.hpp> // AIRSCHED #include <airsched/factory/FacSegmentDate.hpp> @@ -47,12 +48,13 @@ assert (aSegmentDate_ptr != NULL); // The new object is added to the Bom pool - const bool hasInsertBeenSuccessful = _pool. + bool hasInsertBeenSuccessful = _pool. insert (FacBomContent::BomPool_T::value_type (aSegmentDate_ptr, &lSegmentDateStructure)).second; if (hasInsertBeenSuccessful == false) { - AIRSCHED_LOG_ERROR ("The segment-date object " << *aSegmentDate_ptr + AIRSCHED_LOG_ERROR ("The segment-date object " + << aSegmentDate_ptr->describeShortKey() << " can not be added to the factory-held pool" << " of segment-date objects."); throw new MemoryAllocationException(); @@ -67,17 +69,28 @@ dynamic_cast<STDAIR::FlightDate*> (itFlightDateStructure->second); } else { - AIRSCHED_LOG_ERROR ("The flight-date object " << iFlightDate + AIRSCHED_LOG_ERROR ("The flight-date object " + << iFlightDate.describeShortKey() << " can not be retrieved from the factory-held pool" << " of flight-date objects."); throw new MemoryAllocationException(); } assert (lFlightDateStructure_ptr != NULL); - // TODO:: Link the FlightDateStructure (STDAIR::FlightDate) with the + + // Link the FlightDateStructure (STDAIR::FlightDate) with the // SegmentDateStructure + hasInsertBeenSuccessful = STDAIR::FacFlightDate:: + linkFlightDateWithSegmentDate (*lFlightDateStructure_ptr, + lSegmentDateStructure); + if (hasInsertBeenSuccessful == false) { + AIRSCHED_LOG_ERROR ("The segment-date object " << iKey + << " can not be added to the dedicated list " + << " of segment-date objects within the flight-date " + << iFlightDate.describeShortKey()); + throw new MemoryAllocationException(); + } - return *aSegmentDate_ptr; } Modified: trunk/airsched/stdair/bom/FlightDate.cpp =================================================================== --- trunk/airsched/stdair/bom/FlightDate.cpp 2009-06-16 17:42:51 UTC (rev 6) +++ trunk/airsched/stdair/bom/FlightDate.cpp 2009-06-16 22:44:46 UTC (rev 7) @@ -20,6 +20,7 @@ // ////////////////////////////////////////////////////////////////////// void FlightDate::toStream (std::ostream& ioOut) const { + ioOut << toString() << std::endl; } // ////////////////////////////////////////////////////////////////////// @@ -28,23 +29,17 @@ // ////////////////////////////////////////////////////////////////////// std::string FlightDate::toString() const { - std::string oString; - - return oString; + return describeKey(); } // ////////////////////////////////////////////////////////////////////// const std::string FlightDate::describeKey() const { - std::string oKey; - - return oKey; + return _key.toString(); } // ////////////////////////////////////////////////////////////////////// const std::string FlightDate::describeShortKey() const { - std::string oKey; - - return oKey; + return _key.toString(); } } Modified: trunk/airsched/stdair/bom/FlightDateKey.cpp =================================================================== --- trunk/airsched/stdair/bom/FlightDateKey.cpp 2009-06-16 17:42:51 UTC (rev 6) +++ trunk/airsched/stdair/bom/FlightDateKey.cpp 2009-06-16 22:44:46 UTC (rev 7) @@ -19,8 +19,8 @@ // ////////////////////////////////////////////////////////////////////// std::string FlightDateKey::toString() const { - std::stringstream oStr; - oStr << _flightNumber << "-" << _flightDate; + std::ostringstream oStr; + oStr << _flightNumber << ", " << _flightDate; return oStr.str(); } Modified: trunk/airsched/stdair/bom/FlightDateKey.hpp =================================================================== --- trunk/airsched/stdair/bom/FlightDateKey.hpp 2009-06-16 17:42:51 UTC (rev 6) +++ trunk/airsched/stdair/bom/FlightDateKey.hpp 2009-06-16 22:44:46 UTC (rev 7) @@ -46,19 +46,13 @@ void fromStream (std::istream& ioIn); /** Get the serialised version of the Business Object Key. - <br>That string is unique for all the Business Objects, - whatever their level in the BOM hierarchy. - <br>For instance, "BA123/10JUN2010" and "BA123/11JUN2010" allow to - differentiate among two departure dates for the same flight. */ - std::string toString() const; - - /** Get the serialised version of the Business Object Key. <br>That string is unique, at the level of a given Business Object, when among children of a given parent Business Object. <br>For instance, "H" and "K" allow to differentiate among two marketing classes for the same segment-date. */ - std::string toShortString() const; + std::string toString() const; + private: // Attributes /** Flight number. */ Modified: trunk/airsched/stdair/bom/SegmentDate.cpp =================================================================== --- trunk/airsched/stdair/bom/SegmentDate.cpp 2009-06-16 17:42:51 UTC (rev 6) +++ trunk/airsched/stdair/bom/SegmentDate.cpp 2009-06-16 22:44:46 UTC (rev 7) @@ -18,7 +18,14 @@ } // ////////////////////////////////////////////////////////////////////// + FlightDate& SegmentDate::getFlightDate() const { + assert (_flightDate != NULL); + return *_flightDate; + } + + // ////////////////////////////////////////////////////////////////////// void SegmentDate::toStream (std::ostream& ioOut) const { + ioOut << toString() << std::endl; } // ////////////////////////////////////////////////////////////////////// @@ -27,24 +34,17 @@ // ////////////////////////////////////////////////////////////////////// std::string SegmentDate::toString() const { - std::string oString; - // Debug - oString = _key.toShortString(); - return oString; + return describeKey(); } // ////////////////////////////////////////////////////////////////////// const std::string SegmentDate::describeKey() const { - std::string oKey; - - return oKey; + return _key.toString(); } // ////////////////////////////////////////////////////////////////////// const std::string SegmentDate::describeShortKey() const { - std::string oKey; - - return oKey; + return _key.toString(); } } Modified: trunk/airsched/stdair/bom/SegmentDate.hpp =================================================================== --- trunk/airsched/stdair/bom/SegmentDate.hpp 2009-06-16 17:42:51 UTC (rev 6) +++ trunk/airsched/stdair/bom/SegmentDate.hpp 2009-06-16 22:44:46 UTC (rev 7) @@ -10,6 +10,7 @@ namespace STDAIR { // Forward declaration + class FlightDate; class SegmentDateKey; /** Wrapper class aimed at holding the actual content, modeled @@ -17,14 +18,32 @@ in the AIRSCHED library). */ class SegmentDate : public BomAbstract { friend class FacSegmentDate; + friend class FacFlightDate; public: // /////////// Getters ///////////// + /** Get the (parent) FlightDate object. */ + FlightDate* getFlightDatePtr() const { + return _flightDate; + } + + /** Get the (parent) FlightDate object. */ + FlightDate& getFlightDate() const; + /** Get the segment-date key. */ const SegmentDateKey& getKey() const { return _key; } + private: + // /////////// Setters ///////////// + /** Set the (parent) FlightDate object. */ + void setFlightDate (FlightDate& ioFlightDate) { + _flightDate = &ioFlightDate; + } + + + public: // /////////// Display support methods ///////// /** Dump a Business Object into an output stream. @param ostream& the output stream. */ @@ -58,6 +77,9 @@ private: // Attributes + /** Parent flight-date. */ + FlightDate* _flightDate; + /** Segment-date key (e.g., allowing to specify "LHR-SYD"). */ const SegmentDateKey& _key; }; Modified: trunk/airsched/stdair/bom/SegmentDateKey.cpp =================================================================== --- trunk/airsched/stdair/bom/SegmentDateKey.cpp 2009-06-16 17:42:51 UTC (rev 6) +++ trunk/airsched/stdair/bom/SegmentDateKey.cpp 2009-06-16 22:44:46 UTC (rev 7) @@ -19,7 +19,7 @@ // ////////////////////////////////////////////////////////////////////// std::string SegmentDateKey::toString() const { - std::stringstream oStr; + std::ostringstream oStr; oStr << _boardPoint << "-" << _offPoint; return oStr.str(); } Modified: trunk/airsched/stdair/bom/SegmentDateKey.hpp =================================================================== --- trunk/airsched/stdair/bom/SegmentDateKey.hpp 2009-06-16 17:42:51 UTC (rev 6) +++ trunk/airsched/stdair/bom/SegmentDateKey.hpp 2009-06-16 22:44:46 UTC (rev 7) @@ -46,19 +46,13 @@ void fromStream (std::istream& ioIn); /** Get the serialised version of the Business Object Key. - <br>That string is unique for all the Business Objects, - whatever their level in the BOM hierarchy. - <br>For instance, "BA123/10JUN2010" and "BA123/11JUN2010" allow to - differentiate among two departure dates for the same flight. */ - std::string toString() const; - - /** Get the serialised version of the Business Object Key. <br>That string is unique, at the level of a given Business Object, when among children of a given parent Business Object. <br>For instance, "H" and "K" allow to differentiate among two marketing classes for the same segment-date. */ - std::string toShortString() const; + std::string toString() const; + private: // Attributes /** Boarding airport. */ Modified: trunk/airsched/stdair/factory/FacFlightDate.cpp =================================================================== --- trunk/airsched/stdair/factory/FacFlightDate.cpp 2009-06-16 17:42:51 UTC (rev 6) +++ trunk/airsched/stdair/factory/FacFlightDate.cpp 2009-06-16 22:44:46 UTC (rev 7) @@ -3,8 +3,11 @@ // ////////////////////////////////////////////////////////////////////// // C #include <assert.h> +// STL +#include <iostream> // STDAIR #include <stdair/bom/FlightDate.hpp> +#include <stdair/bom/SegmentDate.hpp> #include <stdair/factory/FacSupervisor.hpp> #include <stdair/factory/FacFlightDate.hpp> @@ -42,5 +45,27 @@ return *aFlightDate_ptr; } + // //////////////////////////////////////////////////////////////////// + bool FacFlightDate:: + linkFlightDateWithSegmentDate (FlightDate& ioFlightDate, + SegmentDate& ioSegmentDate) { + + // Set the parent of the SegmentDate object + ioSegmentDate.setFlightDate (ioFlightDate); + + // Retrieve the short key + const std::string& lSegmentDateKey = ioSegmentDate.describeShortKey(); + + // Insert the SegmentDate object in the dedicated list + const bool hasInsertBeenSuccessful = ioFlightDate._segmentList. + insert (SegmentDateList_T::value_type (lSegmentDateKey, + &ioSegmentDate)).second; + + if (hasInsertBeenSuccessful == false) { + return hasInsertBeenSuccessful; + } + + return true; + } + } - Modified: trunk/airsched/stdair/factory/FacFlightDate.hpp =================================================================== --- trunk/airsched/stdair/factory/FacFlightDate.hpp 2009-06-16 17:42:51 UTC (rev 6) +++ trunk/airsched/stdair/factory/FacFlightDate.hpp 2009-06-16 22:44:46 UTC (rev 7) @@ -31,6 +31,12 @@ @return FlightDate& The newly created object. */ FlightDate& create (const FlightDateKey&); + /** Link a SegmentDate object with its parent (FlightDate object). + <br>The SegmentDate object is added to the dedicated list within + the FlightDate object. . + @return bool Whether or not the operation succeeded. */ + static bool linkFlightDateWithSegmentDate (FlightDate&, SegmentDate&); + protected: /** Default Constructor. <br>This constructor is protected in order to ensure the singleton This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |